将随机森林模型从R导出到OpenCV

编程入门 行业动态 更新时间:2024-10-26 06:29:37
本文介绍了将随机森林模型从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

本文发布于:2023-10-23 01:49:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   森林   导出到   OpenCV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!