opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

CvSVM CvSVM::C_SVC get_support_vector_count() & get_support_vector(int i) not working

Open opencv-pushbot opened this issue 9 years ago • 0 comments

Transferred from http://code.opencv.org/issues/2978

|| Ivan Filković on 2013-04-19 09:29
|| Priority: Normal
|| Affected: 2.4.0 - 2.4.7
|| Category: ml
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: Any / Any

CvSVM CvSVM::C_SVC get_support_vector_count() & get_support_vector(int i) not working

Hello,

when CvSVM::C_SVC kernel is linear get_support_vector_count() always returns 1, predict works fine.
Problem can be recreated with http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html#introductiontosvms

Workaround:

CvSVMParams params;
params.svm_type    = CvSVM::C_SVC;
params.kernel_type = CvSVM::POLY;
params.degree = 1;

Best regards,
filko

History

Amro _ on 2013-12-28 08:26
I can confirm this as well (both running the tutorial code and using my own dataset)!

Using the code from the tutorial, even though the prediction is correct, the trained SVM model with linear kernel reports incorrect support vectors (I get only one SV @v = {-0.008130, 0.008163}@ which is completely off).

Changing to a polynomial kernel with degree=1 as suggested (which is equivalent to a linear kernel) returns the expected three support vectors shown in the screenshot of the tutorial...

I'm using the OpenCV 2.4.7 Windows binaries and VS2012 compiler (64-bit) on Windows 8.1.
-   Target version set to 2.4.8
-   Assignee changed from Maria Dimashova to Roman Donchenko
Alexander Smorkalov on 2013-12-30 10:38
-   Target version changed from 2.4.8 to 2.4.9
tian xuxo on 2013-12-31 16:18
hmm yes I'm experiencing this as well, both on windows vs2010 and xcode on os x and the polynomial does fix it
Daniil Osokin on 2014-01-13 13:32
Hi, guys! This is not a bug, in case of _linear_ kernel we can compress all support vectors into one. Here is the details: https://github.com/Itseez/opencv/blob/2.4/modules/ml/src/svm.cpp#L1531
-   Affected version changed from 2.4.5 (latest release) to 2.4.0 -
    2.4.7
-   Operating System set to Any
-   HW Platform set to Any
-   Priority changed from High to Normal
-   Status changed from Open to Cancelled
Amro _ on 2014-01-14 00:40
Interesting. I'm no SVM expert, but doing this "optimization" basically loses the actual support vectors in favor of pre-calculating some terms in the decision function (by multiplying support vectors with corresponding alpha coefficients), in hope of making the future predictions faster to compute...

I'm wondering if this call to @CvSVM::optimize_linear_svm()@ should be commented-out, or at least have an option to control whether it is performed or not.
-   % Done changed from 0 to 50
-   Status changed from Cancelled to Open
Amro _ on 2014-01-14 01:14
Here is the PR which introduced it: https://github.com/Itseez/opencv/pull/669
-   Assignee changed from Roman Donchenko to Vadim Pisarevsky
Alexander Smorkalov on 2014-04-30 19:05
-   Target version changed from 2.4.9 to 2.4.10

opencv-pushbot avatar Jul 27 '15 09:07 opencv-pushbot