如何在TensorFlow的MNIST示例中获取预测的类标签? [英] How to get predicted class labels in TensorFlow's MNIST example?

查看:183
本文介绍了如何在TensorFlow的MNIST示例中获取预测的类标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是神经网络的新手,并为初学者讲了MNIST示例.

I am new to Neural Networks and went through the MNIST example for beginners.

我目前正试图在Kaggle的另一个没有测试标签的数据集上使用此示例.

I am currently trying to use this example on another dataset from Kaggle that does not have test labels.

如果我在没有相应标签的测试数据集上运行模型,因此无法像MNIST示例中那样计算准确性,我希望能够看到预测.可以以某种方式访问​​观测值及其预测的标签并很好地打印出来吗?

If I run the model on the test data set without corresponding labels and therefore unable to compute the accuracy like in the MNIST example, I would like to be able to see the predictions. Is it possible to access observations and their predicted labels somehow and print them out nicely?

推荐答案

我认为您只需要按照本教程中的说明评估输出张量即可:

I think you just need to evaluate your output-tensor as stated in the tutorial:

accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))

要获取张量的输出,请参见文档:

To get the output of a tensor see the docs:

在会话中启动图形后,可以将Tensor的值传递给Session.run()来计算它的值. t.eval()是调用tf.get_default_session().run(t)的快捷方式.

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:

If you want to get predictions rather than accuracy, you need to evaluate your ouput tensor y in the same way:

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

这篇关于如何在TensorFlow的MNIST示例中获取预测的类标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆