# 1、你想創建多少Saver對象就可以創建多少,如果你需要去保存和恢復不同的子圖模型 # 同樣的變量可以在不同的saver對象中被加載 # 只有在Saver.restore()方法被調用的時候才會對變量的值進行計算 # 2、如果你在session開始的時候只恢復一部分變量的值。 # 你必須重新初始化其他變量的值 # 3、如果想檢查checkpoint文件中變量的值,可以使用print_tensors_in_checkpoint_file函數 # 4、默認情況下,Saver使用tf.Variable.name屬性來保存變量 # 然而當你創建一個Saver對象的時候,你或許可以為checkpoint文件中的變量選擇一個名字 # 檢查checkpoint文件中的變量 import tensorflow as tf # import the inspect_checkpoint library from tensorflow.python.tools import inspect_checkpoint as chkp # print all tensors in checkpoint file chkp.print_tensors_in_checkpoint_file("tmp/model.ckpt", tensor_name=None, all_tensors=True, all_tensor_names=True) # print only tensor v1 in checkpoint file chkp.print_tensors_in_checkpoint_file("tmp/model.ckpt", tensor_name='v1', all_tensors=False, all_tensor_names=False) # print only tensor v2 in checkpoint file chkp.print_tensors_in_checkpoint_file("tmp/model.ckpt", tensor_name='v2', all_tensors=False, all_tensor_names=False)
下面是輸出的結果:
tensor_name: v1 [ 1. 1. 1.] tensor_name: v2 [-1. -1. -1. -1. -1.] tensor_name: v1 [ 1. 1. 1.] tensor_name: v2 [-1. -1. -1. -1. -1.]