#原 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
#原 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