I have started using OpenCV 4.1 recently. I am trying to train a random forest model.
auto rTrees = cv::ml::RTrees::create();
rTrees->setMaxDepth(5);
rTrees->setMinSampleCount(3);
rTrees->setTermCriteria(cv::TermCriteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 100, 0.1));
rTrees->setActiveVarCount(0);
rTrees->setTruncatePrunedTree(true);
rTrees->train(data, cv::ml::ROW_SAMPLE, labels);
This trains the model and later I save the model. On reloading the model, I tried reading the values I set to the model while training.
auto rTrees = cv::ml::RTrees::create();
rTrees = cv::ml::StatModel::load<cv::ml::RTrees>(path);
int treeCount = rTrees->getTermCriteria().maxCount;
Whatever value I set while training I get the maxCount value as 50 which is the default value.
I also checked in the xml file in which I save the model ntrees tag has value as 1.
Any idea what am I doing wrong or how can I set the number of trees while training and read from the saved model upon reloading it?
Aucun commentaire:
Enregistrer un commentaire