getting error in multiclass SVM classification??
Hello all, I'm getting error in my code. here i'm doing multiclass classification using svm with 20 classes. here the training data of each class is feature vector .yml file named as Dictionay1 , Dictionay2, ......Dictionay20 such as
vocabulary: !!opencv-matrix
rows: 100
cols: 1
dt: f
data: [ 4.48574181e+01, 3.61391605e-04, 1.06644783e+02,
1.75997910e+02, 8.53040619e+01, 2.40742096e+02, 1.35315109e+02,
9.74207458e+01, 7.31249542e+01, 5.95427322e+01, 3.08762417e+01............
%YAML:1.0
---
vocabulary: !!opencv-matrix
rows: 100
cols: 1
dt: f
data: [ 6.63631945e-04, 1.00589867e+02, 1.60471497e+02,
4.06750679e+01, 1.32695053e+02, 2.54314590e+02, 8.82780228e+01... etc
My code is
char filename[80];
int main(int argc, char* argv[])
{
Mat trainData, trainLabels;
for (int i = 0; i < 22; i++ )
{
sprintf_s(filename, "VocabularyHOG/Dictionary%d.yml", i);
Mat feature;
FileStorage fs(filename, FileStorage::READ);
fs["vocabulary"] >> feature;
feature.convertTo(feature, CV_32F); // make sure we got float data
trainData.push_back(feature.reshape(1, 1)); // as a flat column
trainLabels.push_back(i); // the classlabel
}
// Train the SVM
Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
svm->train(trainData, ROW_SAMPLE, trainLabels);
Mat testData;
FileStorage fs("DictionaryrunningHOG.yml", FileStorage::READ);
fs["vocabulary"] >> testData;
int response = svm->predict(testData);
if (response == 1)
cout << "boxing";
else
cout << "negative result";
waitKey(27);
return 0;
}
I'm getting error
please help where i'm doing wrong. Thanks
you'll have to reshape() your testData to a single row, too.
apart from that, clearly a case, where you have to learn how to use the debugger ...
the screenshot is useless, but a backtrace would be useful.
then, you need more and better data. you cannot do successful machinelearning with a single example per class only.
Thank you sir or your response. i have taken 25 example videeos per class, then i created vocabulary from them using BOW. so Dictionary1 is vocabulary using these 25 videos......i'm doing any thong wrong here? i have to convert my data into single row??
oh, ok. your code above is just reading one yml file, containing a single feature per class only, right ??
yes sir this code is for single feature per class.
that sounds weird. can you take a look here again, and then try to describe in more detail, what you did exactly with your videos ?
converted testData in single row but again the same error??
again, you have to debug it ;(
Thank you sir for your response....after debug It is crash in line trainData.push_back(feature.reshape (1,1));...I'm not getting what I'm doing wrong.