googledatalab / pydatalab

Google Datalab Library
Apache License 2.0
195 stars 81 forks source link

Provide a way for tf.Print to work in Datalab #312

Open qimingj opened 7 years ago

qimingj commented 7 years ago

Currently tf.Print prints stuff in c stdout, which is not reflected in sys.stdout. Users have to apply workarounds like http://stackoverflow.com/questions/37898478/is-there-a-way-to-get-tensorflow-tf-print-output-to-appear-in-jupyter-notebook-o. to get tf.Print stuff showing up.

One proposal is for Datalab to provide a context, such that tf.Print works if we write code like:

import tensorflow as tf import google.datalab.capture_stdout as cs:

with cs.Capture(): with tf.Graph().as_default():

Create a few example ops

a = tf.constant(1)
a = tf.Print(a, [a], "value of a")
# Example ops end

with tf.Session() as sess:
  sess.run(tf.Print(a, [a]))
brandondutra commented 7 years ago

I think one downside to a 'import google.datalab.capture_stdout as cs' is that this package has to be listed as a dependency in setup.py in user's code or added to --packages for training on ml engine...if the user expects the same code to work there.

Because we own the container, could this be solved by some set of jupyter configs? Maybe jupyter can look at some log and print anything that came from a tensorflow file?

My terminal shows:

{"name":"app","hostname":"7c78925abbd4","pid":96,"type":"jupyter","level":30,"msg":"[9000]: I tensorflow/core/kernels/logging_ops.cc:79] hi[1]\n","time":"2017-03-16T18:15:58.840Z" ,"v":0}

qimingj commented 7 years ago

from tf.print doc:

"Note: This op prints to the standard error. It is not currently compatible with jupyter notebook (printing to the notebook server's output, not into the notebook)."

https://www.tensorflow.org/api_docs/python/tf/Print

I think we should wait for a fix from tf.