关于预测时报错ValueError: No such parameter ___conv_pool_0___conv.w0
Created by: xiangjinxin1019
原先在docker环境下训练了一个model,现在打算直接在linux环境下使用该模型进行预测,但预测时报错。换docker环境下,预测时没有问题。
Traceback (most recent call last):
File "predict.py", line 190, in <module>
main()
File "predict.py", line 169, in main
input=test_data,
File "/home/users/xiangjinxin/PaddlePaddle/env2.7-gcc482/lib/python2.7/site-packages/paddle/v2/inference.py", line 154, in infer
inferer = Inference(output_layer=output_layer, parameters=parameters)
File "/home/users/xiangjinxin/PaddlePaddle/env2.7-gcc482/lib/python2.7/site-packages/paddle/v2/inference.py", line 50, in __init__
val.copyFromNumpyArray(parameters.get(name).flatten())
File "/home/users/xiangjinxin/PaddlePaddle/env2.7-gcc482/lib/python2.7/site-packages/paddle/v2/parameters.py", line 239, in get
return self.__getitem__(key=parameter_name)
File "/home/users/xiangjinxin/PaddlePaddle/env2.7-gcc482/lib/python2.7/site-packages/paddle/v2/parameters.py", line 182, in __getitem__
return self.__getter_inner(key, api.PARAMETER_VALUE)
File "/home/users/xiangjinxin/PaddlePaddle/env2.7-gcc482/lib/python2.7/site-packages/paddle/v2/parameters.py", line 149, in __getter_inner
shape = self.get_shape(key)
File "/home/users/xiangjinxin/PaddlePaddle/env2.7-gcc482/lib/python2.7/site-packages/paddle/v2/parameters.py", line 197, in get_shape
raise ValueError("No such parameter %s" % key)
ValueError: No such parameter ___conv_pool_0___conv.w0
预测部分的代码:
test_data = []
cur_dir = os.path.dirname(os.getcwd())
test_dir = os.path.join(cur_dir, 'dataset/small_num_test')
print 'test_dir:', test_dir
output_dir = os.path.join(cur_dir, 'holeView_keyboardModel/output6/params_pass_0.tar')
print 'output_dir:', output_dir
with open(output_dir, 'r') as f:
parameters = paddle.parameters.Parameters.from_tar(f)
# image index
index = 1
# total accuacy
accu_num = 0
label = None
for test_img in os.listdir(test_dir):
test_data.append((load_image(test_dir + '/' + test_img), ))
label_str = test_img.split('.')[0]
# print 'label_str is:', label_str
if label_str == 'correct':
label = 0
elif label_str == 'incorrect':
label = 1
else:
print 'label_str error:', label_str
raise TypeError
probs = paddle.infer(
output_layer=predict,
parameters=parameters,
input=test_data,
)