Retrieving data from a TensorFlow object - a list of logical elements from correct_prediction

I turn to the MNIST beginner's tutorial ( http://www.tensorflow.org/tutorials/mnist/beginners/index.html ) and try to get a logical list of exactly predicted values ​​from the correct_prediction tensor object, I find this confusing.

According to the correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))suppost tutorial , to give us a list of booleans:

This gives us a list of booleans. To determine which fraction is correct, we drop the floating point numbers and then take the average value. For example, [True, False, True, True] will become [1,0,1,1], which is 0.75.

However, Trying correct_prediction[0]gives us <tensorflow.python.framework.ops.Tensor at 0x111a404d0>. type(correct_prediction)gives us tensorflow.python.framework.ops.Tensorwhich is not a list. A call dir()to view methods and then correct_prediction.__getitem__(0)gives us <tensorflow.python.framework.ops.Tensor at 0x111386f50>.

How do I access a list of predicted logical values ​​for these y, W, and b values? Should they somehow access from tf.Session?

Many thanks!

+4
source share
1 answer

Tensor variables actually describe the calculations that must be performed to obtain the values ​​of interest to you.

, , correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)), , . , , tensorflow .

tf.Session. sess = tf.InteractiveSession(), : sess.run(tf.initialize_all_variables()).

sess.run(tensor_variable), ( ). ( ), . .

session.run() .eval() . .

+2

Source: https://habr.com/ru/post/1618517/


All Articles