Normal bayes classifier taking long to train Opencv C++
I am training normal bayes classifier using opencv 3.1.0 C++ to classify face images. I am passing a floating point matrix as classification data and a matrix of integers as labels (responses). Opencv does not throw any exception but the classifier takes a very long time without finishing classification. Below is my code. Kind regards
void trainBayes(Mat hists, vector<int> labels)
{
Mat responses(labels);
responses.convertTo(responses, CV_32SC1);
Ptr<NormalBayesClassifier> bayes = NormalBayesClassifier::create();
cout << "Training Bayes..." << endl;
bayes->train(hists, ml::ROW_SAMPLE, responses);
bool trained = bayes->isTrained();
if (trained)
{
cout << "Normal Bayes Classifier is Trained" << endl;
bayes->save(".\\Trained Models\\LBPBayes.xml");
}
}
to my experience, a NormalBayesClassifier plays badly with long feature vectors (what are you giving it ? pixels ? that would be e.g. 10000 features for a 100x100 img) as well with accuracy and training time.
did you try alternatives, like SVM, ANN_MLP, KNearest ?
May be that could be the reason. My feature vector is 600 rows by 2304 cols Matrix. This means my features are 1,382,400. I have successfully trained ANN, SVM and KNN with the same feature vector.
I have reduced the feature vector to 2 x 16 (32) but still Normal Bayes Classifier is taking forever to train. Could there be any other issue apart from feature size?
Normal Bayes, as @berak said is not for large feature vectors. It is mainly used for simple post processing steps after exhaustive machine learning techniques to refine results. How much different data points are you supplying to the naive bayes? I normally use a set of like 100 samples at most, just because to much data will prolong the decision and building of the model for ages :)
Thank you so much for these comments! It saved my time to debug what's wrong with my training!