Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 185 lines (157 sloc) 5.482 kb
8117fe6 Tomasz Malisiewicz change apply_calibration name to something more meaningful
authored
1 function final = esvm_pool_exemplar_dets(grid, models, M, params)
9cdb797 Tomasz Malisiewicz lots of file updates
authored
2 % Perform detection post-processing and pool detection boxes
3 % (which will then be ready to go into the PASCAL evaluation code)
de79dbc Tomasz Malisiewicz updated file
authored
4 % If there are overlap scores associated with boxes, then they are
5 % also kept track of propertly, even after NMS.
3d23807 Tomasz Malisiewicz more extreme cleanup plus finishing touches
authored
6 %
7 % If M is empty, then just NMS is performed
8 % If M has neighbor_thresh defined, then we apply the
9 % calibration-matrix
10 % If M has betas defined, then do platt-calibration
de79dbc Tomasz Malisiewicz updated file
authored
11 %
be09769 Tomasz Malisiewicz update files with license and renaming
authored
12 % Copyright (C) 2011-12 by Tomasz Malisiewicz
13 % All rights reserved.
14 %
15 % This file is part of the Exemplar-SVM library and is made
16 % available under the terms of the MIT license (see COPYING file).
063ada4 Tomasz Malisiewicz update comments
authored
17 % Project homepage: https://github.com/quantombone/exemplarsvm
de79dbc Tomasz Malisiewicz updated file
authored
18
19 %REMOVE FIRINGS ON SELF-IMAGE (these create artificially high
20 %scores when evaluating on the training set, but no need to set
21 %this on the testing set as we don't train on testing data)
22 REMOVE_SELF = 0;
23
24 if REMOVE_SELF == 1
25 curids = cellfun2(@(x)x.curid,models);
26 end
27
d57c485 Tomasz Malisiewicz more local updates
authored
28 %cls = models{1}.cls;
29 %excurids = cellfun2(@(x)x.curid,models);
de79dbc Tomasz Malisiewicz updated file
authored
30 bboxes = cell(1,length(grid));
31 maxos = cell(1,length(grid));
32
91c4d67 Tomasz Malisiewicz more local changes
authored
33 try
34 curcls = find(ismember(params.dataset_params.classes, ...
35 models{1}.cls));
36 catch
37 %dataset_params is missing
38 end
de79dbc Tomasz Malisiewicz updated file
authored
39
40 for i = 1:length(grid)
41 curid = grid{i}.curid;
42 bboxes{i} = grid{i}.bboxes;
43 if size(bboxes{i},1) == 0
44 continue
45 end
46
d57c485 Tomasz Malisiewicz more local updates
authored
47 if ~isempty(grid{i}.extras) && isfield(grid{i}.extras,'maxos')
de79dbc Tomasz Malisiewicz updated file
authored
48 maxos{i} = grid{i}.extras.maxos;
49 maxos{i}(grid{i}.extras.maxclass~=curcls) = 0;
50 end
51
52 if REMOVE_SELF == 1
53 exes = bboxes{i}(:,6);
54 excurids = curids(exes);
55 badex = find(ismember(excurids,{curid}));
56 bboxes{i}(badex,:) = [];
57
d57c485 Tomasz Malisiewicz more local updates
authored
58 if ~isempty(grid{i}.extras) && isfield(grid{i}.extras,'maxos')
59 if ~isempty(maxos{i})
de79dbc Tomasz Malisiewicz updated file
authored
60 maxos{i}(badex) = [];
61 end
62 end
63 end
64 end
65
f004280 Tomasz Malisiewicz fix calibration code bug, and revert dfun
authored
66 raw_boxes = bboxes;
67
de79dbc Tomasz Malisiewicz updated file
authored
68 %Perform score rescaling
69 %1. no scaling
70 %2. platt's calibration (sigmoid scaling)
71 %3. raw score + 1
72
d57c485 Tomasz Malisiewicz more local updates
authored
73 if (exist('M','var') && (~isempty(M)) && isfield(M,'betas') && ...
3d23807 Tomasz Malisiewicz more extreme cleanup plus finishing touches
authored
74 ~isfield(M,'neighbor_thresh'))
75
76 fprintf(1,'Applying betas to %d images:',length(bboxes));
de79dbc Tomasz Malisiewicz updated file
authored
77 for i = 1:length(bboxes)
78 %if neighbor thresh is defined, then we are in M-mode boosting
601aae7 Tomasz Malisiewicz handle no-detection images
authored
79 if size(bboxes{i},1) == 0
80 continue
81 end
8bc60ae Tomasz Malisiewicz renamed more functions
authored
82 calib_boxes = esvm_calibrate_boxes(bboxes{i},M.betas);
f004280 Tomasz Malisiewicz fix calibration code bug, and revert dfun
authored
83 oks = find(calib_boxes(:,end) > params.calibration_threshold);
de79dbc Tomasz Malisiewicz updated file
authored
84 calib_boxes = calib_boxes(oks,:);
85 bboxes{i} = calib_boxes;
86 end
d57c485 Tomasz Malisiewicz more local updates
authored
87 elseif exist('M','var') && ~isempty(M) && isfield(M,'neighbor_thresh')
b334119 Tomasz Malisiewicz update names and clean outputs
authored
88 fprintf(1,'Applying M-matrix to %d images:',length(bboxes));
89 starter=tic;
90
d57c485 Tomasz Malisiewicz more local updates
authored
91 nbrlist = cell(length(bboxes),1);
de79dbc Tomasz Malisiewicz updated file
authored
92 for i = 1:length(bboxes)
93 fprintf(1,'.');
601aae7 Tomasz Malisiewicz handle no-detection images
authored
94 if size(bboxes{i},1) == 0
95 continue
96 end
3d23807 Tomasz Malisiewicz more extreme cleanup plus finishing touches
authored
97
98 bboxes{i}(:,end) = bboxes{i}(:,end)+1;
99
8bc60ae Tomasz Malisiewicz renamed more functions
authored
100 [xraw,nbrlist{i}] = esvm_get_M_features(bboxes{i},length(models), ...
101 M.neighbor_thresh);
be09769 Tomasz Malisiewicz update files with license and renaming
authored
102 r2 = esvm_apply_M(xraw,bboxes{i},M);
de79dbc Tomasz Malisiewicz updated file
authored
103 bboxes{i}(:,end) = r2;
104 end
b334119 Tomasz Malisiewicz update names and clean outputs
authored
105 fprintf(1,'took %.3fsec\n',toc(starter));
3d23807 Tomasz Malisiewicz more extreme cleanup plus finishing touches
authored
106 else
107 fprintf(1,'No betas, No M-matrix, no calibration\n');
de79dbc Tomasz Malisiewicz updated file
authored
108 end
109
3d23807 Tomasz Malisiewicz more extreme cleanup plus finishing touches
authored
110
de79dbc Tomasz Malisiewicz updated file
authored
111 os_thresh = .3;
b334119 Tomasz Malisiewicz update names and clean outputs
authored
112 fprintf(1, 'Applying NMS (OS thresh=%.3f)\n',os_thresh);
de79dbc Tomasz Malisiewicz updated file
authored
113 for i = 1:length(bboxes)
114 if size(bboxes{i},1) > 0
115 bboxes{i}(:,5) = 1:size(bboxes{i},1);
f5ff12b Tomasz Malisiewicz renamed nms to esvm_nms to prevent clash with pedro
authored
116 bboxes{i} = esvm_nms(bboxes{i},os_thresh);
d57c485 Tomasz Malisiewicz more local updates
authored
117 if ~isempty(grid{i}.extras) && isfield(grid{i}.extras,'maxos')
de79dbc Tomasz Malisiewicz updated file
authored
118 maxos{i} = maxos{i}(bboxes{i}(:,5));
119 end
120 if exist('nbrlist','var')
121 nbrlist{i} = nbrlist{i}(bboxes{i}(:,5));
122 end
123 bboxes{i}(:,5) = 1:size(bboxes{i},1);
124 end
125 end
126
f76db0c make pooling detections an option, disabled by default
Tomasz J Malisiewicz authored
127 if params.calibration_propagate_onto_raw && ...
128 exist('M','var') && length(M)>0 && isfield(M,'betas')
b6fd1e5 Tomasz Malisiewicz minor fixes
authored
129 fprintf(1,'Propagating scores onto raw detections\n');
130 %% propagate scores onto raw boxes
131 for i = 1:length(bboxes)
f48e4d5 Tomasz Malisiewicz add tutorial images
authored
132 if size(bboxes{i},1) > 0
133 allMscores = bboxes{i}(:,end);
8bc60ae Tomasz Malisiewicz renamed more functions
authored
134 calib_boxes = esvm_calibrate_boxes(raw_boxes{i},M.betas);
f48e4d5 Tomasz Malisiewicz add tutorial images
authored
135 beta_scores = calib_boxes(:,end);
136
137 osmat = getosmatrix_bb(bboxes{i},raw_boxes{i});
138 for j = 1:size(osmat,1)
139 curscores = (osmat(j,:)>.5) .* beta_scores';
140 [aa,bb] = max(curscores);
141 bboxes{i}(j,:) = raw_boxes{i}(bb,:);
142 bboxes{i}(j,end) = aa;
143 end
144 bboxes{i}(:,end) = allMscores;
145
146 % new_scores = beta_scores;
147 % for j = 1:length(nbrlist{i})
148 % new_scores(nbrlist{i}{j}) = max(new_scores(nbrlist{i}{j}),...
149 % beta_scores(nbrlist{i}{j}).*...
150 % bboxes{i}(nbrlist{i}{j},end));
151 % end
152 % bboxes{i}(:,end) = new_scores;
b6fd1e5 Tomasz Malisiewicz minor fixes
authored
153 end
154 end
155 end
de79dbc Tomasz Malisiewicz updated file
authored
156
157 % Clip boxes to image dimensions since VOC testing annotation
158 % always fall within the image
159 unclipped_boxes = bboxes;
160 for i = 1:length(bboxes)
161 bboxes{i} = clip_to_image(bboxes{i},grid{i}.imbb);
162 end
163
164 final_boxes = bboxes;
165
166 % return unclipped boxes for transfers
167 final.unclipped_boxes = unclipped_boxes;
168 final.final_boxes = final_boxes;
169 final.final_maxos = maxos;
170
171 %Create a string which summarizes the pooling type
172 calib_string = '';
d57c485 Tomasz Malisiewicz more local updates
authored
173 if exist('M','var') && ~isempty(M) && isfield(M,'betas')
de79dbc Tomasz Malisiewicz updated file
authored
174 calib_string = '-calibrated';
175 end
176
d57c485 Tomasz Malisiewicz more local updates
authored
177 if exist('M','var') && ~isempty(M) && isfield(M,'betas') && isfield(M,'w')
de79dbc Tomasz Malisiewicz updated file
authored
178 calib_string = [calib_string '-M'];
179 end
180
181 final.calib_string = calib_string;
182
183 %NOTE: is this necessary anymore?
184 final.imbb = cellfun2(@(x)x.imbb,grid);
Something went wrong with that request. Please try again.