【问题标题】:How to output the predicted value(label) in tensorflow MNIST tutorial?如何在 TensorFlow MNIST 教程中输出预测值(标签)?
【发布时间】:2016-12-21 06:56:27
【问题描述】:

在tensorflow的MNIST教程中,最后一步是使用如下代码输出模型的测试准确率:

# 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}))

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

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

【问题讨论】:

    标签: graph machine-learning computer-vision tensorflow deep-learning


    【解决方案1】:

    这样的东西应该可以工作

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

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

    PS 对不起我的英语

    【讨论】:

    • 我将您的代码更改为: print sess.run(tf.argmax(y, 1), feed_dict={x: mnist.test.images}) 并且它可以工作。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    • 2017-04-13
    • 2017-09-20
    • 2017-02-21
    • 2017-06-16
    相关资源
    最近更新 更多