问题
How would I export a Random Forest model created with R into OpenCV?
I ask because I prototype in R (specifically Random Forest), but would like to be able to run my model in OpenCV due to the latter's speed with processing large images.
回答1:
Effectively, PMML is a one-way street. It is rather easy to export models from any framework-specific representation (eg. OpenCV, R) to PMML representation, but not so easy to do the opposite. The idea is that once you have your model in PMML representation, you should typically consume it using a dedicated PMML scoring engine, not some other technology.
In your case, what you want to do is to translate between OpenCV's CvRTrees class and R's randomForest data structure. You are probably better off by developing a direct two-way converter (ie. CvRTrees
<-> randomForest
) than using PMML as a middleman (ie. CvRTrees
<-> PMML
<-> randomForest
). This decision is easy to rationalize, because at the moment, there is only the randomForest
-> PMML
conversion component available. Therefore, it is probably less effort to develop two missing conversion components (ie. the former "direct" conversion scenario) than three missing conversion components (ie. the latter "mediated" conversion scenario).
To keep things simple, I would recommend to achieve "model portability" by using a shared training dataset. That is, if you need a OpenCV's RF model, then you would train it directly using the CvRTrees::train
method call, and if you need a R's RF model, then you would train it directly using the randomForest()
method call.
来源:https://stackoverflow.com/questions/27464604/export-random-forest-model-from-r-to-opencv