Mohan Rayapuvari
Mohan Rayapuvari

Reputation: 421

tensorflow tf.Print not printing anything in Jupyter

Trying debug statements in Python/tensorflow1.0 using jupyter , but does not get any output printed from tf.Print

Thought sess.run(during training in below code) should have evaluated db1 tensor and print output which did not happen However db1.eval in evaluate phase , printing entire tensor X with out "message X:".

def combine_inputs(X):
 db1=tf.Print(X,[X],message='X:')
 return (tf.matmul(X, W) + b,db1)
<<training code>>
_,summary=sess.run([train_op,merged_summaries])
## merged_summaries tensor triggers combine_inputs function. There are  
## other tensor functions/coding in between , not giving entire code to keep   
## it simple; code works as expected except tf.Print

<<evaluate code>>
print(db1.eval())

Confused on following

a) Why tf.Print is not printing during sess.run during training?

b) Why explicit db1.eval is necessary , expected tf.Print to trigger with  
sess.run. If eval is required , could copy tensor X in my code to db1 
and evaluate it with out tf.Print. Correct?

Tried going through other questions (like below one). Suggested to implement memory_util or predefined function. As learner could not understand why tf.Print does not work in my scenario

If anyone encountered similar issues , please assist. Thanks!

Similar question in stackoverflow

Upvotes: 0

Views: 1734

Answers (2)

Dat
Dat

Reputation: 5813

You can check the terminal where you launched the jupyter notebook to see the message.

import tensorflow as tf

tf.InteractiveSession()

a = tf.constant(1)
b = tf.constant(2)

opt = a + b
opt = tf.Print(opt, [opt], message="1 + 2 = ")

opt.eval()

In the terminal, I can see:

2018-01-02 23:38:07.691808: I tensorflow/core/kernels/logging_ops.cc:79] 1 + 2 = [3]

Upvotes: 0

mmedina
mmedina

Reputation: 256

According to the documentation, tf.Print prints to standard error (as of version 1.1), and it's not compatible with jupyter notebook. That's why you can't see any output.

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

Upvotes: 1

Related Questions