chiphuyen / stanford-tensorflow-tutorials

This repository contains code examples for the Stanford's course: TensorFlow for Deep Learning Research.
http://cs20.stanford.edu
MIT License
10.32k stars 4.32k forks source link

03_logistic_regression_mnist, line 81, TypeError: #62

Open jerinw opened 7 years ago

jerinw commented 7 years ago

could someone tell me how to deal with it.

Traceback (most recent call last): File "C:/Users/Jerin/PycharmProjects/pyflow/main.py", line 81, in total_correct_preds += accuracy_batch TypeError: unsupported operand type(s) for +=: 'int' and 'list'

physhik commented 6 years ago

if you see the print accuracy_batch, you'll notice it is list. You should flatten to have the float number to add up.

total_correct_preds += accuracy_batch[0]

will work.

Atlas7 commented 6 years ago

I have created a Pull Request #85 to fix this issue. I have explained what is happening in the Pull Request.

In a nutshell, the line (returns a list of 1 value):

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

needs to be changed to (returns a scalar):

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