美文网首页我爱编程
输出TensorFlow 模型的变量名及对应值

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

作者: ziyu123 | 来源:发表于2018-06-06 20:07 被阅读10次
    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 模型的变量名及对应值

        本文链接:https://www.haomeiwen.com/subject/ensisftx.html