load inference model之后执行预测时报错"should be Variable or str"
Created by: thuwangzhe
用save_inference_model的方式保存了模型文件,在执行预测时加载模型:
[self.predict_prog, self.feed_target_names, self.fetch_targets] = (fluid.io.load_inference_model(dirname=args.init_checkpoint, executor=self.exe))
self.predict_exe = fluid.ParallelExecutor(
use_cuda=args.use_cuda, main_program=self.predict_prog)
np_vecs = self.predict_exe.run(fetch_list=[self.fetch_targets])
之后报错
Traceback (most recent call last):
File "main.py", line 147, in <module>
main()
File "main.py", line 81, in main
predictor.process_file(input_filename,input_filename+'.txt')
File "/home/disk0/wangzhe23/qb_shuangta_12_128/predict.py", line 100, in process_file
np_vecs = self.predict_exe.run(fetch_list=[self.fetch_targets])
File "/home/disk0/wangzhe23/tools/python27_paddle_1.5.0/lib/python2.7/site-packages/paddle/fluid/parallel_executor.py", line 280, in run
return_numpy=return_numpy)
File "/home/disk0/wangzhe23/tools/python27_paddle_1.5.0/lib/python2.7/site-packages/paddle/fluid/executor.py", line 665, in run
return_numpy=return_numpy)
File "/home/disk0/wangzhe23/tools/python27_paddle_1.5.0/lib/python2.7/site-packages/paddle/fluid/executor.py", line 526, in _run_parallel
fetch_var_names = list(map(_to_name_str, fetch_list))
File "/home/disk0/wangzhe23/tools/python27_paddle_1.5.0/lib/python2.7/site-packages/paddle/fluid/executor.py", line 247, in _to_name_str
raise TypeError(str(var) + " should be Variable or str")
TypeError: [name: "save_infer_model/scale_0"
type {
type: LOD_TENSOR
lod_tensor {
tensor {
data_type: FP32
dims: -1
dims: 128
}
lod_level: 0
}
}
persistable: false
] should be Variable or str
这个save_infer_model/scale_0输出的向量就是我需要的output向量,不知道为什么会有这样的错误,排查了很久没有解决,辛苦review一下是哪里的问题