Ask Your Question
0

Load SVM from disk on iOS

asked 2017-02-27 18:35:22 -0500

ginister gravatar image

Hi everyone,

I am reading an SVM from my iOS app's document directory and it seemed to be working until I tried predicting something on it. The code is as follows:

    Ptr<ml::svm> SVMAVB;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,     YES);
    NSString *docs = [paths objectAtIndex:0];
    docs = [docs stringByAppendingPathComponent:@"Classifiers/"];

    NSString *vocabPath = [docs stringByAppendingPathComponent:@"SVMAVB.xml"];
    FileStorage fs([vocabPath UTF8String], FileStorage::READ);
    SVMAVB->load<ml::svm>(std::string([vocabPath UTF8String]));
    return SVMAVB->predict(features);

However after inspecting the code before predict runs, it turns out the object is null. This is surprising, I expected a warning or error! However the program proceeds to crash when executing predict, yielding a bad access to address 0x0. Could anyone provide any help on why this might not be loading?

I'm confident the SVM is not accurate (not sure why yet, I'll come to that later), but it does exist so I expected it to at least work! Thanks for the help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-27 21:17:10 -0500

berak gravatar image

updated 2017-02-28 11:31:38 -0500

your problem is unrelated to your os or funny language there.

SVM::load returns a new SVM (it's a static, "factory" method), you'll have to use it like:

SVMAVB = Algorithm::load<ml::SVM>(some_file_name);

after that probably you want to check, if it worked, like:

if ((! SVMAVB.empty()) && (SVMAVB->isTrained()))
       // go on ..
else
      // wrong path ? garbled file ? check !
edit flag offensive delete link more

Comments

@berak Thanks for the response. I've modified the code so that it uses this line. This appears to cause an error of the same nature still, however at a certain address rather than 0x0. The error is exc_bad_access address: 0x10bb5c000. And yes, Objective-C is a funny language that I'm not using out of choice ;)

ginister gravatar imageginister ( 2017-02-28 10:55:55 -0500 )edit

ok, loading still can go wrong. add additionaly checks. see update above.

berak gravatar imageberak ( 2017-02-28 11:32:58 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-02-27 18:35:22 -0500

Seen: 159 times

Last updated: Feb 28 '17