Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVM type in openCV

Tags:

opencv

svm

I am using opencv to develop a very simple classifer for image. I want to use svm type poly but it gives error while other like sigmoid, RBF works fine. I defined the parameters as follows:

SVMParams params;
params.svm_type = SVM::C_SVC;
params.kernel_type = SVM::POLY;
params.gamma = 20;
params.degree = 0;
params.coef0 = 0;

params.C = 7;
params.nu = 0.0;
params.p = 0.0;

params.class_weights = NULL;
params.term_crit.type = CV_TERMCRIT_ITER +CV_TERMCRIT_EPS;
params.term_crit.max_iter = 1000;
params.term_crit.epsilon = 1e-6;

The error reads openCV Error: One of arguments' values is out of range (The kernel parameter must be positive) in CvSVM::set_params. I am unsure what is the error about.?

like image 753
rish Avatar asked May 25 '26 03:05

rish


1 Answers

For a polynomial kernel, degree must be larger than 1 (0 is invalid, 1 is linear). For most packages, the default value for degree is 3.

RBF and sigmoid kernels work fine with your settings because they don't use degree. For reference, the kernel functions in question are:

  • polynomial: k(u,v)=(gamma*u'*v + coef0)^degree,
  • RBF: k(u,v)=exp(-gamma*|u-v|^2),
  • sigmoid: k(u,v)=tanh(gamma*u'*v + coef0).
like image 127
Marc Claesen Avatar answered May 26 '26 22:05

Marc Claesen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!