Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paddle android capi应用forward异常问题 #3498

Closed
bushidonggua opened this issue Aug 15, 2017 · 2 comments
Closed

paddle android capi应用forward异常问题 #3498

bushidonggua opened this issue Aug 15, 2017 · 2 comments

Comments

@bushidonggua
Copy link

bushidonggua commented Aug 15, 2017

android下每次运行到forward以前是好好的,一运行到forward就退出,主要是日志里也没看到相关的异常,不知是不是我的用法哪不对,以下frame 来自图片opencv Mat:

代码:
初始化部分:
char* argv[] = { "--use_gpu=False" };
CHECK(paddle_init(1, (char**)argv));
this->model_buf = read_config(MODEL_FILE, &this->model_size);
CHECK(paddle_gradient_machine_create_for_inference_with_parameters(
&machine, this->model_buf, this->model_size));

predict部分:
paddle_arguments in_args = paddle_arguments_create_none();
// There is only one input of this network.
CHECK(paddle_arguments_resize(in_args, 1));
int data_size = 3 * frame.cols * frame.rows;
int class_dim = 6;
// Create input matrix.
paddle_matrix mat = paddle_matrix_create(1, data_size, /* useGPU */ false);
paddle_real *array;
CHECK(paddle_matrix_get_row(mat, 0, &array));
int index = 0;
for (int i = 0; i < height; ++i)
{
for (int j = 0; j < width; ++j)
{
array[index++] = (paddle_real)frame.at(i, j)[2]; // R
array[index++] = (paddle_real)frame.at(i, j)[1]; // G
array[index++] = (paddle_real)frame.at(i, j)[0]; // B
}
}

CHECK(paddle_arguments_set_value(in_args, 0, mat));
paddle_arguments out_args = paddle_arguments_create_none();
paddle_error err = paddle_gradient_machine_forward(machine,
                                                       in_args,
                                                       out_args,
											/* isTrain */ false);
@Xreki
Copy link
Contributor

Xreki commented Aug 15, 2017

由于Paddleerror log信息都是打印到stdoutstderr,所以在Androidlogcat里面看不到错误信息。Debug的时候,可在Android项目里面加入android_log_wrapper.cpp文件,在调用android_start_logger()函数后,stdoutstderr里面的内容都会重定向到logcat,以助于定位真正的错误。
注意:android_start_logger()只适用于Debug。其中里面启动了一个线程,会耗费资源,发布产品时一定要注释掉。

经和线下实验@bushidonggua 的模型,发现真正的错误信息为:

F0815 08:58:39.674312  4686 NeuralNetwork.cpp:238] Check failed: inArgs.size() == dataLayers_.size() (1 vs. 2) 
*** Check failure stack trace: ***
    @     0x7f7bf649036d  google::LogMessage::Fail()
    @     0x7f7bf6493e1c  google::LogMessage::SendToLog()
    @     0x7f7bf648fe63  google::LogMessage::Flush()
    @     0x7f7bf649532e  google::LogMessageFatal::~LogMessageFatal()
    @     0x7f7bf65cf2f1  paddle::NeuralNetwork::forward()
    @     0x7f7bf648cc06  paddle_gradient_machine_forward
    @           0x40325c  main
    @     0x7f7bf4a10285  __libc_start_main
    @           0x40370d  (unknown)
Aborted (core dumped)

出现该错误的原因是,配置脚本是用于train的,需要datalabel两个输入layer。若要使用于inference,则需要手动修改配置文件,以配置正确的inoutsoutputs。有的配置文件里面提供了is_predict变量,则设置is_predict=True即可。请@bushidonggua 确认是否解决问题。

@bushidonggua
Copy link
Author

@Xreki 解决了,十分感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants