Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Loading a .yml file in a SVM

$
0
0
Hi everyone, I trained an SVM and saved the result in a .yml file thanks to svm->save(filename). However when on the second run I use Ptr svm = SVM::load(filename); the whole program doesn't give me the same result. What I do on the second run is commenting these 2 parts: Mat trainingData; int k = 0; Mat labels; vector fna; glob("C:/Users/albma/Desktop/train_originale/*.png", fna, true); for (size_t i = 0; i < fna.size(); i++) { //trees: label = 1 printf("Training Image = %s\n", fna[i]); img = imread(fna[i]); vector keypoint; Mat bowDescriptor; detector1->detect(img, keypoint); //detect keypoints bowDE.compute(img, keypoint, bowDescriptor); //compute descriptors trainingData.push_back(bowDescriptor); if(!bowDescriptor.empty()) labels.push_back((int)1); } trainingData.convertTo(trainingData, CV_32FC1); And this: int dictSize = 1500; Ptr svm = SVM::create(); svm->setType(SVM::ONE_CLASS); svm->setNu(0.5); svm->setKernel(SVM::LINEAR); svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6)); printf("Training SVM\n"); Ptr td = TrainData::create(trainingData, ROW_SAMPLE, labels); //start training SVM svm->train(td); svm->save("mySVM.yml"); Substituting it all with the load() mentioned above. What's wrong with the code?

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>