发布时间:2022-08-19 12:20
博客首页: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
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)