tf.Print
 该op已经deprecated,目前已经不建议使用
 以前大部分使用tf.Print 打印变量类似一下代码
 1
2
3
4some_op = ...
some_op = tf.Print(some_op, [tf.shape(some_op), "some_op:"])
...
sess.run(some_op)
 这个API已经在新的里面被移除了,使用小写tf.print代替,但是操作方式有点差异
tf.print
tf.print
没有是一个print operation
| 1 | import tensorflow as tf | 
x [0 1 2 … 7 8 9]
x_no_summarize [0 1 2 3 4 5 6 7 8 9]
x_output_stream [0 1 2 … 7 8 9]
[ 0 3 6 9 12 15 18 21 24 27]
| 1 | cat /tmp/debug.log | 
tf.print eager 模式
- 单个tensor - 1 
 2
 3- tf.compat.v1.enable_eager_execution() 
 tensor = tf.range(10)
 tf.print(tensor, output_stream=sys.stderr)
- 多个tensor - 1 
 2
 3- tf.compat.v1.enable_eager_execution() 
 tensor = tf.range(10)
 tf.print("tensors:", tensor, {2: tensor * 2}, output_stream=sys.stdout)
- 函数内 - 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11- import tensorflow as tf 
 import sys
 tf.enable_eager_execution()
 @tf.contrib.eager.defun
 def f():
 tensor = tf.range(10)
 tf.print("debug:", tensor, output_stream=sys.stderr)
 return tensor
 range_tensor = f()
