How to get predicted class labels in TensorFlow's MNIST example?

前端 未结 2 1806
心在旅途
心在旅途 2021-01-03 11:53

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

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

相关标签:
2条回答
  • 2021-01-03 12:22

    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:

    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).

    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}))
    
    0 讨论(0)
  • 2021-01-03 12:28
    prediction=tf.argmax(y,1)
    print prediction.eval(feed_dict={x: mnist.test.images}).
    

    For more details, check out https://github.com/tensorflow/tensorflow/issues/97

    0 讨论(0)
提交回复
热议问题