Jump to content
Compvision.ru
Sign in to follow this  
iskees

SVM light

Recommended Posts

SVM light в качестве результатов обучения выдает файл. Кто знает как его переделать под формат svm который в opencv (ядро радиальная базисная функция)?

Edited by iskees

Share this post


Link to post
Share on other sites

SVM-light Version V6.02
2 # kernel type
3 # kernel parameter -d 
1 # kernel parameter -g 
1 # kernel parameter -s 
1 # kernel parameter -r 
empty# kernel parameter -u 
11 # highest feature index 
168015 # number of training documents 
36580 # number of support vectors plus 1 
0.52852846 # threshold b, each following line is a SV (starting with alpha*y)
-0.49999999999727612 1:1 2:-0.97321862 3:0 4:0 5:0.31793973 6:38.749599 7:-1 8:1 9:1 10:1 11:90.104164 #
0.49999999999727612 1:1 2:-1 3:0 4:0 5:0.41736919 6:24.041599 7:-1 8:0.98609132 9:0.88873035 10:1 11:92.61364 #

и так далее строки с цифрами на 4 метра

Share this post


Link to post
Share on other sites

Думаю самый простой вариант это посмотреть как сохраняется модель .yml или .xml от SVM в opencv и скопировать данные из SVM-light

пример сохранения классификатора в train_svm

https://github.com/Itseez/opencv/blob/b46719b0931b256ab68d5f833b8fadd83737ddd1/samples/cpp/train_HOG.cpp

Да и большая ли разница между SVM-light и LibSVM (которая используется в opencv)?

https://github.com/Itseez/opencv/blob/4997f5dfe9d1fa44f9576649a9f604026714ac1a/modules/ml/src/svm.cpp

Share this post


Link to post
Share on other sites

Меня лично интересуют быстрые линейные модели.

например в opencv  SVM с линейным ядром сохраняется так

 

%YAML:1.0
my_svm: !!opencv-ml-svm
   svm_type: C_SVC
   kernel: { type:LINEAR }
   C: 1.0000000000000001e-05
   term_criteria: { epsilon:1.1920928955078125e-07, iterations:10000 }
   var_all: 4
   var_count: 4
   class_count: 2
   class_labels: !!opencv-matrix
      rows: 1
      cols: 2
      dt: i
      data: [ 0, 1 ]
   sv_total: 1
   support_vectors:
      - [ 6.45558350e-03, 3.20321769e-02, -7.84457382e-03,
          -1.01621241e-04 ]
   decision_functions:
      -
         sv_count: 1
         rho: 1.3422618222817990e+00
         alpha: [ 1. ]
         index: [ 0 ]

и для линейного ядра предикшн будет выглядеть как то так:

    double *w= get_weights();
    double bias= get_bias();

    for(int y=0;y<data.rows;++y)
    {
        double res= 0.0;
        for(int i=0;i<data.cols;++i)
        {
            res+= data.at<float>(y,i)*w;
        }
        int label= ((res+bias)>0)?1:0; // output labels [0,1]
    }

И я так понимаю, что "support_vectors:" это как раз weights, а "rho" это bias.

SVM в Opencv  на базе LibSVM и это медленно, не знаю что быстрее в случае нелинейности, но Liblinear явно быстрее в линейном случае.

Возможно скоро сделаю биндинги Liblinear для opencv и небольшой бенчмарк.

 

 

Кстати не знаю в каком состоянии сейчас этот репозиторий, но на первый взгляд там есть libsvm и svmlight

https://github.com/DaHoC/trainHOG

 

в самом opencv есть пример

https://github.com/Itseez/opencv/blob/ddf82d0b154873510802ef75c53e628cd7b2cb13/samples/cpp/train_HOG.cpp

Edited by mrgloom

Share this post


Link to post
Share on other sites

Есть какой то способ получить bias из Opencv Linear SVM?

sign(x*w+b).

 

//print weights
cout << "support_vector_count: " << svm.get_support_vector_count() << endl;
cout << "w" << endl;
for(int i=0;i<svm.get_support_vector_count();++i)
{
    cout << *svm.get_support_vector(i);
}
cout << endl;
Edited by mrgloom

Share this post


Link to post
Share on other sites

mrgloom, забыл сказать спасибо, ссылки очень помогли

Edited by kilop

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×