zoukankan      html  css  js  c++  java
  • libsvm+detector_(libsvm参数说明)

    细分析了cvhop.cpp中的compute函数,可以直接调用它来获得样本HOG,然后训练得到检测算子

    1.制作样本
    2.对每一张图片调用
    hog.compute(img, descriptors,Size(8,8), Size(0,0));
    可以生成hog descriptors,把它保存到文件中
    for(int j=0;j<3780;j++)
    fprintf(f,"%f,",descriptors[j]);
    3.利用SVM进行训练和分类,可得到权重系数,即getDefaultPeopleDetector()函数中调用的
    检测 算子 detector[]

    使用libsvm求取权重

    直接使用libsvm,需要按它的格式构造数据,下面简述在matlab下使用libsvm 
    下载libsvm-mat-2.9-1 (libsvm3.12版本
    方法1:
    切换到libsvm-mat-2.9-1所在的目录下,打开MATLAB键入:
    mex -setup
    方法2:matlab菜单 File-->set path 将libsvm-mat-2.9-1所在路径添加进来。
    ----------------------
    下面以libsvm-mat-2.9-1自带的heart_scale为例进行介绍
    -----------kernel_type为线性----------------------------------
    load heart_scale.mat 
    train_data = heart_scale_inst(1:150,:);
    train_label = heart_scale_label(1:150,:);
    test_data = heart_scale_inst(151:270,:); 
    test_label = heart_scale_label(151:270,:);
    model_linear = svmtrain(train_label, train_data, '-t 0')
    [predict_label_L, accuracy_L, dec_values_L] = svmpredict(test_label, test_data,model_linear);
    ----------训练后得到模型-------
    model_linear = 
    Parameters: [5x1 double]
    nr_class: 2
    totalSV: 58
    rho: -1.1848
    Label: [2x1 double]
    ProbA: []
    ProbB: []
    nSV: [2x1 double]
    sv_coef: [58x1 double]
    SVs: [58x13 double]
    -----------如何从模型中求取权重系数----
    参考以下网站,可知 
    http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#f804
    对于2类问题,可如下求解线性问题(y=wx+b)的权重系数w和b
    w = model_linear.SVs' * model_linear.sv_coef;
    b = -model_linear.rho;
    ---------
    求出的w即是OpenCv中的detector[]

    注意训练样本可能出现过拟合或者欠拟合~~~:都是在图正中间圈一个框!

    libsvm参数说明:

    English:
    libsvm_options:
    -s svm_type : set type of SVM (default 0)
     0 -- C-SVC
     1 -- nu-SVC
     2 -- one-class SVM
     3 -- epsilon-SVR
     4 -- nu-SVR
    -t kernel_type : set type of kernel function (default 2)
     0 -- linear: u'*v
     1 -- polynomial: (gamma*u'*v + coef0)^degree
     2 -- radial basis function: exp(-gamma*|u-v|^2)
     3 -- sigmoid: tanh(gamma*u'*v + coef0)
     4 -- precomputed kernel (kernel values in training_instance_matrix)
    -d degree : set degree in kernel function (default 3)
    -g gamma : set gamma in kernel function (default 1/k)
    -r coef0 : set coef0 in kernel function (default 0)
    -c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
    -n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
    -p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
    -m cachesize : set cache memory size in MB (default 100)
    -e epsilon : set tolerance of termination criterion (default 0.001)
    -h shrinking: whether to use the shrinking heuristics, 0 or 1 (default 1)
    -b probability_estimates: whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
    -wi weight: set the parameter C of class i to weight*C, for C-SVC (default 1)
    -v n: n-fold cross validation mode
    ==========================================================
    Chinese:
    Options:可用的选项即表示的涵义如下
      -s svm类型:SVM设置类型(默认0)(对于回归只能选3或4)
      0 -- C-SVC
      1 --v-SVC
      2 – 一类SVM
      3 -- e -SVR
      4 -- v-SVR


      -t 核函数类型:核函数设置类型(默认2)
      0 – 线性:u'v
      1 – 多项式:(r*u'v + coef0)^degree
      2 – RBF函数:exp(-r|u-v|^2)(gaussian kernel)
      3 –sigmoid:tanh(r*u'v + coef0)


      -d degree:核函数中的degree设置(针对多项式核函数)(默认3)


      -g (gamma):核函数中的gamma函数设置(针对多项式/RBF/sigmoid核函数)(默认1/ k,类别的倒数)(gaussian kernel 2σ2


      -r coef0:核函数中的coef0设置(针对多项式/sigmoid核函数)((默认0)


      -c cost:设置C-SVC,e -SVR和v-SVR中的参数C(默认1)(参数C)


      -n nu:设置v-SVC,一类SVM和v- SVR中的参数nu(默认0.5)


      -p epsilon:设置epsilon-SVR的损失函数epsilon的值(默认0.1)


      -m cachesize:设置cache内存大小,以MB为单位(默认100)


      -e eps:设置允许的终止迭代的标准(默认0.001)


      -h shrinking:是否使用启发式,0或1(默认1)


      -wi weight:设置第i类的参数C为weight*C,对于C-SVC中的C(默认1)


      -v n: n-fold交互检验模式,n为fold的个数,必须大于等于2
      其中-g选项中的k是指输入数据中的属性数。option -v 随机地将数据剖分为n部分并计算交互检验准确度和均方根误差。以上这些参数设置可以按照SVM的类型和核函数所支持的参数进行任意组合,如果设置的参数在函数或SVM类型中没有也不会产生影响,程序不会接受该参数;如果应有的参数设置不正确,参数将采用默认值。

     -Parameters: parameters
            -nr_class: number of classes; = 2 for regression/one-class svm:数据集中有多少类别

            -totalSV: total SV:总共的支持向量的数目

            -rho: -b of the decision function(s) wx+b
     

           -Label: label of each class; empty for regression/one-class SVM


            -ProbA: pairwise probability information; empty if -b 0 or in one-class SVM
            -ProbB: pairwise probability information; empty if -b 0 or in one-class SVM


            -nSV: number of SVs for each class; empty for regression/one-class SVM:支持向量个数


            -sv_coef: coefficients for SVs in decision functions:支持向量在决策函数中的系数


            -SVs: support vectors

    If you do not use the option '-b 1', ProbA and ProbB are empty
    matrices. If the '-v' option is specified, cross validation is
    conducted and the returned model is just a scalar: cross-validation
    accuracy for classification and mean-squared error for regression.

    参数详解PPT

    libsvm Introduction Paper (林大神写的Introduction,有类型详解和数学推导……)

     还有一篇libsvm注意事项:http://blog.csdn.net/boyhailong/article/details/7100968

    还有一篇讲解松弛变量和惩罚因子(很有用):Relation Extraction中SVM分类样例unbalance data问题解决 -松弛变量与惩罚因子

    from: http://blog.csdn.net/yangtrees/article/details/7605279

  • 相关阅读:
    自定义MyBatis
    SpringMVC基本
    Struts2访问Servlet
    Struts2的配置
    Rust开发环境搭建
    android webview和 javascript 进行交互
    C#开发step步骤条控件
    如何用cmd命令递归文件夹中的所有特定文件,拷贝到另一个文件夹中
    C#用DesignSurface实现一个简单的窗体设计器
    Roslyn如何实现简单的代码提示
  • 原文地址:https://www.cnblogs.com/GarfieldEr007/p/5401888.html
Copyright © 2011-2022 走看看