输出TensorFlow 模型的变量名及对应值
2018-06-06 本文已影响10人
ziyu123
import os
import numpy as np
from tensorflow.python import pywrap_tensorflow
np.set_printoptions(threshold = np.inf) # numpy array 完整输出
model_dir = "模型路径"
checkpoint_path = os.path.join(model_dir, "model.ckpt")
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)
print(reader.get_tensor(key)) # Remove this if you want to print only variable names