Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 errorimage description

please help where i'm doing wrong. Thanks

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 errorimage description

please help where i'm doing wrong. Thanks

click to hide/show revision 3
None

updated 2019-01-10 00:43:10 -0600

berak gravatar image

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 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

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

etc

My code is is

char filename[80];

filename[80]; int main(int argc, char* argv[]) { Mat trainData, trainLabels;

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 errorimage description

please help where i'm doing wrong. Thanks