21
12月 13

Apply DPM code on ImageNet Data

1 ImageSet生成

1.a Train

1.需要构建类别间的体系:list
2.需要构建每个subcategory的list(list of list)
在此基础上,构建每个类的正例list of list(sub_<class_name>.txt),以及相应的负例list of list(fake_<class_name>.txt)
将这些文件全部放入ImageSets文件夹

1.b Test & Val

只需构建所有文件的ImageList

2 VOCcode修改

2.a VOCinit()

VOCopts.annopath=[VOCopts.datadir VOCopts.dataset '/ILSVRC2013_DET_bbox_train/%s/%s.xml'];
VOCopts.imgpath=[VOCopts.datadir VOCopts.dataset '/ILSVRC2013_DET_train/%s.JPEG'];
VOCopts.test_imgpath=[VOCopts.datadir VOCopts.dataset '/ILSVRC2013_DET_%s/%s.JPEG'];
VOCopts.test_annopath=[VOCopts.datadir VOCopts.dataset '/ILSVRC2013_DET_bbox_val/%s.xml'];
VOCopts.imgsetpath=[VOCopts.datadir VOCopts.dataset '/ImageSets/%s.txt'];
VOCopts.clsimgsetpath=[VOCopts.datadir VOCopts.dataset '/ImageSets/%s.txt'];
VOCopts.sub_clsimgsetpath=[VOCopts.datadir VOCopts.dataset '/ImageSets/sub_%s.txt'];
VOCopts.fake_clsimgsetpath=[VOCopts.datadir VOCopts.dataset '/ImageSets/fake_%s.txt'];

2.b VOChash

包含VOChash_init()与VOChash_lookup()两个函数,hash key的计算部分均改为:

h=mod(str2double(s([7:10 16:end])),hsize)+1;

2.c VOCreadrecxml

注释掉10、11、17行:

% rec.source.annotation=x.source.annotation;
% rec.source.image=x.source.image;
% rec.segmented=strcmp(x.segmented,'1');

23行以下改为:

if isfield(x, 'object')
    for i=1:length(x.object)
        rec.objects(i)=xmlobjtopas(x.object(i));
    end
else
    rec.objects = [];
end

2.d VOCevaldet

read annotation处改为

recs(i)=PASreadrecord(sprintf(VOCopts.test_annopath,gtids{i}));

extract objects处增加:

if length(recs(i).objects) < 1
    continue;
end

3 voc-release5修改

3.a data/pascal_data.m

读正样本处:

sub_cls_set = textread(sprintf(VOCopts.sub_clsimgsetpath, ...
                                 cls), '%s');
ids = [];
for sub_cls = sub_cls_set
    single_ids      = textread(sprintf(VOCopts.clsimgsetpath, ...
                                       cls), '%s');
    ids = [ids single_ids];
end

正样本的文件路径:

pos(numpos).im      = sprintf(VOCopts.imgpath, rec.imgname);

读副样本处:

ids = [];
fake_cls_set = textread(sprintf(VOCopts.fake_clsimgsetpath, cls), ...
                       '%s');
for i = 1:length(fake_cls_set)
    single_ids    = textread(sprintf(VOCopts.clsimgsetpath, ...
                                     fake_cls_set{i}), '%s');
    ids = [ids single_ids'];
end

负样本不需要再做查找:

for i = 1:length(ids);
   tic_toc_print('%s: parsing negatives (%s %s): %d/%d\n', ...
                  cls, dataset_bg, year, i, length(ids));
   split_name = regexp(ids{i}, '_', 'split');
   this_cls = split_name{1};
   % rec = PASreadrecord(sprintf(VOCopts.annopath, this_cls, ids{i}));
   % clsinds = strmatch(cls, {rec.objects(:).class}, 'exact');
   %if length(clsinds) == 0
     dataid             = dataid + 1;
     numneg             = numneg+1;
      % split_name = regexp(rec.imgname, '_', 'split')
      % this_cls = split_name(1);
     neg(numneg).im     = sprintf(VOCopts.imgpath, [this_cls '/' ids{i}]);
     neg(numneg).flip   = false;
     neg(numneg).dataid = dataid;
   %end
end

3.b pascal_test.m

读文件的部分:

im = imread(sprintf(opts.test_imgpath, testset, ids{i}));

3.c pascal_eval.m

读取文件列表处:

ids = textread(sprintf(VOCopts.imgsetpath, testset), '%s');