Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Predicting MLP with single sample

$
0
0
I have trained MLP as shown in the code below to classify images into 4 classes. My class labels are `1,2,3,4`.This trains the model successfully but it thorws an Exception **vector out of range** during prediction void train::trainANN(Mat hists, vector labels) { int cols = hists.cols;//size of input layer must be equal to this number of cols int rows = hists.rows;//used to determine rows in Mat of responses Mat_ responses = Mat(labels).reshape(0, rows); Ptr trainData = TrainData::create(hists, ROW_SAMPLE, responses); Ptr ann = ml::ANN_MLP::create(); vector layers = { cols, 500, 1 }; ann->setLayerSizes(layers); ann->setActivationFunction(ml::ANN_MLP::ActivationFunctions::SIGMOID_SYM, 1.0, 1.0); ann->setTrainMethod(ANN_MLP::TrainingMethods::BACKPROP); ann->setBackpropMomentumScale(0.1); ann->setBackpropWeightScale(0.1); ann->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 10000, 0.00001)); ann->train(trainData); } This is how I predict the model float train::predictANN(Mat hist)//hist is a row matrix(one sample) { Mat results(1, 4, CV_32FC1); float pred = ann->predict(hist, results);//This is the line that throws vector out of range exception return pred; } I have tried to debug this code but have not fixed the error. Kindly help with why the prediction throws vector out of range exception. Thank you. **NB:Am using different number of images per class during training. class 1 = 300 images, class 2 = 340 images etc**

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>