What am I doing wrong in training SVM based on BOW? [closed]
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?
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)
??? ... You are right... I have not seen it, sorry, Let me debug more and then I'll edit the question.
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...
Is there a way of converting the mat to vector of rows? :)
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.
Ok, this is going to change very much, I am cosing the question and open another one.
if so, good idea !