Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does tf.Print() does not print in tensorflow

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?

like image 200
A Das Avatar asked May 07 '16 03:05

A Das


People also ask

How do I print a TF tensor?

[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.

How do you print a tensor element?

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.

What is TF function ()?

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 .


Video Answer


1 Answers

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

like image 114
abhinonymous Avatar answered Oct 01 '22 10:10

abhinonymous