Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

SVM returning a single value during prediction

$
0
0
I have trained an SVM for image classification as shown below. The training seem to be going on well but when I predict a row (any row of the training vector), SVM return just one value (60). What could I have done wrong? Is my training and testing approach right as shown in the function below? void trainSVM(Mat hists, vector labels){ Ptr trainData = TrainData::create(hists, ml::ROW_SAMPLE, labels); Ptr svm = SVM::create(); svm->setKernel(SVM::LINEAR); cout << "Training SVM..." << endl; svm->train(trainData); bool trained = svm->isTrained(); if (trained) { cout << "SVM Trained. Saving..." << endl; svm->save(".\\Trained Models\\LBPSVM.yml"); cout << "SVM Model Saved." << endl; } Mat_ output; svm->predict(hists, output); float pred = svm->predict(hists.row(34)); cout << "SVM Output = " << output.at(0) << endl; writeMatToFile(output, "SVNPredict.csv"); } The value stored in variable **pred** is the same regardless of the row I try to predict. It is the same value I get in my single column matrix **output**. All rows are populated with same value. Kindly help.

Viewing all articles
Browse latest Browse all 19555

Trending Articles



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