Ask Your Question
0

RTrees save fails when setPriors() used.

asked 2019-11-20 02:20:08 -0600

frogeye gravatar image

I am trying to train a model with a skewed data set. So tried using

setPriors()

Now the application crashes while saving the model after training.

The code snippet below.

auto rTrees = cv::ml::RTrees::create();

rTrees->setMaxDepth(100);

rTrees->setMinSampleCount(2);

rTrees->setTermCriteria(cv::TermCriteria(cv::TermCriteria::MAX_ITER, 100, 0));

rTrees->setActiveVarCount(0);

rTrees->setTruncatePrunedTree(true);

weightMatrix = cv::Mat(1, 2, CV_32F, { 1.0, 100.0 });
rTrees->setPriors(weightMatrix);

rTrees->train(sampleData, cv::ml::ROW_SAMPLE, sampleLabel);

rTrees->save(path);

The crash happens while I am trying to save the model.
DTreesImpl::writeTrainingPrams() is the call in which crash happens.

At times save works and most of the time, it fails.

Anybody has experienced this before or know whats going on in here?

Thanks in advance.

edit retag flag offensive close merge delete

Comments

it fails

can you be more specific ? error msg ? gdb stack trace or such ?

opencv version ?

berak gravatar imageberak ( 2019-11-20 02:34:15 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-11-20 03:54:39 -0600

frogeye gravatar image

Hi, I found the issue. While setting the priors I was creating a Mat() with references to the weights for my labels. auto weightMatrix = cv::Mat(1, 2, CV_32F, { 1.0, 100.0 });

and was saving the file in other function. So it was not able to find weights values.

I changed it to

auto weightMatrix = cv::Mat::zeros(1, 2, CV_32F);

and now it works fine.

edit flag offensive delete link more

Comments

ahh, was just debugging that ;)

you could also initialize it properly like:

Mat_<float>(1,2) weightMatrix; 
weightMatrix  << 10.0, 100.0;
berak gravatar imageberak ( 2019-11-20 03:57:08 -0600 )edit

Thanks for looking into it.

frogeye gravatar imagefrogeye ( 2019-11-20 03:58:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-11-20 02:20:08 -0600

Seen: 150 times

Last updated: Nov 20 '19