无法使用张量流打印正确的预测

时间:2017-02-20 22:01:22

标签: python tensorflow softmax

我实施了一项工作正常的逻辑回归。它正确地打印出准确性。我显示准确性......

# Test model
correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
# Calculate accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

print("Accuracy:", accuracy.eval({x: mnist.test.images, y: mnist.test.labels}))

正如我所说,这很好。但是,在阅读完教程之后,我知道correct_prediction应该是一个布尔数组,告诉我们我们的预测是否正确。我想打印这个布尔值,但我遇到了问题。我试过以下......

print(correct_prediction)
>>>Tensor("Equal:0", shape=(?,), dtype=bool)

然后我试了......

print(sess.run(correct_prediction))
>>>InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float
 [[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

我对TensorFlow很新。如何将此变量打印为预测数组?

1 个答案:

答案 0 :(得分:1)

您仍然需要输入数据。试试:

print(correct_prediction.eval({x: mnist.test.images, y: mnist.test.labels}))