Question

I am trying to train a SVM with SIFT descriptors taken from images. And then i want to save the SVM in .xml format so that i can load it again.

My structure: I have 10 classes with 100 samples from each class.

Question: If i use 10-50 samples for each class then the SVM gets saved and i can see a classifer.xml file in my folder. But if i want to use more samples e.g. ~100 samples per class, then the SVM is not getting saved.

I thought that it might take some time for it to save but i have already waited for so long (and i have done it several times).

My code for SVM training is following:

void svm::svmTrain()
{
    cv::Mat trainme;        // it should contain the feature vectors
    cv::Mat labels; // it will contain the class labels

    createTrainingDateUsingBOW( trainme, labels);       

    //svm parameters
    CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS, 1000, FLT_EPSILON);
    CvSVMParams svm_params = CvSVMParams (CvSVM::C_SVC, CvSVM::POLY, 10.0   ,  8.0   , 1.0   , 10.0  , 0.5 , 0.1 , NULL         , criteria); //CvSVMParams --it is a struct
                                       //( svm_type,    kernel_type, degree , gamma , coef0 , Cvalue, nu   , p  , class_weights, term_crit)

    cout<<"\n saving SVM \n";

    cv::SVM svm;
    svm.train(trainme, labels, cv::Mat(), cv::Mat(), svm_params);
    svm.save("classifier.xml");

    cout<<"\n SVM classifier is saved.";

}

PS: So if my samples are more 40-60 per class then, i reach upto saving SVM from the above code but never reach to SVM classifier is saved.

No correct solution

OTHER TIPS

try this replacement, you ll find that, its taking too much time for training, after training, it hardly takes a minute to save the file.

cout<<"\n training SVM \n";

cv::SVM svm;
svm.train(trainme, labels, cv::Mat(), cv::Mat(), svm_params);
cout<<"\n saving SVM \n";
svm.save("classifier.xml");

cout<<"\n SVM classifier is saved.";

I never personally experienced with SVM but, with as many as 1000 samples, it won't train in less than an hour. In my case when i tried things for fishers with similar number of samples, it took more than 2-3 hours.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top