Export Random Forest model from R to OpenCV [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-25 06:48:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!