Whenever I try printing I always get truncated results
import tensorflow as tf
import numpy as np
np.set_printoptions(threshold=np.nan)
tensor = tf.constant(np.ones(999))
tensor = tf.Print(tensor, [tensor])
sess = tf.Session()
sess.run(tensor)
As you can see I've followed a guide I found on Print full value of tensor into console or write to file in tensorflow
But the output is simply
...\core\kernels\logging_ops.cc:79] [1 1 1...]
I want to see the full tensor, thanks.
To avoid truncation and to control how much of the tensor data is printed use the same API as numpy's numpy. set_printoptions(threshold=10_000) . If your tensor is very large, adjust the threshold value to a higher number. All the available set_printoptions arguments are documented here.
[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.
print_tensor(y_true, message='y_true = ') y_pred = K. print_tensor(y_pred, message='y_pred = ') ... The function returns an identical tensor. When that tensor is evaluated, it will print its content, preceded by message .
You can do it as follows in TensorFlow 2.x:
import tensorflow as tf
tensor = tf.constant(np.ones(999))
tf.print(tensor, summarize=-1)
From TensorFlow docs -> summarize: The first and last summarize elements within each dimension are recursively printed per Tensor. If set to -1, it will print all elements of every tensor.
https://www.tensorflow.org/api_docs/python/tf/print
This is solved easily by checking the Tensorflow API for tf.Print
. Pass summarize=n
where n
is the number of elements you want displayed.
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