0

I am kind of new to svm classification. I am trying to use opencv svm classifier to do some face recognition. The input feature parameters are normalized Local binary pattern. So all values are from 0-1. I first tried linear kernel to train the classifier and then use the training data set to test set. I got 100% accuracy (I know it means nothing). However, when I changed kernel to RBF (all other parameters are default) and re-test the training set, all cases are classified to one class which means they are not separable. I tried different gamma values from 0.000001 to 10. Does anyone have idea about this issue? Thanks.

btw, I checked the supported vectors after training, all the values are identical.

here is the code

CvSVMParams param;
param.svm_type = CvSVM::C_SVC;
param.kernel_type = CvSVM::RBF; //CvSVM::RBF, CvSVM::LINEAR ...
param.degree = 2; // for poly
param.gamma = 0.000000001; // for poly/rbf/sigmoid
param.coef0 = 1; // for poly/sigmoid

param.C = 0.5; // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR
param.term_crit.type = CV_TERMCRIT_EPS;//CV_TERMCRIT_ITER +CV_TERMCRIT_EPS;
param.term_crit.max_iter = 1000000;
param.term_crit.epsilon = 1e-9;
SVM.train(trainingDataMat, labelMat, Mat(), Mat(), param);

for(int i=0; i<trainingDataMat.rows; i++){
    Mat sampleMat = trainingDataMat(Range(i,i+1), Range::all());
    double response = SVM.predict(sampleMat);
    cout<<"test"<<i<<"=  "<<response<<endl;
}
fnhdx
  • 321
  • 2
  • 5
  • 14
  • just a comment, assessing your model accuracy on the training set does not give a good idea of how it will perform on new data. Training error is useful to know, but try keeping some examples out of your training set and use them to test your model on once it has been trained. – user1269942 Oct 12 '14 at 23:51
  • Yes, I know. My question is why all training data are classified to one class. It looks like they are not separable. – fnhdx Oct 13 '14 at 02:49
  • 1
    Please provide some code. It might be some little bug you overlooked. – a-Jays Oct 13 '14 at 11:31
  • 1
    I just added my code. trainingMat size is 1000x863. – fnhdx Oct 13 '14 at 13:03

1 Answers1

2

What you can do is to let OpenCV optimize the SVM parameter when RBF kernel is used using train_auto. In this way you don't worry about those parameters, they are set automatically.

This OpenCV docmentation provides great explanation on how you use it. Alternatively, you can refer to this great example on how to optimize SVM parameters

The drawback of using train_auto is that training may take a long time. It even may take days depending on your training set so be prepared.

I actually don't know what you're expecting, but I'll give you a tip: RBF may be the most sophisticated kernel available in OpenCV but it probably wont give you the best results. Try other kernels too !

Community
  • 1
  • 1