【问题标题】:Cannot print correct predictions using tensor flow无法使用 tensorflow 打印正确的预测
【发布时间】:2017-02-20 22:01:21
【问题描述】:

我已经实现了一个运行良好的逻辑回归。它正确打印出准确性。我显示的准确性是这样...

# 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 很陌生。如何将此变量打印为预测数组?

【问题讨论】:

    标签: python tensorflow softmax


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      相关资源
      最近更新 更多