因為tensorflow2.0版本與之前版本有所更新,故將代碼修改即可:
#原 config = tf.ConfigProto(allow_soft_placement=True) config = tf.compat.v1.ConfigProto(allow_soft_placement=True) #原 sess = tf.Session(config=config) sess =tf.compat.v1.Session(config=config)
或使用
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
替換
import tensorflow as tf