使用云平台或者别的服务器时,如果安装的是高版本的tf(tf2.x),跑比较旧的代码容易出现这种报错。解决方案:注释tf的引用,换为兼容模式。
# import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
当使用高版本TensorFlow(TF2.x)运行旧代码时,可能会遇到兼容性错误。本文提供了解决方案,通过启用兼容模式,注释掉默认的TF导入,并替换为TF1.x兼容版本。
使用云平台或者别的服务器时,如果安装的是高版本的tf(tf2.x),跑比较旧的代码容易出现这种报错。解决方案:注释tf的引用,换为兼容模式。
# import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
3344