forked from rbgirshick/voc-dpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcascade_test.m
76 lines (69 loc) · 2.47 KB
/
cascade_test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function ds = cascade_test(model, testset, year, suffix)
% boxes1 = cascade_test(cls, model, testset, year, suffix)
% Compute bounding boxes in a test set.
% boxes1 are detection windows and scores.
% Now we also save the locations of each filter for rescoring
% parts1 gives the locations for the detections in boxes1
% (these are saved in the cache file, but not returned by the function)
% AUTORIGHTS
% -------------------------------------------------------
% Copyright (C) 2009-2012 Ross Girshick
%
% This file is part of the voc-releaseX code
% (http://people.cs.uchicago.edu/~rbg/latent/)
% and is available under the terms of an MIT-like license
% provided in COPYING. Please retain this notice and
% COPYING if you use this file (or a portion of it) in
% your project.
% -------------------------------------------------------
conf = voc_config('pascal.year', year, ...
'eval.test_set', testset);
VOCopts = conf.pascal.VOCopts;
cachedir = conf.paths.model_dir;
cls = model.class;
ids = textread(sprintf(VOCopts.imgsetpath, testset), '%s');
pca = 5;
model = cascade_model(model, model.year, pca, model.thresh);
% run detector in each image
try
load([cachedir cls '_boxes_' testset '_' suffix]);
catch
% parfor gets confused if we use VOCopts
opts = VOCopts;
num_ids = length(ids);
ds_out = cell(1, num_ids);
bs_out = cell(1, num_ids);
% parallel implementation disabled for single-threaded tests
parfor i = 1:num_ids
if strcmp('inriaperson', cls)
% INRIA uses a mixutre of PNGs and JPGs, so we need to use the annotation
% to locate the image. The annotation is not generally available for PASCAL
% test data (e.g., 2009 test), so this method can fail for PASCAL.
rec = PASreadrecord(sprintf(opts.annopath, ids{i}));
im = imread([opts.datadir rec.imgname]);
else
im = imread(sprintf(opts.imgpath, ids{i}));
end
th = tic();
pyra = featpyramid(im, model);
time_feat = toc(th);
th = tic();
[ds, bs] = cascade_detect(pyra, model, model.thresh);
time_det = toc(th);
if ~isempty(ds)
[ds, bs] = clipboxes(im, ds, bs);
I = nms(ds, 0.5);
ds_out{i} = ds(I,[1:4 end]);
bs_out{i} = bs(I,:);
else
ds_out{i} = [];
bs_out{i} = [];
end
fprintf('%s: testing: %s %s, %d/%d (time %.3f)\n', cls, testset, year, ...
i, length(ids), time_det);
end
ds = ds_out;
bs = bs_out;
save([cachedir cls '_boxes_' testset '_' suffix], ...
'ds', 'bs');
end