【问题标题】:tensorflow tf.Print not printing anything in Jupytertensorflow tf.Print 在 Jupyter 中不打印任何内容
【发布时间】:2017-04-14 14:48:42
【问题描述】:

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

Thought 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

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

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

    检查这里: https://www.tensorflow.org/api_docs/python/tf/Print

    【讨论】:

      【解决方案2】:

      您可以查看启动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]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-26
        • 2021-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多