forked from rbgirshick/voc-dpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_cascade.m
124 lines (98 loc) · 3.28 KB
/
demo_cascade.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function demo_cascade()
% Run cascade demo.
%
% Note that unless you have compiled fconv.cc as your convolution
% function, you will be comparing a multi-threaded version of the
% DP algorithm to a single-threaded version of the cascade algorithm.
% 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.
% -------------------------------------------------------
startup;
fprintf('compiling the code...');
compile;
fprintf('done.\n\n');
fprintf(['\n\n' ...
' ~~~~~~~~~~~ README ~~~~~~~~~~~\n' ...
'This is comparing a MULTITHREADED, SSE-accelerated version\n' ...
'of the baseline DP algorithm to a SINGLE-THREADED, non-SSE\n' ...
'version of the cascade. Speedups will be less than expected\n' ...
'if you are running this on a multicore system.\n\n']);
input('Noted? Press return to continue.');
load('VOC2007/car_final');
test('000034.jpg', model);
fprintf('\nPress any key to continue with demo'); pause; fprintf('...ok\n\n');
load('INRIA/inriaperson_final');
test('000061.jpg', model);
fprintf('\nPress any key to continue with demo'); pause; fprintf('...ok\n\n');
load('VOC2007/bicycle_final');
test('000084.jpg', model);
function test(impath, model);
name = model.class;
clf;
fprintf('///// Running demo for %s /////\n\n', name);
fprintf('Loading a test image');
fprintf('...done\n');
im = imread(impath);
subplot(1,3,1);
imagesc(im);
axis image;
axis off;
fprintf('Compute cascade thresholds');
fprintf('...done\n');
thresh = -0.5;
pca = 5;
orig_model = model;
csc_model = cascade_model(model, '2007', pca, thresh);
orig_model.thresh = csc_model.thresh;
fprintf('Building the feature pyramid...');
th = tic();
pyra = featpyramid(double(im), csc_model);
tF = toc(th);
fprintf('done\n');
fprintf(' --> Feature pyramid generation took %f seconds\n', tF);
fprintf('Computing detections with dynamic programming...');
th = tic;
[dDP, bDP] = gdetect(pyra, orig_model, orig_model.thresh);
tDP = toc(th);
fprintf('done\n');
fprintf(' --> DP detection took %f seconds\n', tDP);
fprintf('Computing detections with star-cascade...');
th = tic;
[dCSC, bCSC] = cascade_detect(pyra, csc_model, csc_model.thresh);
tCSC = toc(th);
fprintf('done\n');
fprintf(' --> Cascade detection took %f seconds\n', tCSC);
fprintf(' --> Speedup = %fx\n', tDP/tCSC);
b = getboxes(orig_model, im, dDP, reduceboxes(orig_model, bDP));
subplot(1,3,2);
showboxes(im, b);
title('dynamic programming detections');
b = getboxes(csc_model, im, dCSC, bCSC);
subplot(1,3,3);
showboxes(im, b);
title('star-cascade detections');
function b = getboxes(model, image, det, all)
b = [];
if ~isempty(det)
try
% attempt to use bounding box prediction, if available
bboxpred = model.bboxpred;
[det all] = clipboxes(image, det, all);
[det all] = bboxpred_get(bboxpred, det, all);
catch
warning('no bounding box predictor found');
end
[det all] = clipboxes(image, det, all);
I = nms(det, 0.5);
det = det(I,:);
all = all(I,:);
b = [det(:,1:4) all];
end