如何在 tensorflow MNIST 教程中输出预测值(标签)?

How to output the predicted value(label) in tensorflow MNIST tutorial?

在MNIST的tensorflow的教程中,最后一步是使用以下代码输出模型的测试精度:

# Test trained model
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images,
                                  y_: mnist.test.labels}))

但是,我想知道如何修改这段代码以输出测试集的预测值(标签),而不是仅仅打印出准确率?

这是教程的link:https://www.tensorflow.org/tutorials/mnist/beginners/

像这样的东西应该可以工作

print(sess.run(tf.argmax(y, 1), feed_dict={x: mnist.test.images}))

因为教程中的 y 是张量,其中索引为 j 的列描述了行 i 中的图像有多大可能是数字 j,所以 tf.argmax 只是returns 每行概率最高的列的索引。

PS对不起我的英语