【发布时间】:2020-04-07 17:36:26
【问题描述】:
我遇到了 Session 模块的问题。
import tensorflow as tf
n1 = tf.constant(3.0)
n2 = tf.constant(4.0)
print(n1)
sess = tf.Session()
print(sess.run([n1,n2]))
下面是我收到的控制台输出。
runfile('C:/Users/Rushabh Shah/.spyder-py3/temp.py', wdir='C:/Users/Rushabh Shah/.spyder-py3')
tf.Tensor(3.0, shape=(), dtype=float32)
Traceback (most recent call last):
File "C:\Users\Rushabh Shah\.spyder-py3\temp.py", line 11, in <module>
sess = tf.Session()
AttributeError: module 'tensorflow' has no attribute 'Session'
【问题讨论】:
-
看看stackoverflow.com/questions/55142951/…。不确定您的版本是什么,但也许这会有所帮助。
-
是的,这很有用。但在此之后我收到如下新错误
-
tf.Tensor(3.0, shape=(), dtype=float32)Traceback(最近一次调用最后):文件“C:\Users\Rushabh Shah\.spyder-py3\temp.py” ,第 12 行,在
print(sess.run('Hello')) 文件“G:\Rushabh_Shah\envs\tf_env\lib\site-packages\tensorflow_core\python\client\session.py”中,第 956 行,在运行 run_metadata_ptr) 文件 "G:\Rushabh_Shah\envs\tf_env\lib\site-packages\tensorflow_core\python\client\session.py",第 1105 行,在 _run raise RuntimeError('会话图为空。添加操作到' RuntimeError: 会话图为空。在调用 run() 之前向图中添加操作。
标签: python tensorflow