Steven
Steven

Reputation: 430

How to set the number of trees in OpenCV random tree?

I'm new to OpenCV. Used to use the random forest library in R which allows you to set the number of trees to be trained. Is it possible to set this value in OpenCV 3.0?

Also, what other parameters can be tuned?

This is what I have right now:

 // randome forest classifier
Ptr<RTrees> rfClassifier = RTrees::create();
rfClassifier->setMaxDepth(5);
rfClassifier->setMinSampleCount(3);
rfClassifier->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

I check the TermCriteria::Type, it seems I should set it to use 50 trees like this?

int numTrees = 50;    
TermCriteria(TermCriteria::COUNT, numTrees, 1e-6)

Upvotes: 3

Views: 1522

Answers (1)

Seongeun  So
Seongeun So

Reputation: 817

Yes, you're right.

After training the Random forest model, you can save the file and check the number of tree that specified in model file.

In the model file, you can find field named ntrees:

Upvotes: 1

Related Questions