How to SVM predict more than one sample?

asked 2015-01-07 06:25:53 -0600

thdrksdfthmn gravatar image

I want to classify more than one single image with a SVM trained before. I know that there is the

void predict( cv::InputArray samples, cv::OutputArray results )

but I get the following error

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

if I have :

cv::Mat testPredictions;
Mat samples = testDLN.getBOWDescritprs(); // samples is a 90x150 Mat
m_classifier->predict(samples, &testPredictions);

How shall I classify the set of images? Shall I use a for loop instead?

edit retag flag offensive close merge delete

Comments

1

Exactly, just iterate the rows with a for loop and then apply the predict every single time. There is no batch predict function for the moment.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-07 06:34:06 -0600 )edit
1

I have seen the metioned overload of predict and I thought that it works... Thanks

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-01-07 06:37:45 -0600 )edit

No batch predict function? Then what does the predict function documentation mean when it says "Predicts response(s) for the provided sample(s)" implying that we can get multiple predictions for multiple samples/instances? http://docs.opencv.org/3.0-beta/modul...

tpacker gravatar imagetpacker ( 2015-08-10 17:44:03 -0600 )edit