Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load trained RTrees? #141

Open
lymhust opened this issue Jul 3, 2016 · 2 comments
Open

How to load trained RTrees? #141

lymhust opened this issue Jul 3, 2016 · 2 comments
Labels

Comments

@lymhust
Copy link

lymhust commented Jul 3, 2016

Hi,

I have trained a RTrees model and saved it using following codes. However, I cannot reload the trained model. How to solve this problem? Thanks!

local rt = cv.ml.RTrees()
........
rt:save('./RT_MNIST_MODEL')

How to reload RT_MNIST_MODEL?

@lymhust
Copy link
Author

lymhust commented Jul 5, 2016

I have tried to wrap the OpenCV function: cv::Ptr<ml::SVM> p = ml::SVM::load<ml::SVM>(filename) using the following codes and solved the problem. Unfortunately, OpenCV has a bug in this function.....

In ml.cpp:

// SVM
extern "C"
struct SVMPtr SVM_load(const char *filename) {
  return rescueObjectFromPtr(ml::SVM::load<ml::SVM>(filename));
}

In ml/init.lua:

function SVM:load(filename)
   self.ptr = ffi.gc(C.SVM_load(filename), Classes.Algorithm_dtor)
end

Usage:

local svm = cv.ml.SVM()
svm:load('./SVM_MODEL.xml')

@shrubb shrubb added the bug label Aug 17, 2016
@shrubb
Copy link
Contributor

shrubb commented Aug 17, 2016

@lymhust
Thank you very much for the effort, and sorry for late reply.
This is a problem indeed, it turns out that we should wrap these :load() functions for each cv::Algorithm subclass.
I'll now do this for cv::ml based on your patch, and later for other packages. Then it will be possible to call svm:load{'svm_model.xml'}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants