11

The following code does not give any error but does not print the tensor too.

import tensorflow as tf
import numpy as np

# Some tensor we want to print the value of
x = tf.placeholder(tf.float32, shape=[2, 2, 2])
a = np.array([[[1.,1.], [1.,1.]], [[2.,2.], [2.,2.]]])

m = tf.Print(x,[x])

with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
    m_eval = m.eval(session=sess,feed_dict={x: a})

EDIT: after bgshi's reply, I found that in iPython console, the code does print the tensor value. But I'm using iPython notebook. Is there a way to make it displayed in notebook?

A Das
  • 817
  • 2
  • 10
  • 21
  • I tried your code and it does print the tensor. I use tensorflow 0.8, which version are you using? – bgshi May 07 '16 at 03:24
  • Hmm. Thats surprising. I'm using 0.8 too. I'm using it in ubuntu 14.04. I tried it in ipython notebook. Are you using ipython notebook too? Is it printing inline or is it being saved in a log file? – A Das May 07 '16 at 03:31
  • I am using the console. The output is `I tensorflow/core/kernels/logging_ops.cc:79] [1 1 1...]`. So it is saved into a log file, I suppose. – bgshi May 07 '16 at 03:34
  • After I tried in console, I'm getting exactly what you are getting. However I'm not being able to find the log file. Do you know if there is a way to make it work in ipython notebook? – A Das May 07 '16 at 03:45
  • I have little experience with ipython notebook, but this might help: http://stackoverflow.com/questions/14571090/ipython-redirecting-output-of-a-python-script-to-a-file-like-bash – bgshi May 07 '16 at 03:50
  • Thanks @bgshi , I will take a look at it. I also have modified the question so that its now more 'ipython notebook' centric. Let's see if some more insight comes out. – A Das May 07 '16 at 03:53
  • @ADas Could you add 'print(m_eval)'? – Sung Kim May 07 '16 at 05:04
  • Hi @SungKim , do you mean adding 'print(m_eval)' after m.eval? Yes, that prints the value, but I wanted to see how tf.Print works. – A Das May 07 '16 at 05:16
  • Another possible workaround for you: http://stackoverflow.com/questions/37898478/is-there-a-way-to-get-tensorflow-tf-print-output-to-appear-in-jupyter-notebook-o/39649614#39649614 – Eric Czech Sep 22 '16 at 22:11

1 Answers1

6

From the documentation:

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)

tf.print documentation

Jon
  • 9,156
  • 9
  • 56
  • 73
abhinonymous
  • 329
  • 2
  • 13