如何在 TensorFlow 的 MNIST 示例中获得预测的 class 标签?
How to get predicted class labels in TensorFlow's MNIST example?
我是神经网络的新手,并为初学者浏览了 MNIST 示例。
我目前正在尝试在另一个没有测试标签的 Kaggle 数据集上使用这个例子。
如果我 运行 测试数据集上的模型没有相应的标签,因此无法像 MNIST 示例中那样计算准确性,我希望能够看到预测。是否有可能以某种方式访问观察结果及其预测标签并很好地打印出来?
我认为您只需要按照教程中的说明评估您的输出张量:
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
要获取张量的输出,请参阅 docs:
After the graph has been launched in a session, the value of the Tensor can be computed by passing it to Session.run(). t.eval() is a shortcut for calling tf.get_default_session().run(t).
如果您想获得预测而不是准确性,则需要以相同的方式评估您的输出张量y
:
print(sess.run(y, feed_dict={x: mnist.test.images}))
prediction=tf.argmax(y,1)
print prediction.eval(feed_dict={x: mnist.test.images}).
有关详细信息,请查看 https://github.com/tensorflow/tensorflow/issues/97
我是神经网络的新手,并为初学者浏览了 MNIST 示例。
我目前正在尝试在另一个没有测试标签的 Kaggle 数据集上使用这个例子。
如果我 运行 测试数据集上的模型没有相应的标签,因此无法像 MNIST 示例中那样计算准确性,我希望能够看到预测。是否有可能以某种方式访问观察结果及其预测标签并很好地打印出来?
我认为您只需要按照教程中的说明评估您的输出张量:
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
要获取张量的输出,请参阅 docs:
After the graph has been launched in a session, the value of the Tensor can be computed by passing it to Session.run(). t.eval() is a shortcut for calling tf.get_default_session().run(t).
如果您想获得预测而不是准确性,则需要以相同的方式评估您的输出张量y
:
print(sess.run(y, feed_dict={x: mnist.test.images}))
prediction=tf.argmax(y,1)
print prediction.eval(feed_dict={x: mnist.test.images}).
有关详细信息,请查看 https://github.com/tensorflow/tensorflow/issues/97