解决AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘

本是古典 何须时尚 2023-02-27 05:37 106阅读 0赞

tensorflow2解决AttributeError: module ‘tensorflow’ has no attribute ‘Session’

代码

  1. ys = tf.Session().run(sigmoid)

报错信息

  1. ---------------------------------------------------------------------------
  2. AttributeError Traceback (most recent call last)
  3. <ipython-input-3-6d9c3954d7ab> in <module>()
  4. 1 xs = np.linspace(-10.0, 10.0, num=100)
  5. 2 sigmoid = tf.nn.sigmoid(xs)
  6. ----> 3 ys = tf.Session().run(sigmoid)
  7. 4 show_me(xs, ys, (-0.1, 1.15), .5)
  8. AttributeError: module 'tensorflow' has no attribute 'Session'

解决方法

查看tensorflow版本信息

  1. pip list
  2. tensorflow 2.2.0

代码开头加入代码

  1. import tensorflow.compat.v1 as tf
  2. tf.disable_v2_behavior()

tensorflow2下使用tensorflow1的方法

欢迎大家交流学习,任何问题都可以留言

发表评论

表情:
评论列表 (有 0 条评论,106人围观)

还没有评论,来说两句吧...

相关阅读