What am I doing wrong in training SVM based on BOW? [closed]

asked 2015-01-07 04:32:21 -0600

thdrksdfthmn gravatar image

updated 2015-01-07 04:45:14 -0600

I am using openCV 2.4.10. I have an application that trains a NormalBayesClassifier based on the BOW descriptors. It works nice, but I want to test the SVM too. When I have changed the classifier to SVM, in the training process (bothe train and train_auto) I am getting errors like

OpenCV Error: Incorrect size of input array (Input sample must be 1-dimensional vector) in cvPreparePredictData, file /home/me/opencv/modules/ml/src/inner_functions.cpp, line 1107
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/me/opencv/modules/ml/src/inner_functions.cpp:1107: error: (-201) Input sample must be 1-dimensional vector in function cvPreparePredictData

The trainingData Mat is 90x150 and the labels is 90x1. It is true that there are 9 classes (so 10 images per class; just for testing for now). Could it be because the SVM cannot have more than 2 classes? Norally it could.

Please help...


I have created the training Mats like this:

// read image; get bow descriptors and add them in the matrix:
trainingData.push_back(bowDescriptors);
labels.push_back(imageLabel);

Have I done it wrong? Why for the NormalBayesClassifier it works?

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by thdrksdfthmn
close date 2015-01-07 05:54:45.994795

Comments

SVM can handle more than 2 classes, that's not the problem

please show your prediction code, the problem seems to be there (not in the training)

berak gravatar imageberak ( 2015-01-07 04:48:58 -0600 )edit

??? ... You are right... I have not seen it, sorry, Let me debug more and then I'll edit the question.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-07 04:54:03 -0600 )edit

rrr... I have used a Mat instead of a vector of Mat for prediction... It was because of copy-pasting the code (from the other version)... Normal Bayes predict accespt a Mat that contains more than one sample, while SVM seems it do not...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-07 04:59:35 -0600 )edit

Is there a way of converting the mat to vector of rows? :)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-07 05:01:14 -0600 )edit

Mat m2 = M1.reshape(1,1); //makes a single flat array of it. this is probably expected for the prediction

but again, it complains about the prediction not the training. please show that code.

berak gravatar imageberak ( 2015-01-07 05:06:16 -0600 )edit

Ok, this is going to change very much, I am cosing the question and open another one.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-07 05:54:09 -0600 )edit

if so, good idea !

berak gravatar imageberak ( 2015-01-07 05:54:56 -0600 )edit