Problem of predicting model via loading SVM

asked 2016-05-29 06:00:59 -0500

kenli gravatar image

updated 2016-05-29 23:50:55 -0500

OpenCV3.0.0+VS2013

The results after training is different with original predict after reloading model.

//////////////////////////////////////////////////////////////

Ptr<SVM> svm = SVM::create();

    svm->setType(SVM::C_SVC);
    svm->setKernel(SVM::RBF);
    svm->setC(1);       
    svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 3000, 1e-6));
    svm->setGamma(0.25);

Ptr<TrainData> tData = TrainData::loadFromCSV("20160519_r_COS.csv",1,-1,-1);
svm->train(tData, ROW_SAMPLE);

svm->save("20160519__r1.xml");              //model

Mat comp_result(predict_comp.rows, 1, CV_32FC(1));
svm->predict(predict_comp, comp_result);

Ptr<SVM> tData_comp = SVM::create();
tData_comp = StatModel::load<SVM>("20160519__r1.xml");
Mat comp_result2(predict_comp.rows, 1, CV_32FC(1));
tData_comp->predict(predict_comp, comp_result2);

the result with predict after traing is different with load model

edit retag flag offensive close merge delete

Comments

Can this quick and dirty fix solve your problem :D ?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-05-30 03:54:54 -0500 )edit
1

Thanks it's a good answer, I will try it.

kenli gravatar imagekenli ( 2016-05-30 04:13:48 -0500 )edit