打印出ckpt里的所有变量和值

参考:http://blog.csdn.net/helei001/article/details/56489658

from tensorflow.python import pywrap_tensorflow
import os
import numpy as np
import tensorlayer as tl

# print出ckpt里的所有变量
model_dir = './logs_vgg16/case_64'
checkpoint_path = os.path.join(model_dir, "model.ckpt-18000")
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
# var_to_shape_map里存储了所有变量和其值的键值对
var_to_shape_map = reader.get_variable_to_shape_map()

for key in var_to_shape_map:
    # 打印出所有key及其value
    # print(key,':')
    # print(reader.get_tensor(key))
    # 将键值对保存在npy文件中,var_to_shape_map表示保存所有键值对的字典
    var_to_shape_map[key] = reader.get_tensor(key)
    np.save('all_variables.npy',var_to_shape_map)

data2 = np.load('./all_variables.npy')
data = tl.files.load_npy_to_any(name='all_variables.npy')
print(data['vgg_16/conv5/conv5_1/biases'])

你可能感兴趣的:(打印出ckpt里的所有变量和值)