module ‘tensorflow.python.pywrap_tensorflow‘ has no attribute ‘NewCheckpointReader‘的解决方法

 🔝🔝🔝🔝🔝🔝🔝🔝🔝🔝🔝🔝 

🥰 博客首页:knighthood2001

😗 欢迎点赞👍评论🗨️

❤️ 热爱python,期待与大家一同进步成长!!❤️

👀给大家推荐一款很火爆的刷题、面试求职网站👀

利用以下代码获取输出节点的检查点模型名称。

from tensorflow.python import pywrap_tensorflow

checkpoint_path = r'E:\crack\models_trainning\my_model\ckpt-2'
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()

for key in var_to_shape_map:
    print("tensor_name: ", key)

不过出现了以下错误

Traceback (most recent call last):
  File "C:/Users/knighthood/OneDrive/桌面/tensorflow_ckpt_2_pb-master/tensorflow_ckpt_2_pb-master/view_ckpt_graph.py", line 6, in <module>
    reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
AttributeError: module 'tensorflow.python.pywrap_tensorflow' has no attribute 'NewCheckpointReader'

module 'tensorflow.python.pywrap_tensorflow' has no attribute 'NewCheckpointReader'

原因:由于tensorflow版本有1.和2.的区别,以上只适用于tensorflow 1.的版本,争对tensorflow 2.的版本,可以使用如下代码

import tensorflow.compat.v1 as tf1

tf1.disable_v2_behavior()
checkpoint_path = r'E:\crack\models_trainning\my_model\ckpt-2'
# Read data from checkpoint file
reader = tf1.train.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()

for key in var_to_shape_map:
    print("tensor_name: ", key)

运行结果如下: 

 

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

knighthood2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值