问题产生的原因:无法执行sess.run()的原因是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.
解决办法:
tf.compat.v1.disable_eager_execution()

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))

后记:(1)对问题的认知,能够帮助自己快速定位问题。
      开始定位问题时,太懒,直接连英文的意思都没搞懂,就直接粘贴到百度去搜索,于是根本无法找到合适的答案。
   (2)明确问题,这个问题是图是空的,然后我去查看图建立的方法,没错,就是这样建立的。然后怀疑可能时无法执行sess.run()。
   (3)遇到问题,一定要深入思考一下,才是问题的根因,直接依据问题的表面去查找答案,根本无法找到。
参考链接:https://blog.csdn.net/sinat_36502563/article/details/102302392
参考链接:https://ask.csdn.net/questions/657580
————————————————
原文链接:https://blog.csdn.net/weixin_38410551/article/details/103631977

posted on 2021-04-23 22:55  swxj  阅读(247)  评论(0编辑  收藏  举报