Tuesday 15 May 2012

c++ - OpenCV Linear SVM not training -



c++ - OpenCV Linear SVM not training -

i've been stuck on time now. opencv's svm implementation doesn't seem work linear kernel. i'm sure there's no bug in code: when alter kernel_type rbf or poly, keeping else is, works.

the reason doesn't work is, save generated model , check out. shows back upwards vector count 1. not case in rbf or polynomial kernels.

there's nil special code in itself, i've used opencv's svm implementation before, never linear kernel. tried setting degree 1 in poly kernel , results in same model. makes me believe buggy here.

the code structure, if required:

mat trainingdata; //acquire files. done , correct. mat testingdata; //acquire files. done , right again. mat labels; //corresponding labels. checked , correct. svm my_svm; svmparams my_params; my_params.svm_type = svm::c_svc; my_params.kernel_type = svm::linear; //or poly, my_params.degree = 1. my_param.c = 0.02; //doesn't matter if set 20000, makes no difference. my_svm.train( trainingdata, labels, mat(), mat(), my_params ); //train_auto(..) function 10-fold cross-validation takes same time above (~2sec)! mat responses; my_svm.predict( testingdata, responses ); //responses matrix wrong.

i have 500 samples 1 class , 600 other class test, , right classifications are: 1/500 , 597/600.

craziest part: i have done same experiment same info on libsvm's matlab wrapper, , works. trying opencv version of it.

it not bug 1 back upwards vector linear cvsvm.

opencv optimizes linear svm downwards 1 back upwards vector. thought here back upwards vectors define classification margin, , actual classification separating hyperplane needed , can defined 1 vector.

parameter c doesn't matter if training info linearly separable. maybe case.

c++ opencv svm libsvm

No comments:

Post a Comment