Ask Your Question
0

SVM training under OpenCV 3.1 weird classification labels

asked 2016-01-12 10:52:13 -0600

So I got training data with double features and accompanied integer labels. Since I want binary classification I give one class 1 labels and other class -1 labels. Training data is a matrix with amount of samples as rows and with features as columns.

Training is set up as

// Set up SVM's parameters
Ptr<SVM> svm1 = SVM::create();
svm1->setType(SVM::C_SVC);
svm1->setKernel(SVM::LINEAR);
svm1->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
svm1->train(trainingDataSVM1, ROW_SAMPLE, labelsSVM1);

cerr << "SVM 1 trained and ready to use!" <<  endl;

While testing is done with

// Classify the labels of the testing data
Mat labelsTest( testData.rows, 1, CV_32SC1);
svm1->predict(testData, labelsTest);

cerr << "Labels: ";
for(int i=0; i < labelsTest.rows; i++){
    cerr << labelsTest.at<int>(i, 0) << " / ";
}
cerr << endl;

Now this generates the following output, which is quite unusual

SVM 1 trained and ready to use!
Labels: -1082130432 / 1065353216 / 1065353216 / 1065353216 / 1065353216 / 1065353216 / 1065353216 / 1065353216 / 1065353216 /

What concerns me is that

  1. Training goes extremely fast, its like instant, but that can be due to the low amount of training samples, for 1 class it is 42 while for the -1 class it is 40. But still it seems that SVM should take time to train?
  2. I have a binary SVM so how does he finds those extreme large values.
edit retag flag offensive close merge delete

Comments

1

http://answers.opencv.org/question/77... About your other concern, I haven't tested 3.1, I've sucessfully trained SVMs in 3.0 (with manual train() function, there were many bugs in the trainAuto() one - don't know if solved right now)

LorenaGdL gravatar imageLorenaGdL ( 2016-01-12 11:06:29 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-12 11:11:14 -0600

Found my problem ...

Should have been

cerr << "Labels: ";
for(int i=0; i < labelsTest.rows; i++){
    cerr << labelsTest.at<float>(i, 0) << " / ";
}

instead of jumping through the data with int, which is 64 bits, in contradiction to the 32 bit jump I needed...

edit flag offensive delete link more

Comments

Then it works, however results are quite bad, need to find better features to descriminate :D

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-12 11:11:48 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-01-12 10:52:13 -0600

Seen: 1,294 times

Last updated: Jan 12 '16