tensorflow报错raise RuntimeError('The Session graph is empty.  Add operations to the ' RuntimeError:

tensorflow报错raise RuntimeError('The Session graph is empty.  Add operations to the '

RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().

这个是在安装tensorflow的时候为了测试安装是否成功,然后就用了网上的方法,但是在运行如下代码的时候却产生了错误

import tensorflow as tf

import os

# os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 这是默认的显示等级,显示所有信息

os.environ["TF_CPP_MIN_LOG_LEVEL"]='2'

sess = tf.Session()

a = tf.constant(2)

b = tf.constant(2)

print(sess.run(a+b))

一开始是怀疑自己本地问题tensorflow没有下载全,后来百度了下没有解决,又想到是不是安装过程出错了,问题还真的就在这里,在我创建好tensorflow环境后,执行pip install tensorflow 这个默认下载的是2.0.0版本的,但是conda却不支持,所以我们在下载前要看看conda支持的tensorflow

版本,执行下边命令conda search --full -name tensorflow,如图

好了到这里我们根据自己的tensorflow的python版本选择就好了,然后执行

pip install tensorflow==1.x.x就好了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章