Introductory MNIST example from Tensorflow results

2019-07-30 09:03发布

问题:

Running the first example on Tensorflow's tutorial results in an exception. Tutorial: https://www.tensorflow.org/get_started/mnist/beginners

Code: https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/examples/tutorials/mnist/mnist_softmax.py

The error I am encountering is:

An exception has occurred, use %tb to see the full traceback

I am using Python 3.6 and the latest version of Tensorflow. Can anyone else try running the code and see if a similar error occurs?

回答1:

The error is produced in ipython (Jupyter), because Tensorflow forces system exit, which ipython doesn't like. See for instance this discussion.

Luckily, system exit is done by tf.app.run method, so the solution for you is to inline the FLAGS.data_dir flag (set the local path to MNIST) and run main manually:

if __name__ == '__main__':
  main(None)

You can even go on and inline the whole main method if you like.