Closed shboy closed 6 years ago
我想infer出结果 结果这样写会报错:
Traceback (most recent call last):
File "train_infer.py", line 95, in
input
参数的类型需要是一个Python的List,而不是一个callable function.
参数说明: http://paddlepaddle.org/docs/develop/api/en/run_logic.html?highlight=infer#inference
样例: https://github.com/PaddlePaddle/book/blob/develop/01.fit_a_line/infer.py#L11
with open('/work/shenhao/test_data/event_day=2017010406070912_shuffle_test/2017010406070912', 'r') as f:
line = f.readline().strip(' ').split()
X_C = line[1: 331345]
#X_C = np.asarray(X_C)
X_P = line[331345: 331345+110448]
#X_P = np.asarray(X_P)
X_T = line[441793: 441793+110448]
#X_T = np.asarray(X_T)
X_E = line[552241: 552241+31]
#X_E = np.asarray(X_E)
global data_infer
data_infer = []
data_infer.append(X_C)
data_infer.append(X_P)
data_infer.append(X_T)
data_infer.append(X_E)
# Create parameters
para_path = '/work/shenhao/paddle/STResNet_network_ok/params_pass_99.tar'
print len(data_infer)
with open(para_path, "r") as f:
parameters = paddle.parameters.Parameters.from_tar(f)
img = paddle.infer(
output_layer=main_output,
parameters=parameters,
input=[item for item in data_infer],
feeding={'input_c': 0,
'input_p': 1,
'input_t': 2,
'input_ex': 3})
print img
我改成这样了 报了另外的错
Traceback (most recent call last):
File "train_infer.py", line 80, in <module>
main()
File "train_infer.py", line 74, in main
'input_ex': 3})
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/inference.py", line 172, in infer
return inferer.infer(field=field, input=input, feeding=feeding)
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/inference.py", line 107, in infer
for result in self.iter_infer_field(field=field, **kwargs):
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/inference.py", line 94, in iter_infer_field
for result in self.iter_infer(**kwargs):
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/inference.py", line 87, in iter_infer
yield self.__gradient_machine__.forwardTest(feeder(data_batch))
File "/usr/local/lib/python2.7/dist-packages/py_paddle/dataprovider_converter.py", line 282, in __call__
return self.convert(dat, argument)
File "/usr/local/lib/python2.7/dist-packages/paddle/v2/data_feeder.py", line 133, in convert
return DataProviderConverter.convert(self, reorder_data(dat), argument)
File "/usr/local/lib/python2.7/dist-packages/py_paddle/dataprovider_converter.py", line 267, in convert
scanner.pre_scan(each_step)
File "/usr/local/lib/python2.7/dist-packages/py_paddle/dataprovider_converter.py", line 114, in pre_scan
"The input should be a vector, please check your input data."
ValueError: The input should be a vector, please check your input data.
@Yancey1989
请按照demo和文档检查下输入的格式,应该是预测数据的List,例如你每天待预测的数据是类似
(1,2,3,4)
这种,那么你的input应该是类似:
[
(1,2,3,4),
(3,4,5,5),
...
]
With a short discuss offline this issue has been fixed, and I'll close this issue, please feel free to reopen it.