Custom SVM training for use with HOGDescriptor in OpenCV

I am trying to train my own detector for use with OpenCV :: HOGDescriptor, but I am having trouble creating an existing HOGDescriptor with my newly trained SVM.

I calculated HOG functions for positive and negative learning images, tagged them and trained SVM with CvSVM. The options I used are as follows:

    CvSVMParams params;
    params.svm_type =CvSVM::EPS_SVR;
    params.kernel_type = CvSVM::LINEAR;
    params.C = 0.01;
    params.p = 0.5;

Then I calculate the Primal Form of the support vectors, so that I get only one vector instead of many and set the calculated support vector using HOGDescriptor.setSVMDetector (vector);

This is the primary form.

When I use CvSVM.predict (), I can correctly classify objects using SVM, but HOGDescriptor.detect () or detectMultiScale () always returns many positive matches and does not give accurate predictions.

CvSVM.predict () uses the original support vectors for classification, so there might be something wrong with the way I calculate the primary form.

Is there anyone who trained his detector that can point me in the right direction?

+4
source share
3 answers

CvSVM svm. 1, -1. , rho , HogDescriptor.

LinearSVM.h

#ifndef LINEAR_SVM_H_
#define LINEAR_SVM_H_
#include <opencv2/core/core.hpp>
#include <opencv2/ml/ml.hpp>

class LinearSVM: public CvSVM {
public:
  void getSupportVector(std::vector<float>& support_vector) const;
};  

#endif /* LINEAR_SVM_H_ */

LinearSVM.cc

#include "linear_svm.h"    
void LinearSVM::getSupportVector(std::vector<float>& support_vector) const {

    int sv_count = get_support_vector_count();
    const CvSVMDecisionFunc* df = decision_func;
    const double* alphas = df[0].alpha;
    double rho = df[0].rho;
    int var_count = get_var_count();
    support_vector.resize(var_count, 0);
    for (unsigned int r = 0; r < (unsigned)sv_count; r++) {
      float myalpha = alphas[r];
      const float* v = get_support_vector(r);
      for (int j = 0; j < var_count; j++,v++) {
        support_vector[j] += (-myalpha) * (*v);
      }
    }
    support_vector.push_back(rho);
}
+5

. , CvSVM ( ). LIBSVM . HOGDescriptor.setSVMDetector(w): . / LIBSVM. ++, LIBSVM CV LIBSVM; , cv:: HOGDescriptor. w std::vector<float> w

    const double * const *sv_coef = model.sv_coef;
const svm_node * const *SV = model.SV;
int l = model.l;
model.label;

const svm_node* p_tmp = SV[0];
int len = 0;
while( p_tmp->index != -1 )
{
    len++;
    p_tmp++;
}
w.resize( len+1 );

for( int i=0; i<l; i++)
{
    double svcoef = sv_coef[0][i];
    const svm_node* p = SV[i];
    while( p->index != -1 )
    {
        w[p->index-1] += float(svcoef * p->value);
        p++;
    }
}
w[len] = float(-model.rho[0]);

, ...

+4

, Dalal HOG, , . ( , ), . .

Then add all these false positives to your negative image samples (negative data set), repeat the training. The resulting model, as proposed in the document, will return much less false positives.

Unfortunately, however, I tried (retraining), but the resulting model simply does not recognize anything even on positive samples. But I think it’s worth a try, because that’s exactly what was proposed in the inventor's article on the HOG detector

0
source

All Articles