【发布时间】:2017-09-18 21:01:22
【问题描述】:
在学习 Tensorflow 时,我对输出层张量的维度感到困惑。
我正在学习如何在 Tensorflow 中构建一个多层感知器模型。我开始的代码是this one。
简单来说就是如下图:
def multilayer_perceptron(x, weights, biases):
:
:
pred = multilayer_perceptron(x, weights, biases)
:
:
with tf.Session() as sess:
sess.run(init)
:
correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print ("Accuracy:", accuracy.eval({x: X_test, y: y_test_onehot}))
我了解argmax 和equal 方法的概念。但是为什么在tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1)) 中,axis 参数是 1?或者说,为什么pred 不止一维?对我来说,pred 应该类似于一维数组。例如。 [0,1,1,1,1] 表示除第一个预测外,其他都正确。为什么我们在 equal 方法之前需要一个 argmax?
谢谢!
【问题讨论】:
标签: python tensorflow nlp data-science