IOS OpenCV 3.0 SVM save / load issue
I am unable to save the prepared SVM in the xml file. That's my fault:
OpenCV error: parsing error (no invalid SVM type) in read_params file /Users/build/test/opencv/modules/ml/src/svm.cpp line 2050 libc ++ abi.dylib: exit with uncaught cv type exception :: Exception: /Users/build/test/opencv/modules/ml/src/svm.cpp: 2050: error: (-212) Missing invalid SVM type in read_params function
What should I do...
- (void)saveSVM {
string oFileName = "NormParameters.xml";
svm->save(oFileName);
}
- (BOOL)loadSVM {
string oFileName = "NormParameters.xml";
svm = StatModel::load<SVM>(oFileName);
NSLog(@"COUNT: %d", svm->getVarCount());
if (svm->getVarCount() > 0) {
return YES;
}
return NO;
}
The SVM will persist every time I get a new sample for it. Loading the trainable SVM occurs in initWithParams ().
- (id)initWithParams {
self = [super init];
if (self) {
// create and set SVM parameters
SVM::Params param = SVM::Params();
param.svmType = SVM::EPS_SVR; // Support Vector Regression. The distance between feature vectors from the training set and the fitting hyper-plane must be less than p. For outliers the penalty multiplier C is used.
param.kernelType = SVM::RBF; //Polynomial kernel
param.degree = 3.0; // for poly
param.gamma = 1.0; // for poly/rbf/sigmoid
param.coef0 = 0.0; // for poly/sigmoid
param.C = 256.0; // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR
param.nu = 0.1; // for CV_SVM_NU_SVC, CV_SVM_ONE_CLASS, and CV_SVM_NU_SVR
param.p = 0.00390625; // for CV_SVM_EPS_SVR
param.classWeights = NULL; // for CV_SVM_C_SVC
param.termCrit.type = CV_TERMCRIT_EPS | CV_TERMCRIT_ITER; // CV_TERMCRIT_EPS + CV_TERMCRIT_ITER
param.termCrit.maxCount = 1000;
param.termCrit.epsilon = 0.00390625; //1e-6;
// create SVM
svm = SVM::create(param);
// load svm
[self loadSVM];
// create trained data
trainedDataMat = [[MLDataMatrix alloc] init];
[trainedDataMat removeDataRow];
}
return self;
}
I'm new to OpenCV, maybe I gave the wrong parameters (I played with all of them) or StatModel :: load doesn't work unter iOS 8.3? If you know another way to save SVMs to a file, please let me know too ... Thanks for every answer!
source to share
No one has answered this question yet
Check out similar questions: