【问题标题】:How to get predicted class labels in TensorFlow's MNIST example?如何在 TensorFlow 的 MNIST 示例中获得预测的类标签?
【发布时间】:2016-03-07 17:35:01
【问题描述】:

我是神经网络的新手,并通过了 MNIST 示例供初学者使用。

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

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

【问题讨论】:

    标签: python machine-learning neural-network tensorflow data-science


    【解决方案1】:

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

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

    要获得张量的输出,请参阅docs

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

    如果你想得到预测而不是准确度,你需要以同样的方式评估你的输出张量y

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

    【讨论】:

    • 当我尝试 print(sess.run(y, feed_dict={x: mnist.test.images})) 时,我得到:TypeError: unhashable type: 'numpy.ndarray'。其他人是否看到了这一点,或者它对他们有用吗?
    【解决方案2】:
    prediction=tf.argmax(y,1)
    print prediction.eval(feed_dict={x: mnist.test.images}).
    

    更多详情,请查看https://github.com/tensorflow/tensorflow/issues/97

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 2017-06-16
      • 2017-12-03
      • 1970-01-01
      相关资源
      最近更新 更多