c++ - Recommended values for OpenCV SVM parameters -
any idea on recommended parameters opencv svm? i'm playing letter_recog.cpp in opencv sample directory, however, svm accuracy poor! in 1 run got 62% accuracy:
$ ./letter_recog_modified -data /home/cobalt/opencv/samples/data/letter-recognition.data -save svm_letter_recog.xml -svm database /home/cobalt/opencv/samples/data/letter-recognition.data loaded. training classifier ... data.size() = [16 x 20000] responses.size() = [1 x 20000] recognition rate: train = 64.3%, test = 62.2%
the default parameters are:
model = svm::create(); model->settype(svm::c_svc); model->setkernel(svm::linear); model->setc(1); model->train(tdata);
setting trainauto() didn't help; gave me weird 0 % test accuracy:
model = svm::create(); model->settype(svm::c_svc); model->setkernel(svm::linear); model->trainauto(tdata);
result:
recognition rate: train = 0.0%, test = 0.0%
update using yangjie's answer:
$ ./letter_recog_modified -data /home/cobalt/opencv/samples/data/letter-recognition.data -save svm_letter_recog.xml -svm database /home/cobalt/opencv/samples/data/letter-recognition.data loaded. training classifier ... data.size() = [16 x 20000] responses.size() = [1 x 20000] recognition rate: train = 58.8%, test = 57.5%
the result no longer 0% accuracy worse 62% earlier.
using rbf kernel trainauto() worst?
$ ./letter_recog_modified_rbf -data /home/cobalt/opencv/samples/data/letter-recognition.data -save svm_letter_recog.xml -svm database /home/cobalt/opencv/samples/data/letter-recognition.data loaded. training classifier ... data.size() = [16 x 20000] responses.size() = [1 x 20000] recognition rate: train = 18.5%, test = 11.6%
parameters:
model = svm::create(); model->settype(svm::c_svc); model->setkernel(svm::rbf); model->trainauto(tdata);
i debugged sample code , found reason.
the responses
mat
of ascii code of letters.
however, predicted labels returned svm trained svm::trainauto
ranging 0-25, correspond 26 classes. can observed looking @ <class_labels>...</class_labels>
in output file svm_letter_recog.xml
.
therefore in test_and_save_classifier
, r = model->predict( sample )
, responses.at<int>(i)
apparently not equal.
i found if use svm::train
, class labels 65-89 instead, why can normal result @ first.
solution
i not sure whether bug. if want use svm::trainauto
in sample now, can change
test_and_save_classifier(model, data, responses, ntrain_samples, 0, filename_to_save);
in build_svm_classifier
to
test_and_save_classifier(model, data, responses, ntrain_samples, 'a', filename_to_save);
update
trainauto
, train
should have same behavior in class_labels
. problem due bug fix before. have created pull request opencv fix problem.
Comments
Post a Comment