restore not found的错误

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
原文地址:https://www.cnblogs.com/dmesg/p/7485342.html