问题
AttributeError: module ‘tensorflow’ has no attribute ‘Session’
原因
TensorFlow从2.0版本已经没有Session
了,除了Session
,还有placeholder
等旧版本的方法都不可以直接调用。
解决方法
imprt之后加一句tf.compat.v1.disable_eager_execution()
,保证sess.run()
能够正常运行。
在调用时指明使用的是老版本的方法,如tf.compat.v1.placeholder()
,tf.compat.v1.Session()