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

时间: 2024-08-09 10:43:31

libsvm+detector_(libsvm参数说明)的相关文章

libsvm的数据格式及制作

1.libsvm数据格式 libsvm使用的训练数据和检验数据文件格式如下: [label] [index1]:[value1] [index2]:[value2] … [label] [index1]:[value1] [index2]:[value2] … label  目标值,就是说class(属于哪一类),就是你要分类的种类,通常是一些整数. index 是有顺序的索引,通常是连续的整数.就是指特征编号,必须按照升序排列 value 就是特征值,用来train的数据,通常是一堆实数组成.

Libsvm在python中的使用

LIBSVM是台湾大学林智仁(LinChih-Jen)教授等开发设计的一个简单.易于使用和快速有效的SVM模式识别与回归的软件包,他不但提供了编译好的可在Windows系列系统的执行文件,还提供了源代码,方便改进.修改以及在其它操作系统上应用:该软件对SVM所涉及的参数调节相对比较少,提供了很多的默认参数,利用这些默认参数可以解决很多问题:并提供了交互检验(Cross Validation)的功能.该软件包可在http://www.csie.ntu.edu.tw/~cjlin/免费获得.该软件可

LibSVM for Python 使用

经历手写SVM的惨烈教训(还是太年轻)之后,我决定使用工具箱/第三方库 Python libsvm的GitHub仓库 LibSVM是开源的SVM实现,支持C, C++, Java,Python , R 和 Matlab 等, 这里选择使用Python版本. 安装LibSVM 将LibSVM仓库的所有内容放入Python的包目录\Lib\site-packages或者工程目录中. 在libsvm根目录和python子目录下中分别新建名为__init__.py的空文件,这两个空文件将标识所在的目录为

64位matlab中libsvm的安装

因为windows版的matlab对编译器的识别不好.所以直接在网上下了已经编译好的libsvm文件放入toolbox文件夹就可以用libsvm了 libsvm已编译好的文件下载地址: 猛戳我下载 1.把下载好的文件放入*/matlab/toolbox中 2.在matlab中set path.把"*\Matlab 2013b\toolbox\libsvm-3.18\matlab"加入到path中 over 64位matlab中libsvm的安装,布布扣,bubuko.com

Matlab 2015b安装libsvm 3.21

1.下载libsvm 3.21,更新日期为2015年12月14日 https://www.csie.ntu.edu.tw/~cjlin/libsvm/ Download LIBSVM The current release (Version 3.21, December 2015) of LIBSVM can be obtained by downloading the zip fileor tar.gzfile. You can also check this github directory

LIBSVM与LIBLINEAR

原文: http://orangeprince.info/2014/11/23/libsvm-liblinear-2/ http://orangeprince.info/2014/11/22/libsvm-liblinear-1/ LIBSVM与LIBLINEAR(一) 在过去的十几年里,支持向量机(Support Vector Machines)应该算得上是机器学习领域影响力最大的算法了.而在SVM算法的各种实现工具中,由国立台湾大学林智仁老师开发的工具包LIBSVM,又无疑是影响力最大的.2

Linux下libsvm的安装及简单练习

引文:常常在看paper的时候.就看到svm算法,可是要自己来写真的是难于上青天呀! 所幸有一个libsvm的集成软件包给我们使用,这真的是太好了.以下简介下怎么来使用它吧! LIBSVM是一个集成软件包.提供支持向量机分类(C-SVC,nu-SVC),回归(epsilon-SVR,nu-SVR)以及分布预计(one-class SVM).工具包支持多类分类问题.LIBSVM是台湾大学林智仁(LinChih-Jen)副教授等开发设计的一个简单.易于使用和高速有效的SVM模式识别与回归的软件包.

win10环境下python版libsvm的安装

1.前言 由于毕业设计需要用到libsvm,所以最近专心于配置libsvm,曾经尝试过在matlab中安装,但是没有成功.最终在Python环境中完成安装. 2.LIBSVM介绍 LIBSVM 是台湾大学林智仁(Lin Chih-Jen)教授等开发设计的一个操作简单.易于使用.快速有效的 SVM 软件包.可以解决分类问题(包括 C-SVC.n-SVC ).回归问题(包括 e-SVR.n-SVR )以及分布估计(one-class-SVM)等问题,提供了线性.多项式.径向基和 S 形函数四种常用的

Stanford机器学习---第八讲. 支持向量机SVM

本文原始文章见http://blog.csdn.net/abcjennifer/article/details/7849812,本文添加了一些自己的理解 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归.Octave Tutorial.Logistic Regression.Regularization.神经网络.机器学习系统设计.SVM(Support Vector Machines 支持向量机).聚类.降维.异常检测.大规模机器学习等章节.所有内容均来自Sta