出现这个错误的原因是python代码是基于TensorFlow1.0的,而系统中的TensorFlow版本为2.0

所以两种解决思路:

  1. 把1.0的代码改为2.0
  2. 把TensorFlow降为1.0

我选择了第一种方法

AttributeError: module 'tensorflow' has no attribute 'ConfigProto'

出现报错的语句:

config = tf.ConfigProto()

修改后的语句:

config = tf.compat.v1.ConfigProto()

类似的:

AttributeError: module 'tensorflow' has no attribute 'Session'

出现报错的语句:

session = tf.Session(config=config)

修改后的语句:

session = tf.compat.v1.Session(config=config)

同样因为版本问题造成的错误:

RuntimeError: set_session is not available when using TensorFlow 2.0.

出现报错的语句:

KTF.set_session(session)

修改后的语句:

tf.compat.v1.keras.backend.set_session(session)
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐