capi, 数据输入格式
Created by: hyo009
python做infer没问题,换成capi后报错
I0227 05:59:35.251722 445 Util.cpp:166] commandline: --use_gpu=false
I0227 05:59:35.256510 445 GradientMachine.cpp:83] Loading parameters from ./model/dnn_params_30min/
F0227 05:59:35.282200 445 TableProjection.cpp:39] Check failed: in_->ids
*** Check failure stack trace: ***
@ 0x7ff487fe876d google::LogMessage::Fail()
@ 0x7ff487fec21c google::LogMessage::SendToLog()
@ 0x7ff487fe8293 google::LogMessage::Flush()
@ 0x7ff487fed72e google::LogMessageFatal::~LogMessageFatal()
@ 0x7ff48801c6d5 paddle::TableProjection::forward()
@ 0x7ff488081db9 paddle::MixedLayer::forward()
@ 0x7ff48814c4bd paddle::NeuralNetwork::forward()
@ 0x7ff487fe4676 paddle_gradient_machine_forward
@ 0x402cc1 main
@ 0x7ff487398bd5 __libc_start_main
@ 0x401859 (unknown)
@ (nil) (unknown)
模型data leyer定义:
data_layer_dict = {}
for iter in ['cur_stream','up_stream_1', 'down_stream_1']:
data_stream = paddle.layer.data(
name=iter,
type=paddle.data_type.integer_value_sequence(2966))
data_layer_dict[iter] = data_stream
data_stream = paddle.layer.data(
name='vector',
type=paddle.data_type.dense_vector(490))
data_layer_dict['vector'] = data_stream
在python做infer时cur_stream,up_stream_1和down_stream_1都是长度为43的list,vector为长度为490的list。
capi中测试数据读入方式:
paddle_arguments in_args = paddle_arguments_create_none();
CHECK(paddle_arguments_resize(in_args, 4));
int array_cur[43];
int array_up[43];
int array_down[43];
int array_vec[490];
...
paddle_ivector cur_stream = paddle_ivector_create(array_cur, sizeof(array_cur) / sizeof(int), false, false);
paddle_ivector up_stream_1 = paddle_ivector_create(array_up, sizeof(array_up) / sizeof(int), false, false);
paddle_ivector down_stream_1 = paddle_ivector_create(array_down, sizeof(array_down) / sizeof(int), false, false);
paddle_ivector vector = paddle_ivector_create(array_vec, sizeof(array_vec) / sizeof(int), false, false);
CHECK(paddle_arguments_set_value(in_args, 0, cur_stream));
CHECK(paddle_arguments_set_value(in_args, 1, up_stream_1));
CHECK(paddle_arguments_set_value(in_args, 2, down_stream_1));
CHECK(paddle_arguments_set_value(in_args, 3, vector));
paddle_arguments out_args = paddle_arguments_create_none();
CHECK(paddle_gradient_machine_forward(machine,
in_args,
out_args,
false));
paddle_matrix prob = paddle_matrix_create_none();
CHECK(paddle_arguments_get_value(out_args, 0, prob));