View source on GitHub |
Print the specified inputs.
tf.print(
*inputs, **kwargs
)
A TensorFlow operator that prints the specified inputs to a desired output stream or logging level. The inputs may be dense or sparse Tensors, primitive python objects, data structures that contain tensors, and printable Python objects. Printed tensors will recursively show the first and last elements of each dimension to summarize.
Example | |
---|---|
Single-input usage:
(This prints "[0 1 2 ... 7 8 9]" to sys.stderr) Multi-input usage:
(This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to sys.stdout) Changing the input separator:
(This prints "[0 1],[0 2]" to sys.stderr) Usage in a
(This prints "[0 1 2 ... 7 8 9]" to sys.stderr) |
Compatibility usage in TF 1.x graphs:
In graphs manually created outside of tf.function
, this method returns
the created TF operator that prints the data. To make sure the
operator runs, users need to pass the produced op to
tf.compat.v1.Session
's run method, or to use the op as a control
dependency for executed ops by specifying
with tf.compat.v1.control_dependencies([print_op])
.
tf.compat.v1.disable_v2_behavior() # for TF1 compatibility only
sess = tf.compat.v1.Session()
with sess.as_default():
tensor = tf.range(10)
print_op = tf.print("tensors:", tensor, {2: tensor * 2},
output_stream=sys.stdout)
with tf.control_dependencies([print_op]):
tripled_tensor = tensor * 3
sess.run(tripled_tensor)
(This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to sys.stdout)
Returns | |
---|---|
None when executing eagerly. During graph tracing this returns
a TF operator that prints the specified inputs in the specified output
stream or logging level. This operator will be automatically executed
except inside of tf.compat.v1 graphs and sessions.
|
Raises | |
---|---|
ValueError
|
If an unsupported output stream is specified. |