forked from aosokin/cnn_head_detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.m
227 lines (197 loc) · 7.18 KB
/
demo.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
% Demo code
% Tuan-Hung Vu, Anton Osokin, Ivan Laptev, Context-aware CNNs for person head detection, ICCV 2015
%% Setup
setup;
%% Training ===============================
% %% To rerun our training and evaluation uncomment the following lines, specify matconvnetPath and cudaRoot to the root folder of Matconvnet and CUDA
% matconvnetPath = '~/local/software/matlab_toolboxes/matconvnet-1.0-beta12';
% setup( matconvnetPath );
%
% cudaRoot = '/usr/cuda-7.0' ;
% compile_mex(cudaRoot);
%
% %% Train/evaluate local model
% run_training_localModel;
% run_computeScores_localModel;
%
% %% Train/evaluate pairwise model
% run_training_pairwiseModel;
% run_computeScores_pairwiseModel;
%
% %% Train/evaluate global model
% run_training_globalModel;
% run_computeScores_globalModel;
%% Evaluation ===============================
% Following code will evaluate results of different models on
% HollywoodHeads test set.
% List of evaluated models
% - local
% - pairwise
% - local + pairwise + global
% - RCNN
% - DPM
VOCinit_HH; % prepare VOC options
RES_ROOT = fullfile(VOCopts.resdir, 'res');
if ~exist(RES_ROOT, 'dir')
mkdir(RES_ROOT)
end
%load testset
im_format = VOCopts.imgpath;
test_set = readLines(sprintf(VOCopts.imgsetpath, 'test'));
%pre-saved detection path format
LOCAl_SAVE_DET_FORMAT = 'results/HollywoodHeads/local/dets/%s.mat';
GLOBAL_SAVE_DET_FORMAT = 'results/HollywoodHeads/global/dets/%s.mat';
PAIRWISE_SAVE_DET_FORMAT = 'results/HollywoodHeads/pairwise/dets/%s.mat';
RCNN_SAVE_DET_FORMAT = 'results/HollywoodHeads/rcnn/dets/%s.mat';
DPM_SAVE_DET_FORMAT = 'results/HollywoodHeads/dpm/dets/%s.mat';
%% Local model
modelname = 'Local';
disp(['> Evaluating model: ' modelname]);
saverespath = fullfile(RES_ROOT, [modelname '.mat']);
if ~exist(saverespath, 'file')
opts = struct;
opts.det.modeltype = 'local';
opts.det.scoretype = 'raw';
opts.det.path_format = LOCAl_SAVE_DET_FORMAT;
opts.im_path_format = im_format;
opts.im_set = test_set;
%regressed version
opts.regression.param = [0.000500595642863 -0.00649301373331 0.975682458365 0.982287603066];
det = load_det(opts);
[rec, prec, ap] = evaluate_detection_HH(det, modelname, VOCopts, 'head');
save(saverespath, 'rec', 'prec', 'ap', 'det', 'opts', 'VOCopts');
else
load(saverespath);
end
%% Pairwise model
modelname = 'Pairwise';
disp(['> Evaluating model: ' modelname]);
saverespath = fullfile(RES_ROOT, [modelname '.mat']);
if ~exist(saverespath, 'file')
opts = struct;
opts.det.modeltype = 'pairwise';
opts.det.scoretype = 'raw';
opts.det.path_format = PAIRWISE_SAVE_DET_FORMAT;
opts.im_path_format = im_format;
opts.im_set = test_set;
%regressed version
opts.regression.param = [0.000500595642863 -0.00649301373331 0.975682458365 0.982287603066];
det = load_det(opts);
[rec, prec, ap] = evaluate_detection_HH(det, modelname, VOCopts, 'head');
save(saverespath, 'rec', 'prec', 'ap', 'det', 'opts', 'VOCopts');
else
load(saverespath);
end
%% Local + global + pairwise model
modelname = 'Local+Global+Pairwise';
disp(['> Evaluating model: ' modelname]);
saverespath = fullfile(RES_ROOT, [modelname '.mat']);
if ~exist(saverespath, 'file')
%load non-regressed local detections
local_model_nonreg_save_path = fullfile(RES_ROOT, 'Local_model_nonreg.mat');
if ~exist(local_model_nonreg_save_path, 'file')
opts = struct;
opts.im_path_format = im_format;
opts.im_set = test_set;
opts.det.scoretype = 'raw';
opts.regression.param = [0 0 1 1];
opts.det.modeltype = 'local';
opts.det.path_format = LOCAl_SAVE_DET_FORMAT;
det = load_det(opts);
save(local_model_nonreg_save_path, 'det');
clear det;
end
%load non-regressed pairwise detections
pairwise_model_nonreg_save_path = fullfile(RES_ROOT, 'Pairwise_model_nonreg.mat');
if ~exist(pairwise_model_nonreg_save_path, 'file')
opts = struct;
opts.im_path_format = im_format;
opts.im_set = test_set;
opts.det.scoretype = 'raw';
opts.regression.param = [0 0 1 1];
opts.det.modeltype = 'pairwise';
opts.det.path_format = PAIRWISE_SAVE_DET_FORMAT;
det = load_det(opts);
save(pairwise_model_nonreg_save_path, 'det');
clear det;
end
%combined detections
opts = struct;
opts.local_res_path = local_model_nonreg_save_path;
opts.pairwise_res_path = pairwise_model_nonreg_save_path;
opts.im_path_format = im_format;
opts.im_set = test_set;
opts.regression.param = [0.000500595642863 -0.00649301373331 0.975682458365 0.982287603066];
opts.ialpha = 5;
opts.ibias = 9;
opts.global.alpha = 0.30;
opts.global.path_format = GLOBAL_SAVE_DET_FORMAT;
opts.global.platform = 'matconvnet';
det = load_det_local_pairwise_global(opts);
[rec, prec, ap] = evaluate_detection_HH(det, modelname, VOCopts, 'head');
save(saverespath, 'rec', 'prec', 'ap', 'det', 'opts', 'VOCopts');
else
load(saverespath);
end
%% RCNN
modelname = 'R-CNN';
disp(['> Evaluating model: ' modelname]);
saverespath = fullfile(RES_ROOT, [modelname '.mat']);
if ~exist(saverespath, 'file')
opts = struct;
opts.regression.param = [-0.00239252348267 -0.017133841922 0.975428819577 0.958512960492];
opts.det.modeltype = 'rcnn_svm';
opts.det.scoretype = 'raw';
opts.det.path_format = RCNN_SAVE_DET_FORMAT;
opts.im_path_format = im_format;
opts.im_set = test_set;
det = load_det(opts);
[rec, prec, ap] = evaluate_detection_HH(det, modelname, VOCopts, 'head');
save(saverespath, 'rec', 'prec', 'ap', 'det', 'opts', 'VOCopts');
else
load(saverespath);
end
%% DPM
modelname = 'DPM Face';
disp(['> Evaluating model: ' modelname]);
saverespath = fullfile(RES_ROOT, [modelname '.mat']);
if ~exist(saverespath, 'file')
opts = struct;
opts.regression.param = [-0.0110632673917 -0.154468706569 1.17615081441 1.32509178499];
opts.det.modeltype = 'dpm';
opts.det.scoretype = 'raw';
opts.det.path_format = DPM_SAVE_DET_FORMAT;
opts.im_path_format = im_format;
opts.im_set = test_set;
det = load_det(opts);
[rec, prec, ap] = evaluate_detection_HH(det, modelname, VOCopts, 'head');
save(saverespath, 'rec', 'prec', 'ap', 'det', 'opts', 'VOCopts');
else
load(saverespath);
end
%% Draw AP curve
%list of visualized methods and corresponding curve-colors
list_model = {'DPM Face', 'R-CNN', 'Local', 'Local+Global+Pairwise'};
color_hex = {'ffbd0d', '1e72ef', '019c59', 'dd4f3b'};
%draw curves
fig = figure('PaperPositionMode','auto'); hold on;
fontsize = 43;
linewidth = 6;
str_legend = [];
for i=1:length(list_model)
saverespath = fullfile(RES_ROOT, [list_model{i} '.mat']);
if exist(saverespath, 'file')
load(saverespath);
plot(rec,prec,'-', 'color', hex2rgb(color_hex{i}),'LineWidth',linewidth);
str_legend{end+1} = sprintf('%s (%.1f%%)', list_model{i}, ap*100);
end
end
grid;
set(gca, 'FontSize', fontsize);
set(gca, 'YLim', [0 1]);
set(gca, 'XLim', [0 1]);
xlabel('Recall', 'fontsize', fontsize);
ylabel('Precision', 'fontsize', fontsize);
l = legend(str_legend);
set(l, 'Interpreter', 'none');
set(gcf, 'Position', [0 0 1920 1024]);