在使用pre-train model時候,我們需要restore variables from checkpoint files.
經常出現在checkpoint 中找不到”Tensor name not found”.
這時候需要查看一下ckpt中到底有哪些變量
import osfrom tensorflow.python import pywrap_tensorflowcheckpoint_path = os.path.join(model_dir, "model.ckpt")# Read data from checkpoint filereader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)var_to_shape_map = reader.get_variable_to_shape_map()# Print tensor name and valuesfor key in var_to_shape_map: print("tensor_name: ", key) print(reader.get_tensor(key))
可以顯示ckpt中的tensor名字和值,當然也可以用pycharm調試。
以上這篇Tensorflow: 從checkpoint文件中讀取tensor方式就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答