下面的代码没有给出任何错误,但也没有打印张量。
import tensorflow as tf
import numpy as np
# Some tensor we want to print the value of
x = tf.placeholder(tf.float32, shape=[2, 2, 2])
a = np.array([[[1.,1.], [1.,1.]], [[2.,2.], [2.,2.]]])
m = tf.Print(x,[x])
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
m_eval = m.eval(session=sess,feed_dict={x: a})
编辑:在 bgshi 的回复之后,我发现在 iPython 控制台中,代码确实打印了张量值。但我正在使用 iPython 笔记本。有没有办法让它显示在笔记本上?
最佳答案
来自文档:
This op prints to the standard error. It is not currently compatible with jupyter notebook (printing to the notebook server's output, not into the notebook)
关于python - 为什么 tf.Print() 不在 tensorflow 中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37084124/