1. 程式人生 > >restore not found的錯誤

restore not found的錯誤

pytho ret int pre tac spec 可能 code com

tensorflow保存模型後,restore的時候報參數not found是什麽原因呢

一般預測的流程是:建圖然後restore參數,很有可能你的變量作用域和train的時候不一樣,那麽在現在的變量域很可能找不到變量。

總而言之就是,保證和建圖的變量域是一致的,再restore

如何查看原來的變量域呢:

from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file

print_tensors_in_checkpoint_file(file_name=‘../model/model_396300.ckpt‘, tensor_name=‘‘,all_tensors=‘‘)

或者這種(未測試)

from tensorflow.python import pywrap_tensorflow
reader = pywrap_tensorflow.NewCheckpointReader(‘./model.ckpt‘)
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))

https://stackoverflow.com/questions/40719311/list-of-restored-variables-in-tensorflow

restore not found的錯誤