Ask Your Question
0

svm load (still?) missing in java

asked 2016-04-10 07:49:30 -0600

just_trying_stuff gravatar image

updated 2016-04-11 02:44:21 -0600

So after training and saving my model. I tried to load it again only to find that there's no load function in the java wrappers. After some googling I found that this is a bug. It looks like the python wrappers are fixed but no word on the java ones.

So is there a work around for this? Because training the model each run is a bit too much. I'm using OpenCV 3.1.0

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-11 03:44:14 -0600

berak gravatar image

updated 2016-04-11 05:02:48 -0600

the python fix also applies to java.

(maybe you need to update your opencv libs)

if you compile the latest master branch, you should have:

//
// C++: static Ptr_SVM load(String filepath)
//

//javadoc: SVM::load(filepath)
public static SVM load(String filepath)
{

    SVM retVal = new SVM(load_0(filepath));

    return retVal;
}

in build/modules/java/ml+SVM.java, and you would use it like:

SVM svm = SVM.load("my.yml");
edit flag offensive delete link more

Comments

That's what I also though but I downloaded the latest release from opencv.org (3.1.0) and used the prebuilt jar file. I just redownloaded for a sanity check but still no load function. The load function is a function from the algorithmclass. The Algorithm class in java doesn't contain a load function.

just_trying_stuff gravatar imagejust_trying_stuff ( 2016-04-11 04:47:57 -0600 )edit

unfortunately, the prebuilt libs always lag behind master.

Algorithm::load() is a template function in c++, that's why you need this overload to use it from python or java

any chance, that you can rebuild the libs locally ? (needs cmake, ant, jdk and a c++ compiler)

berak gravatar imageberak ( 2016-04-11 04:59:40 -0600 )edit

Hmm yeah that's something I'm going to do another day then. Never done that before but I found this tutorial. So it shouldn't be to hard I guess.

just_trying_stuff gravatar imagejust_trying_stuff ( 2016-04-11 05:05:18 -0600 )edit
1

yes, the tutorial is fairly accurate. good luck !

berak gravatar imageberak ( 2016-04-11 05:28:03 -0600 )edit

omg I finally got it compiled. And now I get errors on smv.save. Exception in thread "main" java.lang.Exception: unknown exception Yeah that's a clear error message /s

just_trying_stuff gravatar imagejust_trying_stuff ( 2016-04-11 14:47:22 -0600 )edit

Have you solved your error with svm.save method? Because I am currently getting also this "unknown exception" and don't know what to do with that.

Infinito gravatar imageInfinito ( 2017-02-27 07:42:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-10 07:49:30 -0600

Seen: 847 times

Last updated: Apr 11 '16