用下面代码就可以轻松解决

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