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]: To print the value of a tensor without returning it to your Python program, you can use the tf. print() operator, as Andrzej suggests in another answer. According to the official documentation: To make sure the operator runs, users need to pass the produced op to tf.
To print to a file, pass a string started with "file://" followed by the file path, e.g., "file:///tmp/foo.out". The first and last summarize elements within each dimension are recursively printed per Tensor. If None, then the first 3 and last 3 elements of each dimension are printed for each tensor.
You can use tf. function to make graphs out of your programs. It is a transformation tool that creates Python-independent dataflow graphs out of your Python code. This will help you create performant and portable models, and it is required to use SavedModel .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With