134、TensorFlow檢查點checkpoint文件中的信息


# 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.]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM