Ask Your Question

How to prepare labeled data for action recognition video datasets using multiclass svm? [closed]

asked 2018-12-28 03:00:15 -0500

arti gravatar image

updated 2018-12-28 03:29:49 -0500

Hello all, i have read many examples of binary svm and got how to apply...but still suffering in multiclass svm . I'm not getting how to prepare multi-class action data for training along with labels. how to train svm for multiple classes and test. my data set have 10 classes like running, walking ,biking riding, waving, walking etc. and each class have 20 videos. so what should be label for each class. Please give me some reference regading multiclass. Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by berak
close date 2018-12-29 03:02:46.918433


before you can classify anything, you have to extract features from the video data. so what are you planning to do there ?

have e.g. a look here

berak gravatar imageberak ( 2018-12-28 03:01:39 -0500 )edit

I have 4 features of each data like, lbp,hog,glcm and sift

arti gravatar imagearti ( 2018-12-28 03:06:41 -0500 )edit

i have extracted features from video data and then created dictionary using BOW in .yml files. now i want to use multi class svm for classification

arti gravatar imagearti ( 2018-12-28 03:17:10 -0500 )edit

can you give us information about the dimensions of the features ?

berak gravatar imageberak ( 2018-12-28 03:17:26 -0500 )edit

i have 20 dectionaries of each 10 class videos, sow to use svm to classifie them

arti gravatar imagearti ( 2018-12-28 03:18:33 -0500 )edit

yes features are in n*1 dimension .

arti gravatar imagearti ( 2018-12-28 03:21:01 -0500 )edit
berak gravatar imageberak ( 2018-12-28 07:03:39 -0500 )edit

answered here

berak gravatar imageberak ( 2018-12-29 03:03:11 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-28 07:01:26 -0500

berak gravatar image

updated 2018-12-28 07:04:43 -0500

opencv's SVM can handle multi-class problems, it will make an one-vs-all problem for each class from it internally .

i can't give you python code (c++ person here), but you have to flatten each of your features to a single row, and stack them vertically into a single numpy array, so it looks like this:

FEATURES                       LABELS

feature1                          5
feature2                          3
feature3                          1

the features need to be a float32 numpy array, and the labels an int32 1xN numpy array, then you can train your SVM:

svm =
svm.train(features,, labels)

later you can predict on test features, reshaped and converted in the same way to a single row:

predicted = svm.predict(feature)
edit flag offensive delete link more


thanks a lot for the explanation.....means i have to train svm for each class of videos and at the time of test i have to test input with each train svms? ..what is the criteria for assigning to assign label for each class. In opencv document it is defied as fallows

 // Set up training data
    float labels[4] = {1.0, -1.0, -1.0, -1.0};
    Mat labelsMat(4, 1, CV_32FC1, labels);

    float trainingData[4][2] = { {501, 10}, {255, 10}, {501, 255}, {10, 501} };
    Mat trainingDataMat(4, 2, CV_32FC1, trainingData);

but i'm not getting in my case. i have 10 classes like running, walking , biking etc. and each class have 20 sample videos. then what should be label size and values in my case for each class.

arti gravatar imagearti ( 2018-12-28 10:26:02 -0500 )edit

means i have to train svm for each class

while you can do that, no, you probably should train 1 SVM with all the data you have.

.how to assign label for each class

simply like: 0:running, 1:standing, 2:whatever..

(this is also the number, the SVM will predict later.)

berak gravatar imageberak ( 2018-12-28 10:38:32 -0500 )edit

few more doubt please.... means in my case i have to take labels like

 float labels[10] = {0, 1, 2, 3,.......10};
 Mat labelsMat(10, 1, CV_32FC1, labels);

and training data for each class

float trainingData1[4] [n]= { feature1, feature2, feature3, feature4};
Mat trainingDataMat1(4, n, CV_32FC1, trainingData1);

then create svm for each class such as

Ptr<SVM> svm1 = SVM::create();

svm1->train(trainingDataMat1, ROW_SAMPLE, labelsMat);

here each svm should be trained with same labelsMat or i have to define different labels for each class?

and at the time testing i have to apply predict function with each svm1...svmN like

float response1 = svm1->predict(sampleMat); . . . . float responseK = svmN->predict(sampleMat);

then accuracy is calculated??

arti gravatar imagearti ( 2018-12-28 20:20:03 -0500 )edit

Question Tools


Asked: 2018-12-28 03:00:15 -0500

Seen: 21 times

Last updated: Dec 28 '18