stanford-tensorflow-tutorials icon indicating copy to clipboard operation
stanford-tensorflow-tutorials copied to clipboard

Hotfix mnist sess run

Open Atlas7 opened this issue 7 years ago • 0 comments

The current example MNIST code has this line in it:

accuracy_batch = sess.run([accuracy], feed_dict={X: X_batch, Y:Y_batch})

This gives error (attempting to add a list to an int):

---> 33     total_correct_preds += accuracy_batch
     34   print('Accuracy {0}'.format(total_correct_preds/mnist.test.num_examples))
     35

TypeError: unsupported operand type(s) for +: 'int' and 'list'

This hotfix fixes it, by ensuring we are parsing a tensor object (instead of a list of 1 tensor object). i.e.

accuracy_batch = sess.run(accuracy, ...)

Note: Parsing a list is only appropriate when we are parsing multiple tensor objects. i.e. the following would work (and produce no error):

accuracy_batch_a, accuracy_batch_b = sess.run([accuracy, accuracy], ...)

Atlas7 avatar Jan 03 '18 16:01 Atlas7