解决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
一个面向所有人的开源机器学习框架

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
推荐内容
GitHub 加速计划 / te / tensorflow
23
4
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:1 个月前 )
4f64a3d5 Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`. This prevents us from stepping into nested fusions. PiperOrigin-RevId: 724311958 1 个月前
aa7e952e Fix a bug in handling negative strides, and add a test case that exposes it. We can have negative strides that are not just -1, e.g. with a combining reshape. PiperOrigin-RevId: 724293790 1 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐