Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow tutorial MNST.py runs from Docker command line, but errors from Dockerized iPython notebook #415

Closed
JeffreyBenjaminBrown opened this issue Jul 12, 2017 · 8 comments
Labels
type:Question A question about the use of the docker stack images

Comments

@JeffreyBenjaminBrown
Copy link

I am launching jupyter/tensorflow-notebook via sudo docker run -v /home/jeff/code/tflow:/home/jovyan/work -it --rm -p 8888:8888 jupyter/tensorflow-notebook. That causes bash to print some things, including a link. I click that link to open a Jupyter Notebook in Chrome.

The sample MNST problem in the Tensorflow tutorials runs fine from the command line within that docker container:

jeff@jbb-lenovo:~/code/tflow$ sudo docker exec -it cb8909a41635 bash
jovyan@cb8909a41635:~$ cd work
jovyan@cb8909a41635:~/work$ python3 mnst.py
Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
passed 1 line
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
0.9171
jovyan@cb8909a41635:~/work$ 

However, from the notebook in Chrome, the same command (exec(open("./mnst.py").read())) prints the following to screen:

Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
0.9179
An exception has occurred, use %tb to see the full traceback.

SystemExit


/opt/conda/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2870: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Notice that it ran the program! Or at least close to it. From the command line it printed 0.9171, and from the notebook, 0.9179. The error only came after it printed that out -- and that print command is the last line of main() in mnst.py.

If I then evaluate %tb as the error suggests, I get the following:

----------------------------------------------------------------
SystemExit                     Traceback (most recent call last)
<ipython-input-4-5328e78f561e> in <module>()
----> 1 exec(open("./mnst.py").read())

<string> in <module>()

/opt/conda/lib/python3.6/site-packages/tensorflow/python/platform/app.py in run(main, argv)
     42   # Call the main function, passing through any arguments
     43   # to the final program.
---> 44   _sys.exit(main(_sys.argv[:1] + flags_passthrough))
     45 
     46 

SystemExit:
@JeffreyBenjaminBrown
Copy link
Author

Update: If instead of executing the file via exec() from within the Jupyter notebook, I paste the code into the notebook first and then evaluate, it runs with no errors.

@parente
Copy link
Member

parente commented Jul 13, 2017

Looks like the tensorflow code forcefully exits the process in which it's running after main completes. This isn't friendly to using it in a notebook, but is working as designed at the moment.

@parente parente added the type:Question A question about the use of the docker stack images label Jul 13, 2017
@JeffreyBenjaminBrown
Copy link
Author

Aha! Thanks, Peter!

@jpzwolak
Copy link

I have the exact same problem. I run Python 3.6 and tensorflow v.1.2 on Mac OS Sierra 10.12.6. I tried to copy-paste the entire code the the Jupyter notebook but I get the same error. When I run the code in the terminal everything worked just fine. Is there something I need to do in order to get the code running via Jupyter? (I want to ass that I am very new to Python)

@nb312
Copy link

nb312 commented Oct 28, 2017

I have the same error when I run the minst_softmax.py of tensorflow in the Anaconda.

@nb312
Copy link

nb312 commented Oct 28, 2017

the error occurred at the code :
with open(filename, 'rb') as f: exec(compile(f.read(), filename, 'exec'), namespace)

@nb312
Copy link

nb312 commented Oct 28, 2017

This error can ignore, for there is not affecting my program.

@jpzwolak
Copy link

jpzwolak commented Nov 1, 2017

I am not sure if that is completely correct, but what I think is happening is that the code on tensorflow website was written so that it can be compiled from a terminal. When I tried to run it from a jupyter notebook it was giving me an error, but when I removed the last two lines of the code, defined a dummy variable a = None and then run main(a) the code run as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Question A question about the use of the docker stack images
Projects
None yet
Development

No branches or pull requests

4 participants