Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem of predicting model via loading SVM

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

Problem of predicting model via loading SVM

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