SVM model fails to load in Android NDK

asked 2015-01-27 23:51:40 -0600

Bornfree gravatar image

updated 2018-09-09 03:25:37 -0600

I have trained a SVM model for detecting handwritten characters. On my desktop, I am able to save and load the model and its working perfectly. This is what I've used.

svm.save("./activ_hog_svm");
svm.load("./activ_hog_svm");

It works with both relative and absolute paths. However when I try to load the saved model in my Android app, the load command doesn't seem to work.

JNIEXPORT void JNICALL Java_co_activ_exp_MainActivity_loadSvm(JNIEnv* env, jobject, jstring svm_location)
{
  const char *c_dir = env->GetStringUTFChars(svm_location, NULL);
  LOGD("SVM location %s", c_dir);
  // This prints /storage/emulated/0/Android/data/co.activ.exp/files/mounted/activ_hog_svm
  // I have ensured that the file exists and has right permissions 
  svm.load(c_dir);
  env->ReleaseStringUTFChars(svm_location, c_dir);
}

The model sits in assets folder. I also tried putting it directly at /sdcard but that didn't work either. The error that shows up in logcat when I run a svm.predict later is

OpenCV Error: Bad argument (The SVM should be trained first) in CvSVM::predict, file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/ml/src/svm.cpp, line 21

Any help on how to fix this? Thanks.

edit retag flag offensive close merge delete

Comments

Just realized I made a horribly silly mistake. A typo in filename. Please consider question closed.

Bornfree gravatar imageBornfree ( 2015-01-28 01:10:58 -0600 )edit

Can you please share source code? as I am trying something very similar.

shayankh gravatar imageshayankh ( 2015-07-06 17:22:41 -0600 )edit