Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to code one vs rest multi class SVM for action recognition project

I'm new to SVM. I want to use Multiclass svm for classification in my action recognition project. My data set have 15 class like running jogging walking biking etc. I understand binary SVM and seen lot of examples. I'm getting confusion in one vs one multiclass svm and one vs rest multiclass svm. My question is should i have to create and train a svm for each class like svm1 for running, svm2 for jogging.....etc what should be class lebels for each created svm either (0,1,2,.......14) or (0,1). how to determine the model for multiclass classification.how the result will be predicted. please clear my doubts please. Thanks

I was trying some thing like this

 Mat trainData, trainLabels;

        for (int i = 0; i < 15; 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.reshape(1, 1));
    if (response == 1)
        cout << "boxing";
    else
        cout << "negative result";

    waitKey(27);
    return 0;

but getting error. what is wrong here?? how to code one vs rest multiclass svm properly. What is the label for each svm? Thanks