Ask Your Question

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

asked 2019-01-12 18:46:27 -0500

arti gravatar image

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 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->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";
        cout << "negative result";

    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

edit retag flag offensive close merge delete


but getting error. what is wrong here??

how would we know, if you don't tell us ?

berak gravatar imageberak ( 2019-01-13 03:10:59 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-01-13 03:15:08 -0500

berak gravatar image

for a multi-class SVM, you will label your features like 1,2,3,4,... like in the code above.

for binary SVM's you would label them like 1: expected class, 0: all others. you would also need to train one SVM per class (all with the same data, just with different labels)

edit flag offensive delete link more


Thank you sir for your time and help. In my case each class have 4 features like LBP(100x80), HOG(100x1), SIFT(200x128),GLCM1(100x250), Then i have to train class1 with SVM1 with label 1, 2, 3, 4( for each feature one label) then train class2 with SVM2 with label 5,6,7,8............i'm right or wrong???

arti gravatar imagearti ( 2019-01-13 05:07:59 -0500 )edit

you are totally wrong !

labels are for classes, not for feature types. (and no you cannot even train an SVM on different feature types at the same time.

and sorry, nothing in your comment makes any sense to me ;(

berak gravatar imageberak ( 2019-01-13 05:16:00 -0500 )edit

can it be, you're confusing features and dictionaries here ? if above are your Bow vocabularies, then you're doing something wrong, those should not go into the classification.

instead, you have to take e.g. 500 hog features from your video, match each of them to the vocabulary (cluster centers), and increase a histogram bin for the cluster id of the closest match.

the normalized histogram is your BoW feature for classification !

berak gravatar imageberak ( 2019-01-13 09:43:41 -0500 )edit

Thanks a lot sir for clearing my concept. yes these are Bow vocabularies. ok means i have to first find normalized histogram for classification. and each feature cant be taken for training at the same time?? i have to train one SVM per class with different labels??

arti gravatar imagearti ( 2019-01-13 10:26:55 -0500 )edit

ok means i have to first find normalized histogram for classification


and each feature cant be taken for training at the same time??

wat ?

i have to train one SVM per class with different labels??

again, you can train 1 multiclass SVM or N binary ones.

can you try to look at the ml samples, e.g. here ?

imho, you should start easy, e.g. roll it back to a single "running vs all others" classification, from a single feature type (e.g. HOG). (all samples from "running" get a 1 label, all others a 0)

once you have that running, start making new plans.

berak gravatar imageberak ( 2019-01-13 10:37:30 -0500 )edit

Thanks a lot sir for your help...first read these things again and then i'll try.

arti gravatar imagearti ( 2019-01-13 10:47:10 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-12 18:46:27 -0500

Seen: 24 times

Last updated: Jan 13