module ‘tensorflow.python.pywrap_tensorflow‘ has no attribute ‘NewCheckpointReader‘的解决方法
🔝🔝🔝🔝🔝🔝🔝🔝🔝🔝🔝🔝
🥰 博客首页:knighthood2001
😗 欢迎点赞👍评论🗨️
❤️ 热爱python,期待与大家一同进步成长!!❤️
👀给大家推荐一款很火爆的刷题、面试求职网站👀
from tensorflow.python import pywrap_tensorflowcheckpoint_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 tf1tf1.disable_v2_behavior()checkpoint_path = r'E:\crack\models_trainning\my_model\ckpt-2'# Read data from checkpoint filereader = 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)
运行结果如下: