tensorflow實現讀取模型中儲存的值 tf.train.NewCheckpointReader
阿新 • • 發佈:2020-02-11
使用tf.trian.NewCheckpointReader(model_dir)
一個標準的模型檔案有一下檔案,model_dir就是MyModel(沒有後綴)
checkpoint Model.meta Model.data-00000-of-00001 Model.index
import tensorflow as tf import pprint # 使用pprint 提高列印的可讀性 NewCheck =tf.train.NewCheckpointReader("model")
列印模型中的所有變數
print("debug_string:\n") pprint.pprint(NewCheck.debug_string().decode("utf-8"))
其中有3個欄位,分別是名字,資料型別,shape
獲取變數中的值
print("get_tensor:\n") pprint.pprint(NewCheck.get_tensor("D/conv2d/bias"))
print("get_variable_to_dtype_map\n") pprint.pprint(NewCheck.get_variable_to_dtype_map()) print("get_variable_to_shape_map\n") pprint.pprint(NewCheck.get_variable_to_shape_map())
以上這篇tensorflow實現讀取模型中儲存的值 tf.train.NewCheckpointReader就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。