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.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

上一篇:LeetCode刷题笔记 1122 数组的相对排序


下一篇:阶段3-练习2