今天在跑Tensorflow测试程序的时候,遇到了一下问题。
测试程序
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0], name="a")
b = tf.constant([3.0, 4.0, 3.0], name="b")
result = a + b
sess = tf.Session()
print(sess.run(result))
报错1:
原因:tensorflow版本问题
解决办法:
使用
sess = tf.compat.v1.Session()
注意Session后面的括号,我之前忘了加括号就报错。
报错2:
原因:还是因为版本问题
解决办法:
在前面加上这一行代码
tf.compat.v1.disable_eager_execution()
最后的测试程序是:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
a = tf.constant([1.0, 2.0, 3.0], name="a")
b = tf.constant([3.0, 4.0, 3.0], name="b")
result = a + b
result2 = a + b
sess = tf.compat.v1.Session()
print(sess.run(result))
后记:tensorflow版本问题太多…对我很不友好…但是也反映一个问题,我只知道是版本问题,也不知道为什么会出现版本问题,后续学习可以关注一下。
参考链接:
https://blog.csdn.net/qq_33440324/article/details/94200046
https://blog.csdn.net/weixin_38410551/article/details/103631977