How do I save and upload a random forest once I have trained it?
I used OpenCV code to train a random forest classifier. But I cannot find any documentation on how to save and upload it to use. I don't want to have to retrain it each time. Does anyone have the code for doing this?
in opencv2.4, all ml classes inherit from StatModel, so you can use load() and save() to xml/yml files.
in opencv3, there is a slight difference - load() will return a new object
Yes, I am using load() and save(), but how do I use the CvMLData that I get when I load the classifier? I am looking for code that does the job. I have the code to train it and then test it, but I don't see any method for using it for test data once I have loaded a pre-trained model. I have tried to use predict, but it is expecting something else besides a CvMLData.
It baffles me that there is easy, clear sample code in the OpenCV textbook for training and testing a random forest classifier, but there is nothing for just loading a trained classifier and using it, which should be even easier to do. I have gone through the letter recognition example, but they are rewriting the entire read .csv function. There must be an easy way to do it.
hmm, i'm confused.
CvMlData is for getting the traindata into the classifier for training, right ? once you trained your forest, you save the trained classifier, and load it later for prediction.
imho, you do not need CvMlData at that stage at all.
(also, bear with me, not too familiar with 2.4 ml classes anymore...)
What I mean is that when I am loading a classifier that I already trained and saved, using the load function returns a CvMLData, but using predict requires a CvMat instead. I have tried all kinds of ways of getting this to work, but nothing works.