将随机森林模型从R导出到OpenCV [英] Export Random Forest model from R to OpenCV

查看:227
本文介绍了将随机森林模型从R导出到OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将用R创建的随机森林模型导出到OpenCV中?

我问是因为我在R(特别是随机森林)中制作原型,但由于OpenCV处理大型图像的速度很快,因此希望能够在OpenCV中运行我的模型.

解决方案

有效地,PMML是一条单向街.将模型从任何特定于框架的表示形式(例如OpenCV,R)导出到PMML表示形式相当容易,但是相反则不那么容易.这个想法是,一旦您的模型具有PMML表示形式,通常就应该使用专用的PMML评分引擎而不是其他一些技术来使用它.

您的情况是,您要在 OpenCV的 R的randomForest数据结构 .通过开发直接的双向转换器(即CvRTrees<-> randomForest),可能比使用PMML作为中间人(即CvRTrees<-> PMML<->)更好. randomForest).该决定很容易合理化,因为目前只有randomForest-> PMML转换组件可用.因此,开发两个缺失的转换组件(即前者直接"转换方案)可能要比三个缺失的转换组件(即后者中介"转换方案)花费更少的精力.

为简单起见,我建议使用共享的训练数据集来实现模型可移植性".也就是说,如果您需要OpenCV的RF模型,则可以使用CvRTrees::train方法调用直接对其进行训练,如果需要R的RF模型,则可以使用randomForest()方法调用直接对其进行训练.

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.

解决方案

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.

这篇关于将随机森林模型从R导出到OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆