Ask Your Question

banshees.beat's profile - activity

2016-12-12 06:02:37 -0500 received badge  Editor (source)
2016-12-09 05:11:08 -0500 asked a question ANN_MLP segmentation fault on predict() if not directly preceeded by train()


i am using c++ OpenCV 3.1 on Ubuntu Xenial. I think i found a bug in OpenCV but want to reassure that I am not missing something.

I have code that first trains my ANN_MLP with training data in one method. Then, on user input a new sample is generated and forwarded to my predict() wrapping method.

This is how a snippet looks

Mat_<float> responses = Mat::zeros(data.rows, categories.size(), data.type());
(...) //fillup responses
Mat_<int> layer_sizes(1, 3); //gets filled up
(...) //fillup layer_sizes
mlp = ml::ANN_MLP::create(); // mlp is a class variable
mlp->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM, 0.1, 0.1);
mlp->setTrainMethod(ml::ANN_MLP::BACKPROP, 0.1, 0.1);

traindata = ml::TrainData::create(data, ml::ROW_SAMPLE, responses); //traindata is a class variable

training works well here! Now when I go to predict within another method of the same class and I take a row from the trained set I get a segmentation fault except I do it this way

mlp->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM, 0.1, 0.1); 
mlp->predict(feature, results);

As you see I have to set the activation function again and train again. This is really annoying. It may be somewhat related to the following bug: Because when I run the program with gdb I get a message containing


related to an error. Now I think that ANN_MLP internally misses to internally store the activation function as well as the trained data (or parts of this).

What do you think?

Here is the gdb bt output. Sadly, i cannot compile OpenCV in debug mode.

    Thread 1 "xxx" received signal SIGSEGV, Segmentation fault.
0x00007ffff5a59e9a in icv_y8_ownMinMaxIndx_32f_C1R_U8_2 () from /xxx/ros/kinetic/lib/
(gdb) bt
#0  0x00007ffff5a59e9a in icv_y8_ownMinMaxIndx_32f_C1R_U8_2 () from /xxx/ros/kinetic/lib/
#10 0x00000000011dc380 in ?? ()
#11 0x00007fffffff9cb8 in ?? ()
#12 0x0000000000000008 in ?? ()
#13 0x00007ffff57ce5d7 in icv_y8_ippiMinMaxIndx_32f_C1R () from /xxx/ros/kinetic/lib/
#14 0x00007ffff5490f97 in cv::minMaxIdx(cv::_InputArray const&, double*, double*, int*, int*, cv::_InputArray const&) () from /xxx/ros/kinetic/lib/