Retrieving data from TensorFlow object - list of booleans from correct_prediction

I am going over MNIST beginner tutorial ( and trying to get a boolean list of accurately predicted values from the correct_prediction tensor object. I am finding this confusing.

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

That gives us a list of booleans. To determine what fraction are correct, we cast to floating point numbers and then take the mean. For example, [True, False, True, True] would become [1,0,1,1] which would become 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.Tensor which is not a list. Calling dir() to see methods and then correct_prediction.__getitem__(0) gives us <tensorflow.python.framework.ops.Tensor at 0x111386f50>.

How do I access the list of predicted booleans and for that matter values of y, W and b? Should they be accessed somehow from tf.Session?

Many thanks!


The tensor variables actually describe the computations that must be performed in order to obtain the values you are interested in.

In other words, the tensor defined with correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) doesn't contain the list of booleans, it contains the instructions for computing it in a tensorflow graph. In order to get the actual values, you need to tell tensorflow to compute it in a graph.

First, you need a tf.Session variable. A simple way to get it for testing in a interactive shell is sess = tf.InteractiveSession(), followed by variable initialization:

Then, you can call to compute the value of a given tensor (or a list of them). If your tensors include placeholders in their computations (which they usually do), you'll also have to provide a feed dictionary. This is exemplified in the tutorial.

Instead of, you can also call the .eval() method from tensors. This also needs that a default session exists.

Need Your Help

Extract fields from JSON response in Mule

json mule mule-studio

I have a JSON response which is like {"id":10,"name":"ABCD","deptId":0,"address":null}