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就好了

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