AttributeError: module ‘tensorflow._api.v2.train‘ has no attribute ‘NewCheckpointReader‘解决方案

解决AttributeError: module ‘tensorflow._api.v2.train’ has no attribute ‘NewCheckpointReader’


问题描述:

TensorFlow版本是2.8.0,执行如下代码:

reader = tf.train.NewCheckpointReader(filename)

报错如下:

AttributeError: module 'tensorflow._api.v2.train' has no attribute 'NewCheckpointReader'

原因分析:

TensorFlow 2.0以上的版本已经移除 tf.train.NewCheckpointReader 了。


解决方案:

tf.compat.v1.train.NewCheckpointReader 替换 tf.train.NewCheckpointReader 即可。

# reader = tf.train.NewCheckpointReader(filename)
reader = tf.compat.v1.train.NewCheckpointReader(filename)

tf.compat.v1.train.NewCheckpointReader

如果代码多处因版本问题出现报错,可改换低版本的TensorFlow,用pip安装即可。

pip uninstall tensorflow
pip install tensorflow==1.14

猜你喜欢

转载自blog.csdn.net/qq_39691492/article/details/123093603