tensorflow tf.Print不在Jupyter打印任何东西

时间:2017-04-14 14:48:42

标签: tensorflow

使用jupyter在Python / tensorflow1.0中尝试调试语句,但是没有从tf.Print打印任何输出

思考sess.run(在下面的代码训练期间)应该评估db1张量和打印输出没有发生 但是db1.eval在评估阶段,打印整个张量X而没有“消息X:”。

def combine_inputs(X):
 db1=tf.Print(X,[X],message='X:')
 return (tf.matmul(X, W) + b,db1)
<<training code>>
_,summary=sess.run([train_op,merged_summaries])
## merged_summaries tensor triggers combine_inputs function. There are  
## other tensor functions/coding in between , not giving entire code to keep   
## it simple; code works as expected except tf.Print

<<evaluate code>>
print(db1.eval())

Confused on following

a) Why tf.Print is not printing during sess.run during training?

b) Why explicit db1.eval is necessary , expected tf.Print to trigger with  
sess.run. If eval is required , could copy tensor X in my code to db1 
and evaluate it with out tf.Print. Correct?

尝试通过其他问题(如下面的一个)。建议实现memory_util或预定义函数。由于学习者无法理解为什么tf.Print在我的场景中不起作用

如果有人遇到类似问题,请提供帮助。谢谢!

Similar question in stackoverflow

2 个答案:

答案 0 :(得分:1)

根据文档,tf.Print打印到标准错误(从1.1版开始),并且它与jupyter笔记本不兼容。这就是为什么你看不到任何输出的原因。

点击此处: https://www.tensorflow.org/api_docs/python/tf/Print

答案 1 :(得分:0)

您可以查看发送jupyter notebook的终端以查看消息。

import tensorflow as tf

tf.InteractiveSession()

a = tf.constant(1)
b = tf.constant(2)

opt = a + b
opt = tf.Print(opt, [opt], message="1 + 2 = ")

opt.eval()

在终端,我可以看到:

2018-01-02 23:38:07.691808: I tensorflow/core/kernels/logging_ops.cc:79] 1 + 2 = [3]
相关问题