列印出ckpt裡的所有變數和值

weixin_34120274發表於2018-07-16

參考: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'])

相關文章