python - 为什么 tf.Print() 不在 tensorflow 中打印

标签 python tensorflow

下面的代码没有给出任何错误,但也没有打印张量。

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)

tf.print documentation

关于python - 为什么 tf.Print() 不在 tensorflow 中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37084124/

相关文章:

Python - 从文件夹中读取所有文件(.shp、.dbf、.mxd 等)

python - 我尝试创建一个面积计算器,它不断指出正确代码的语法无效

python - 如何使用 **kwargs 更改默认值?

python - 不同 GPU 上的 Tensorflow 执行和内存

rest - 使用 Celery 或 RESTful API 服务深度学习模型?

python - 为什么我安装 virtualenv 后 pip 不可用?

python - 如何从C :\Python37\Scripts?创建类似于pip.exe、jupyter.exe等的.exe

python - 使用图像数据生成器评估 keras 模型

python - tensorflow : optimizer gives nan as ouput

python - 检查 tf.Tensor 是否可变