Tensorflow安裝以及RuntimeError: The Session graph is empty. Add operations to the graph before calling run().解決方法


Tensorflow安裝

之前裝過pytorch,但是很多老的機器學習代碼都是tensorflow,所以沒辦法,還要裝個tensorflow。

在安裝之前還要安裝nvidia驅動還有cudn之類的,這些我已經在之前的篇章介紹過,就不在這細說了,可以直接傳送過去看。
那么前面這些搞完,直接運行下面的命令:
pip install --upgrade tensorflow-gpu

上面這行命令,會自動下載你的對應版本或者最新版本,現在下載應該是2.0版本的。

sess.run()無法運行

問題產生的原因:無法執行sess.run()的原因是tensorflow版本不同導致的,tensorflow版本2.0無法兼容版本1.0.
解決辦法:
tf.compat.v1.disable_eager_execution()

具體的測試tensorflow是否裝好代碼:

import tensorflow as tf
tf.compat.v1.disable_eager_execution() #保證sess.run()能夠正常運行
hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session()#版本2.0的函數
print(sess.run(hello))

參考鏈接:
https://blog.csdn.net/weixin_38410551/article/details/103631977


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM