我把补充的内容放最前面,显眼!
补充:1 关于负样本。框架里面提取负样本的方式是选择样本库中不包含训练类型的图片为负样本。我直接用库里面的图片。我用1000张左右的负样本,,自己准备的话也简单没太多好说的。提供图片路径就OK了,它自己会裁。
2 关于自己准备正样本要注意的问题:
(1) pos(numpos).flip = false; pos(numpos).trunc = 0;
(2) 最好不要自己手动裁正样本小图片当正样本图片,而应该将一张图片的中的正样本用坐标表示出来,做成类似原框架中的解析文件(用OPENCV之类的东西做应该容易吧),我是写脚本解析的别人的样本库,我的解析文件格式是:x1 y1 x2 y2 filepath, 这样一行对应一个正样本,在MATLAB格式化读取也方便。注意!没有标LABEL,RESIZE之类的步骤!只需要指明正样本的框,和相应的图片路径就OK。
3 关于pascal()第二个参数的问题:按作者的说法(组件的个数)不太好理解。我理解的意思是:Model中子模型的个数。这个值的设置比较重要,一般设置成1. 如果正样本比较多样化,比如行人样本中有两种情况:站立的,躺着的。这时应该设置成2。如果基本上只有一种情况,设成1就够了,因为设置成多个的话, 效果提 高不了多少,检测速度还慢了不少!看一下代码应该知道,组件分类的时候,只是简单的按SIZE的宽高比例分,并没有还可以分正面反面那么高级。
4 part个数 part大小的设置:在pascal_train.m里面model_addparts函数的最后两个参数。目标不同,这两个参数也可能不一样,可以先目测一下,大约多少个part可以基本捕获目标的基本特征。可能需要实验多次。
5 训练时间问题:刚开始调整训练参数的时候,只需要看大致的效果,所以只用很少的样本量就可以,还嫌慢的话,可以减少learn.cc里面的迭代次数(我就是这么干 的),还可以把pascal_train里面的maxneg的值改小,比如50。
6 怎么生成PCA统计信息文件: 参见
——————–邪恶的补充完结分割线—————————–
我是在
1pascal_init,global中的路径设置。
Felzenszwalb
2pascal_data.m中需要几行代码来防止因图片不存在而报错:
ifexist([VOCopts.datadirrec.imgname])==0
continue;
end
VOCopts.datadirrec.imgname代表样本图片的绝对路径,创建正负样本集的时候都应该进行判断,我下载的2011的库存在个别图片不存在的情况。
3
4compilelearn.cc
5compilec++helperfunctions.参见:前一篇
6WINDOWS
调用
调用
7执行pascal(‘person’,3);%trainandevaluatea6componentpersonmodel
8 我训练时出现过的错误和解决方法:
把 unix 调用换成system调用 感觉运行不稳定,把rewritedat.m里面的 unix([‘mv ‘ datfile ‘ ‘ oldfile]) 改成 movefile(datfile, oldfile)
unix([‘rm ‘ oldfile]) 改成delete(oldfile)。
同样是rewritedat.m中还会出现下标越界的情况:
把这段代码:
I = sort(I);pos = 1;for i = 1:length(I) cnt = I(i)-pos; while cnt > 0% + 2 to include the num non-zero blocks and example lengthinfo = fread(fin, labelsize+2, ‘int32’);dim = info(end);fseek(fin, dim*4, 0);cnt = cnt – 1; end y = fread(fin, labelsize+2, ‘int32’); dim = y(end); x = fread(fin, dim, ‘single’); fwrite(fout, y, ‘int32’); fwrite(fout, x, ‘single’); pos = I(i)+1;end
替换成:
I = sort(I);pos = 1;for i = 1:length(I) cnt = I(i)-pos; while cnt > 0% + 2 to include the num non-zero blocks and example lengthinfo = fread(fin, labelsize+2, ‘int32’);if length(info) == 0dim = 0;elsedim = info(end);end%dim = info(end);fseek(fin, dim*4, 0);cnt = cnt – 1; end y = fread(fin, labelsize+2, ‘int32’); %//! if length(y) == 0dim = 0; elsedim = y(end); end x = fread(fin, dim, ‘single’); fwrite(fout, y, ‘int32’); fwrite(fout, x, ‘single’); pos = I(i)+1;end
类似的越界错误在检测模块中,检测完成提取框时,如果检测个数为0的话也可能出现,不过影响不大。
c++ code for Discriminatively Trained Deformable Part Models
Readme里面的原文:
Usingthelearningcode
=======================
1.Downloadandinstallthe2006/2007/2008PASCALVOCdevkitanddataset.
(youshouldsetVOCopts.testset=’test’inVOCinit.m)
2.Modify’globals.m’accordingtoyourconfiguration.
3.Run’make’tocompilelearn.cc,theLSVMgradientdescentcode.
(Runfromashell,notMatlab.)
4.Startmatlab.
5.Runthe’compile’scripttocompilethehelperfunctions.
(youmayneedtoeditcompile.mtouseadifferentconvolution
routinedependingonyoursystem)
6.Usethe’pascal’scripttotrainandevaluateamodel.
example:
>pascal(‘person’,3);%trainandevaluatea6componentpersonmodel
Thelearningcodesavesanumberofintermediatefilesinacache
directorydefinedin’globals.m’.Youshoulddeletethesefilesbefore
trainingmodelsondifferentdatasets,orwhentrainingnewmodelsafter
modifingthecode.
Thecodealsogeneratessomeverylargetemporaryfilesduringtraining
(thedefaultconfigurationproducesfilesuptoabout3GB).Theyare
placedinatemporarydirectorydefinedin’globals.m’.Thisdirectory
shouldbeinalocalfilesystem.
福报不够的人,就会常常听到是非;