Ask Your Question
0

OpenCV 3 Boost train help

asked 2016-04-05 16:38:39 -0500

Killerwife gravatar image

updated 2016-04-06 09:15:31 -0500

I am trying to train my own AdaBoost for object detection. I have compiled this code from examples but I encountered a problem.

cv::Mat* data=nullptr;
cv::Mat* responses = nullptr;
parser.toMat(&data,&responses);
cv::Ptr<cv::ml::Boost> boost = cv::ml::Boost::create();
boost->setBoostType(cv::ml::Boost::DISCRETE);
boost->setWeakCount(100);
boost->setWeightTrimRate(0.95);
boost->setMaxDepth(2);
boost->setUseSurrogates(false);
boost->setPriors(cv::Mat());
boost->train(cv::Mat(*data), cv::ml::ROW_SAMPLE, cv::Mat(*responses));
boost->save("trainedBoost.xml");

This error pops up when I use the train function "Expression: vector subscript out of range" It occurs on this line: err += wval*(result[i] != w->cat_responses[si]); in opencv_ml310d.dll!cv::ml::DTreesImplForBoost::updateWeightsAndTrim(int treeidx, std::vector<int,std::allocator<int> > & sidx) Line 235 C++

My data and responses cv::Mats have the exact same amount of rows. Responses is a cv::Mat with one collumn, containing a 0 or 1 depending on the class of each sample. Data mat is a cv::Mat of images I am trying to train on, each containing a person if its a positive sample. The format of the data cv::Mat consists of one image in each row of the cv::Mat.

I have compiled the latest opencv 3 from GitHub and to my knowledge it was compiled correctly thus far. Any ideas where I should look for an error?

Sample Data (using cv::FileStorage) in yml Sample Data

edit retag flag offensive close merge delete

Comments

can you try to find some simple (synthetic) test data, to reproduce your problem ?

berak gravatar imageberak ( 2016-04-06 06:40:53 -0500 )edit
2

I added a link to some uploaded sample data.

Killerwife gravatar imageKillerwife ( 2016-04-06 09:15:53 -0500 )edit

indeed, w->cat_responses was never initialized.

berak gravatar imageberak ( 2016-04-06 09:36:16 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-04-06 09:47:09 -0500

berak gravatar image

are you trying to do a classification or regression ?

w->cat_responses[si]

only gets correctly initialized here , if you use integer responses.

edit flag offensive delete link more

Comments

I am trying to do a classification. So I need to convert responses array to integers?

Killerwife gravatar imageKillerwife ( 2016-04-06 11:20:31 -0500 )edit
1

yes, indeed.

berak gravatar imageberak ( 2016-04-06 11:24:22 -0500 )edit

Yes, that fixed the problem. Now I need to figure out why my XML weights are only 0 and 0. but thats a different issue completely. Thank you.

Killerwife gravatar imageKillerwife ( 2016-04-06 11:38:20 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-04-05 16:38:39 -0500

Seen: 574 times

Last updated: Apr 06 '16