输出TensorFlow 模型的变量名及对应值

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

来源:https://stackoverflow.com/questions/38218174/how-to-find-the-variable-names-that-are-saved-in-a-tensorflow-checkpoint/38226516#38226516

你可能感兴趣的:(输出TensorFlow 模型的变量名及对应值)