tf打印调试信息的方法 Debugging operation tf.Print

tf.Print(input_, data, message=None, first_n=None, summarize=None, name=None)

Prints a list of tensors. This is an identity op with the side effect of printing data when evaluating.

Args:

  • input_: A tensor passed through this op.这个参数是要处理的数据(可以称为处理前数据)
  • data: A list of tensors to print out when op is evaluated.这个参数(是一个列表)是上面的参数经过处理或者计算之后,想要打印的内容
  • message: A string, prefix of the error message.是一个字符串,接在data输出之前组成要打印的全部内容
  • first_n: Only log(记录) first_n number of times. Negative numbers log always; this is the default.
  • summarize: Only print this many entries of each tensor.参数summarize默认为3,只打印3个参数
  • name: A name for the operation (optional).

Returns:

Same tensor as input_.

 举例子

 bgr = tf.Print(bgr, [tf.shape(bgr)], message='Shape of input image: ', summarize=4, first_n=1)
实际上打印出来的是Shape of input image:(224,224,3)

为什么要用这个函数?

tensorflow是通过先建图再运行的方式进行运行,这就使得我们写在图建立过程中的输出语句在图运行的时候并不能得到执行,从而使得调试困难. 我们想在运行过程中,对训练的一些变量进行追踪和打印,对一些错误进行输出分析

详细例子可以参考 tf打印调试信息方法

猜你喜欢

转载自blog.csdn.net/zz2230633069/article/details/81393805
tf