Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 training data 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...

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

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 training data 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?