【发布时间】:2018-12-07 10:20:28
【问题描述】:
我是 TensorFlow 的新手。有问题的代码如下:
import tensorflow as tf
g = tf.Graph()
with g.as_default():
x = tf.constant(8, name="x_const")
y = tf.constant(5, name="y_const")
my_sum = tf.add(x, y, name="x_y_sum")
with tf.Session() as sess:
print(my_sum.eval())
上面的代码在 PyCharm 中运行没有任何错误,给出了正确的结果。但是当我从命令行尝试相同的代码时,我得到了一些我提供的屏幕截图的错误。 screenshot of the error
我无法理解错误的原因。错误状态中的主线:
"Cannot use the default session to evaluate tensor: the tensor's graph is
different from the session's graph.Pass an explicit session to
'eval(session=sess)'"
但即使我给出明确的会话,它也会显示几乎相同的错误。我也不明白为什么它在 PyCharm IDE 中运行时没有任何错误。
我的系统:
- Windows 7 Ultimate(64 位)
- 4GB 内存
- 英特尔奔腾 2020M 处理器
- 英特尔高清显卡
- Python 3.6.5(64 位)
- Tensorflow 版本 1.5.0
【问题讨论】:
标签: python python-3.x tensorflow pycharm