解决AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘
tensorflow2解决AttributeError: module ‘tensorflow’ has no attribute ‘Session’
代码
ys = tf.Session().run(sigmoid)
报错信息
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-6d9c3954d7ab> in <module>()
1 xs = np.linspace(-10.0, 10.0, num=100)
2 sigmoid = tf.nn.sigmoid(xs)
----> 3 ys = tf.Session().run(sigmoid)
4 show_me(xs, ys, (-0.1, 1.15), .5)
AttributeError: module 'tensorflow' has no attribute 'Session'
解决方法
查看tensorflow版本信息
pip list
tensorflow 2.2.0
代码开头加入代码
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
tensorflow2下使用tensorflow1的方法
欢迎大家交流学习,任何问题都可以留言
还没有评论,来说两句吧...