Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 477 lines (383 sloc) 12.62 kB
3bb008c @quantombone more minor cleanups
quantombone authored
1 function [resstruct,feat_pyramid] = esvm_detect(I, models, params)
be09769 @quantombone update files with license and renaming
quantombone authored
2 % Localize a set of models in an image.
3bb008c @quantombone more minor cleanups
quantombone authored
3 % function [resstruct,feat_pyramid] = esvm_detect(I, models, params)
be09769 @quantombone update files with license and renaming
quantombone authored
4 %
5 % If there is a small number of models (such as in per-exemplar
6 % mining), then fconvblas is used for detection. If the number is
7 % large, then the BLOCK feature matrix method (with a single matrix
8 % multiplication) is used.
7b27734 @quantombone fixed ind bug
quantombone authored
9 %
063ada4 @quantombone update comments
quantombone authored
10 % NOTE: These local detections can be pooled with esvm_pool_exemplars_dets.m
11 %
eea2ad9 @quantombone Restructured Data types
quantombone authored
12 % I: Input image (or already precomputed pyramid)
13 % models: A cell array of models to localize inside this image
14 % models{:}.model.w: Learned template
15 % models{:}.model.b: Learned template's offset
3bb008c @quantombone more minor cleanups
quantombone authored
16 % params: Localization parameters (see esvm_get_default_params.m)
eea2ad9 @quantombone Restructured Data types
quantombone authored
17 %
18 % resstruct: Sliding window output struct with
19 % resstruct.bbs{:}: Detection boxes and pyramid locations
20 % resstruct.xs{:}: Detection features
d57c485 @quantombone more local updates
quantombone authored
21 % feat_pyramid: The Feature pyramid output
7b27734 @quantombone fixed ind bug
quantombone authored
22 %
be09769 @quantombone update files with license and renaming
quantombone authored
23 % Copyright (C) 2011-12 by Tomasz Malisiewicz
24 % All rights reserved.
25 %
26 % This file is part of the Exemplar-SVM library and is made
27 % available under the terms of the MIT license (see COPYING file).
063ada4 @quantombone update comments
quantombone authored
28 % Project homepage: https://github.com/quantombone/exemplarsvm
9d6ec0c @quantombone fixed some information
quantombone authored
29
d57c485 @quantombone more local updates
quantombone authored
30 if isempty(models)
3bb008c @quantombone more minor cleanups
quantombone authored
31 fprintf(1,'Warning: empty models in esvm_detect\n');
8048653 @quantombone return nothing if no models are given as input
quantombone authored
32 resstruct.bbs{1} = zeros(0,0);
33 resstruct.xs{1} = zeros(0,0);
81a5789 @quantombone change prototype
quantombone authored
34 feat_pyramid = [];
8048653 @quantombone return nothing if no models are given as input
quantombone authored
35 return;
36 end
37
ef94b3d @quantombone remove verbose output, and handle a non-cell array as input
quantombone authored
38 if ~iscell(models)
39 models = {models};
40 end
41
5f0b7b9 @quantombone Fix bug when params are specified, they should overwrite the models'
quantombone authored
42 if isfield(models{1},'mining_params') && ~exist('params','var')
728304c @quantombone use built in params if they exist
quantombone authored
43 params = models{1}.mining_params;
44 elseif ~exist('params','var')
063ada4 @quantombone update comments
quantombone authored
45 params = esvm_get_default_params;
d7a3db8 @quantombone minor cleanup
quantombone authored
46 end
47
3bb008c @quantombone more minor cleanups
quantombone authored
48 if ~isfield(params,'nnmode')
49 params.nnmode = '';
75017d6 @quantombone update saving conventions
quantombone authored
50 end
51
3bb008c @quantombone more minor cleanups
quantombone authored
52 doflip = params.detect_add_flip;
8cab4fd changed
Tomasz Malisiewcz authored
53
3bb008c @quantombone more minor cleanups
quantombone authored
54 params.detect_add_flip = 0;
55 [rs1, t1] = esvm_detectdriver(I, models, params);
56 rs1 = prune_nms(rs1, params);
768d80a @quantombone add block-based localizer
quantombone authored
57
2413eb9 @quantombone newest fixes
quantombone authored
58 if doflip == 1
3bb008c @quantombone more minor cleanups
quantombone authored
59 params.detect_add_flip = 1;
60 [rs2, t2] = esvm_detectdriver(I, models, params);
61 rs2 = prune_nms(rs2, params);
eea2ad9 @quantombone Restructured Data types
quantombone authored
62 else %If there is no flip, then we are done
2413eb9 @quantombone newest fixes
quantombone authored
63 resstruct = rs1;
81a5789 @quantombone change prototype
quantombone authored
64 feat_pyramid = t1;
2413eb9 @quantombone newest fixes
quantombone authored
65 return;
66 end
8cab4fd changed
Tomasz Malisiewcz authored
67
eea2ad9 @quantombone Restructured Data types
quantombone authored
68 %If we got here, then the flip was turned on and we need to concatenate
69 %results
70 for q = 1:length(rs1.bbs)
ff88b01 @quantombone more rearranging
quantombone authored
71 rs1.xs{q} = cat(2,rs1.xs{q}, ...
72 rs2.xs{q});
768d80a @quantombone add block-based localizer
quantombone authored
73
eea2ad9 @quantombone Restructured Data types
quantombone authored
74
75 rs1.bbs{q} = cat(1,rs1.bbs{q},rs2.bbs{q});
8cab4fd changed
Tomasz Malisiewcz authored
76 end
77
78 resstruct = rs1;
eea2ad9 @quantombone Restructured Data types
quantombone authored
79
80 %Concatenate normal and LR pyramids
81a5789 @quantombone change prototype
quantombone authored
81 feat_pyramid = cat(1,t1,t2);
8cab4fd changed
Tomasz Malisiewcz authored
82
81a5789 @quantombone change prototype
quantombone authored
83 function [resstruct,t] = esvm_detectdriver(I, models, ...
3bb008c @quantombone more minor cleanups
quantombone authored
84 params)
755fc7a @quantombone move files and renamed directories
quantombone authored
85 if ~isfield(params,'max_models_before_block_method')
86 params.max_models_before_block_method = 20;
87 end
3bb008c @quantombone more minor cleanups
quantombone authored
88
89 if (length(models) > params.max_models_before_block_method) ...
90 || (~isempty(params.nnmode))
768d80a @quantombone add block-based localizer
quantombone authored
91
81a5789 @quantombone change prototype
quantombone authored
92 [resstruct,t] = esvm_detectdriverBLOCK(I, models, ...
3bb008c @quantombone more minor cleanups
quantombone authored
93 params);
768d80a @quantombone add block-based localizer
quantombone authored
94 return;
95 end
c427846 @quantombone only do new matching for more than 40 exemplars
quantombone authored
96
8cab4fd changed
Tomasz Malisiewcz authored
97 N = length(models);
98 ws = cellfun2(@(x)x.model.w,models);
99 bs = cellfun2(@(x)x.model.b,models);
100
101 %NOTE: all exemplars in this set must have the same sbin
3bb008c @quantombone more minor cleanups
quantombone authored
102 luq = 1;
103
104 if isfield(models{1}.model,'init_params')
105 sbins = cellfun(@(x)x.model.init_params.sbin,models);
106 luq = length(unique(sbins));
107 end
108
109 if isfield(models{1}.model,'init_params') && luq == 1
110 sbin = models{1}.model.init_params.sbin;
111 elseif ~isfield(models{1}.model,'init_params')
112 if isfield(params,'init_params')
113 sbin = params.init_params.sbin;
114 else
115 fprintf(1,'No hint for sbin!\n');
116 error('No sbin provided');
117 end
118
119 else
120 fprintf(1,['Warning: not all exemplars have save sbin, using' ...
121 ' first]\n']);
122 sbin = models{1}.model.init_params.sbin;
123 end
124
125
126
127 t = get_pyramid(I, sbin, params);
8cab4fd changed
Tomasz Malisiewcz authored
128
eea2ad9 @quantombone Restructured Data types
quantombone authored
129 resstruct.padder = t.padder;
130 resstruct.bbs = cell(N,1);
131 xs = cell(N,1);
8cab4fd changed
Tomasz Malisiewcz authored
132
eea2ad9 @quantombone Restructured Data types
quantombone authored
133 maxers = cell(N,1);
8cab4fd changed
Tomasz Malisiewcz authored
134 for q = 1:N
9e6277c @quantombone fixed up the files
quantombone authored
135 maxers{q} = -inf;
8cab4fd changed
Tomasz Malisiewcz authored
136 end
137
bbd90dd @quantombone add spaces
quantombone authored
138
3bb008c @quantombone more minor cleanups
quantombone authored
139 if params.dfun == 1
336515c @quantombone handle both dfun and normal mode
quantombone authored
140 wxs = cellfun2(@(x)reshape(x.model.x(:,1),size(x.model.w)), ...
141 models);
142 ws2 = ws;
d57c485 @quantombone more local updates
quantombone authored
143 special_offset = zeros(length(ws2),1);
336515c @quantombone handle both dfun and normal mode
quantombone authored
144 for q = 1:length(ws2)
145 ws2{q} = -2*ws{q}.*wxs{q};
146 special_offset(q) = ws{q}(:)'*(models{q}.model.x(:,1).^2);
147 end
148 end
149
8cab4fd changed
Tomasz Malisiewcz authored
150 %start with smallest level first
151 for level = length(t.hog):-1:1
152 featr = t.hog{level};
eea2ad9 @quantombone Restructured Data types
quantombone authored
153
3bb008c @quantombone more minor cleanups
quantombone authored
154 if params.dfun == 1
336515c @quantombone handle both dfun and normal mode
quantombone authored
155 featr_squared = featr.^2;
156
157 %Use blas-based fast convolution code
158 rootmatch1 = fconvblas(featr_squared, ws, 1, N);
159 rootmatch2 = fconvblas(featr, ws2, 1, N);
160
161 for z = 1:length(rootmatch1)
162 rootmatch{z} = rootmatch1{z} + rootmatch2{z} + special_offset(z);
163 end
164
165 else
166 %Use blas-based fast convolution code
167 rootmatch = fconvblas(featr, ws, 1, N);
168 end
169
8cab4fd changed
Tomasz Malisiewcz authored
170 rmsizes = cellfun2(@(x)size(x), ...
171 rootmatch);
eea2ad9 @quantombone Restructured Data types
quantombone authored
172
8cab4fd changed
Tomasz Malisiewcz authored
173 for exid = 1:N
174 if prod(rmsizes{exid}) == 0
175 continue
176 end
177
eea2ad9 @quantombone Restructured Data types
quantombone authored
178 cur_scores = rootmatch{exid} - bs{exid};
8cab4fd changed
Tomasz Malisiewcz authored
179 [aa,indexes] = sort(cur_scores(:),'descend');
3bb008c @quantombone more minor cleanups
quantombone authored
180 NKEEP = sum((aa>maxers{exid}) & (aa>=params.detect_keep_threshold));
eea2ad9 @quantombone Restructured Data types
quantombone authored
181 aa = aa(1:NKEEP);
182 indexes = indexes(1:NKEEP);
183 if NKEEP==0
184 continue
185 end
8cab4fd changed
Tomasz Malisiewcz authored
186 sss = size(ws{exid});
187
188 [uus,vvs] = ind2sub(rmsizes{exid}(1:2),...
eea2ad9 @quantombone Restructured Data types
quantombone authored
189 indexes);
8cab4fd changed
Tomasz Malisiewcz authored
190
eea2ad9 @quantombone Restructured Data types
quantombone authored
191 scale = t.scales(level);
192
193 o = [uus vvs] - t.padder;
194
195 bbs = ([o(:,2) o(:,1) o(:,2)+size(ws{exid},2) ...
196 o(:,1)+size(ws{exid},1)] - 1) * ...
197 sbin/scale + 1 + repmat([0 0 -1 -1],length(uus),1);
198
199 bbs(:,5:12) = 0;
200 bbs(:,5) = (1:size(bbs,1));
201 bbs(:,6) = exid;
202 bbs(:,8) = scale;
203 bbs(:,9) = uus;
204 bbs(:,10) = vvs;
205 bbs(:,12) = aa;
206
3bb008c @quantombone more minor cleanups
quantombone authored
207 if (params.detect_add_flip == 1)
eea2ad9 @quantombone Restructured Data types
quantombone authored
208 bbs = flip_box(bbs,t.size);
209 bbs(:,7) = 1;
8cab4fd changed
Tomasz Malisiewcz authored
210 end
211
eea2ad9 @quantombone Restructured Data types
quantombone authored
212 resstruct.bbs{exid} = cat(1,resstruct.bbs{exid},bbs);
213
3bb008c @quantombone more minor cleanups
quantombone authored
214 if params.detect_save_features == 1
eea2ad9 @quantombone Restructured Data types
quantombone authored
215 for z = 1:NKEEP
216 xs{exid}{end+1} = ...
217 reshape(t.hog{level}(uus(z)+(1:sss(1))-1, ...
218 vvs(z)+(1:sss(2))-1,:), ...
219 [],1);
220 end
221 end
222
8cab4fd changed
Tomasz Malisiewcz authored
223 if (NKEEP > 0)
3bb008c @quantombone more minor cleanups
quantombone authored
224 newtopk = min(params.detect_max_windows_per_exemplar,size(resstruct.bbs{exid},1));
eea2ad9 @quantombone Restructured Data types
quantombone authored
225 [aa,bb] = psort(-resstruct.bbs{exid}(:,end),newtopk);
226 resstruct.bbs{exid} = resstruct.bbs{exid}(bb,:);
3bb008c @quantombone more minor cleanups
quantombone authored
227 if params.detect_save_features == 1
eea2ad9 @quantombone Restructured Data types
quantombone authored
228 xs{exid} = xs{exid}(:,bb);
8cab4fd changed
Tomasz Malisiewcz authored
229 end
e97a6d2 @quantombone fix a bug when loading SVs
quantombone authored
230 %TJM: changed so that we only maintain 'maxers' when topk
231 %elements are filled
3bb008c @quantombone more minor cleanups
quantombone authored
232 if (newtopk >= params.detect_max_windows_per_exemplar)
e97a6d2 @quantombone fix a bug when loading SVs
quantombone authored
233 maxers{exid} = min(-aa);
234 end
eea2ad9 @quantombone Restructured Data types
quantombone authored
235 end
8cab4fd changed
Tomasz Malisiewcz authored
236 end
237 end
238
3bb008c @quantombone more minor cleanups
quantombone authored
239 if params.detect_save_features == 1
eea2ad9 @quantombone Restructured Data types
quantombone authored
240 resstruct.xs = xs;
8cab4fd changed
Tomasz Malisiewcz authored
241 else
eea2ad9 @quantombone Restructured Data types
quantombone authored
242 resstruct.xs = cell(N,1);
8cab4fd changed
Tomasz Malisiewcz authored
243 end
ef94b3d @quantombone remove verbose output, and handle a non-cell array as input
quantombone authored
244 %fprintf(1,'\n');
4e1e750 @quantombone most recent changes
quantombone authored
245
81a5789 @quantombone change prototype
quantombone authored
246 function [resstruct,t] = esvm_detectdriverBLOCK(I, models, ...
3bb008c @quantombone more minor cleanups
quantombone authored
247 params)
768d80a @quantombone add block-based localizer
quantombone authored
248
75017d6 @quantombone update saving conventions
quantombone authored
249 %%HERE is the chunk version of exemplar localization
768d80a @quantombone add block-based localizer
quantombone authored
250
251 N = length(models);
252 ws = cellfun2(@(x)x.model.w,models);
eea2ad9 @quantombone Restructured Data types
quantombone authored
253 bs = cellfun(@(x)x.model.b,models)';
314fc9f @quantombone reshape the b-vector because it is different on different implementat…
quantombone authored
254 bs = reshape(bs,[],1);
768d80a @quantombone add block-based localizer
quantombone authored
255 sizes1 = cellfun(@(x)x.model.hg_size(1),models);
256 sizes2 = cellfun(@(x)x.model.hg_size(2),models);
257
258 S = [max(sizes1(:)) max(sizes2(:))];
0ffe88d @quantombone update function names again
quantombone authored
259 fsize = params.init_params.features();
260 templates = zeros(S(1),S(2),fsize,length(models));
261 templates_x = zeros(S(1),S(2),fsize,length(models));
262 template_masks = zeros(S(1),S(2),fsize,length(models));
768d80a @quantombone add block-based localizer
quantombone authored
263
264 for i = 1:length(models)
0ffe88d @quantombone update function names again
quantombone authored
265 t = zeros(S(1),S(2),fsize);
768d80a @quantombone add block-based localizer
quantombone authored
266 t(1:models{i}.model.hg_size(1),1:models{i}.model.hg_size(2),:) = ...
267 models{i}.model.w;
9f3c26d @quantombone fix a displaying bug and such
quantombone authored
268
768d80a @quantombone add block-based localizer
quantombone authored
269 templates(:,:,:,i) = t;
0ffe88d @quantombone update function names again
quantombone authored
270 template_masks(:,:,:,i) = repmat(double(sum(t.^2,3)>0),[1 1 fsize]);
9f3c26d @quantombone fix a displaying bug and such
quantombone authored
271
3bb008c @quantombone more minor cleanups
quantombone authored
272 if (~isempty(params.nnmode)) || ...
273 (isfield(params,'wtype') && ...
274 strcmp(params.wtype,'dfun')==1)
0ffe88d @quantombone update function names again
quantombone authored
275 x = zeros(S(1),S(2),fsize);
9f3c26d @quantombone fix a displaying bug and such
quantombone authored
276 x(1:models{i}.model.hg_size(1),1:models{i}.model.hg_size(2),:) = ...
277 reshape(models{i}.model.x(:,1),models{i}.model.hg_size);
278 templates_x(:,:,:,i) = x;
bbd90dd @quantombone add spaces
quantombone authored
279
9f3c26d @quantombone fix a displaying bug and such
quantombone authored
280 end
768d80a @quantombone add block-based localizer
quantombone authored
281 end
282
0ffe88d @quantombone update function names again
quantombone authored
283 %maskmat = repmat(template_masks,[1 1 1 fsize]);
54a7969 @quantombone fixed those NNs!
quantombone authored
284 %maskmat = permute(maskmat,[1 2 4 3]);
285 %templates_x = templates_x .* maskmat;
286
8957af1 @quantombone newest updates make the interface much nicer
quantombone authored
287 sbin = models{1}.model.init_params.sbin;
3bb008c @quantombone more minor cleanups
quantombone authored
288 t = get_pyramid(I, sbin, params);
eea2ad9 @quantombone Restructured Data types
quantombone authored
289 resstruct.padder = t.padder;
768d80a @quantombone add block-based localizer
quantombone authored
290
d9419aa @quantombone fix finalf being too large bug
quantombone authored
291 pyr_N = cellfun(@(x)prod([size(x,1) size(x,2)]-S+1),t.hog);
292 sumN = sum(pyr_N);
293
0ffe88d @quantombone update function names again
quantombone authored
294 X = zeros(S(1)*S(2)*fsize,sumN);
768d80a @quantombone add block-based localizer
quantombone authored
295 offsets = cell(length(t.hog), 1);
eea2ad9 @quantombone Restructured Data types
quantombone authored
296 uus = cell(length(t.hog),1);
297 vvs = cell(length(t.hog),1);
768d80a @quantombone add block-based localizer
quantombone authored
298
d9419aa @quantombone fix finalf being too large bug
quantombone authored
299 counter = 1;
768d80a @quantombone add block-based localizer
quantombone authored
300 for i = 1:length(t.hog)
301 s = size(t.hog{i});
302 NW = s(1)*s(2);
303 ppp = reshape(1:NW,s(1),s(2));
0ffe88d @quantombone update function names again
quantombone authored
304 curf = reshape(t.hog{i},[],fsize);
768d80a @quantombone add block-based localizer
quantombone authored
305 b = im2col(ppp,[S(1) S(2)]);
d9419aa @quantombone fix finalf being too large bug
quantombone authored
306
768d80a @quantombone add block-based localizer
quantombone authored
307 offsets{i} = b(1,:);
308 offsets{i}(end+1,:) = i;
309
310 for j = 1:size(b,2)
3bb008c @quantombone more minor cleanups
quantombone authored
311 X(:,counter) = reshape (curf(b(:,j),:),[],1);
312 counter = counter + 1;
768d80a @quantombone add block-based localizer
quantombone authored
313 end
7b27734 @quantombone fixed ind bug
quantombone authored
314
315 [uus{i},vvs{i}] = ind2sub(s,offsets{i}(1,:));
768d80a @quantombone add block-based localizer
quantombone authored
316 end
317
318 offsets = cat(2,offsets{:});
319
7b27734 @quantombone fixed ind bug
quantombone authored
320 uus = cat(2,uus{:});
321 vvs = cat(2,vvs{:});
322
0ffe88d @quantombone update function names again
quantombone authored
323 % m.model.w = zeros(S(1),S(2),fsize);
3bb008c @quantombone more minor cleanups
quantombone authored
324 % m.model.b = 0;
325 % temp_params = params;
326 % temp_params.detect_save_features = 1;
327 % temp_params.detect_exemplar_nms_os_threshold = 1.0;
328 % temp_params.max_models_before_block_method = 1;
329 % temp_params.detect_max_windows_per_exemplar = 28000;
330
331 % [rs] = esvm_detect(I, {m}, temp_params);
332 % X2=cat(2,rs.xs{1}{:});
333 % bbs2 = rs.bbs{1};
334
335
2bfba90 @quantombone allow for the NN-flag, which indicates what kind of nn-computation we
quantombone authored
336 exemplar_matrix = reshape(templates,[],size(templates,4));
768d80a @quantombone add block-based localizer
quantombone authored
337
3bb008c @quantombone more minor cleanups
quantombone authored
338 if isfield(params,'wtype') && ...
339 strcmp(params.wtype,'dfun')==1
336515c @quantombone handle both dfun and normal mode
quantombone authored
340 W = exemplar_matrix;
341 U = reshape(templates_x,[],length(models));
342 r2 = repmat(sum(W.*(U.^2),1)',1,size(X,2));
343 r = (W'*(X.^2) - 2*(W.*U)'*X + r2);
344 r = bsxfun(@minus, r, bs);
3bb008c @quantombone more minor cleanups
quantombone authored
345 elseif isempty(params.nnmode)
2bfba90 @quantombone allow for the NN-flag, which indicates what kind of nn-computation we
quantombone authored
346 %nnmode 0: Apply linear classifiers by performing one large matrix
347 %multiplication and subtract bias
336515c @quantombone handle both dfun and normal mode
quantombone authored
348 r = exemplar_matrix' * X;
2bfba90 @quantombone allow for the NN-flag, which indicates what kind of nn-computation we
quantombone authored
349 r = bsxfun(@minus, r, bs);
3bb008c @quantombone more minor cleanups
quantombone authored
350 elseif strcmp(params.nnmode,'normalizedhog') == 1
336515c @quantombone handle both dfun and normal mode
quantombone authored
351 r = exemplar_matrix' * X;
3bb008c @quantombone more minor cleanups
quantombone authored
352 elseif strcmp(params.nnmode,'nndfun') == 1
336515c @quantombone handle both dfun and normal mode
quantombone authored
353 %Do euclidean distance (but only over the regions corresponding
354 %to the in-mask (non-padded) regions
355 W = reshape(template_masks,[],length(models));
356 W = W / 100;
357 U = reshape(templates_x,[],length(models));
358 r2 = repmat(sum(W.*(U.^2),1)',1,size(X,2));
359 r = - (W'*(X.^2) - 2*(W.*U)'*X + r2);
2bfba90 @quantombone allow for the NN-flag, which indicates what kind of nn-computation we
quantombone authored
360 else
3bb008c @quantombone more minor cleanups
quantombone authored
361 error('invalid nnmode=%s\n',params.nnmode);
2bfba90 @quantombone allow for the NN-flag, which indicates what kind of nn-computation we
quantombone authored
362 end
eea2ad9 @quantombone Restructured Data types
quantombone authored
363
364 resstruct.bbs = cell(N,1);
365 resstruct.xs = cell(N,1);
768d80a @quantombone add block-based localizer
quantombone authored
366
367 for exid = 1:N
368
3bb008c @quantombone more minor cleanups
quantombone authored
369 goods = find(r(exid,:) >= params.detect_keep_threshold);
7b27734 @quantombone fixed ind bug
quantombone authored
370
eea2ad9 @quantombone Restructured Data types
quantombone authored
371 if isempty(goods)
372 continue
373 end
374
5904e72 @quantombone update several mining flags
quantombone authored
375 [sorted_scores,bb] = ...
376 psort(-r(exid,goods)',...
3bb008c @quantombone more minor cleanups
quantombone authored
377 min(params.detect_max_windows_per_exemplar, ...
5904e72 @quantombone update several mining flags
quantombone authored
378 length(goods)));
eea2ad9 @quantombone Restructured Data types
quantombone authored
379 bb = goods(bb);
768d80a @quantombone add block-based localizer
quantombone authored
380
eea2ad9 @quantombone Restructured Data types
quantombone authored
381 sorted_scores = -sorted_scores';
768d80a @quantombone add block-based localizer
quantombone authored
382
336515c @quantombone handle both dfun and normal mode
quantombone authored
383 resstruct.xs{exid} = X(:,bb);
eea2ad9 @quantombone Restructured Data types
quantombone authored
384
385 levels = offsets(2,bb);
386 scales = t.scales(levels);
387 curuus = uus(bb);
388 curvvs = vvs(bb);
389 o = [curuus' curvvs'] - t.padder;
390
391 bbs = ([o(:,2) o(:,1) o(:,2)+size(ws{exid},2) ...
392 o(:,1)+size(ws{exid},1)] - 1) .* ...
393 repmat(sbin./scales',1,4) + 1 + repmat([0 0 -1 ...
394 -1],length(scales),1);
395
396 bbs(:,5:12) = 0;
397 bbs(:,5) = (1:size(bbs,1));
398 bbs(:,6) = exid;
399 bbs(:,8) = scales;
400 bbs(:,9) = uus(bb);
401 bbs(:,10) = vvs(bb);
402 bbs(:,12) = sorted_scores;
403
3bb008c @quantombone more minor cleanups
quantombone authored
404 if (params.detect_add_flip == 1)
eea2ad9 @quantombone Restructured Data types
quantombone authored
405 bbs = flip_box(bbs,t.size);
406 bbs(:,7) = 1;
768d80a @quantombone add block-based localizer
quantombone authored
407 end
eea2ad9 @quantombone Restructured Data types
quantombone authored
408
409 resstruct.bbs{exid} = bbs;
768d80a @quantombone add block-based localizer
quantombone authored
410 end
411
3bb008c @quantombone more minor cleanups
quantombone authored
412
413 if params.detect_save_features == 0
eea2ad9 @quantombone Restructured Data types
quantombone authored
414 resstruct.xs = cell(N,1);
768d80a @quantombone add block-based localizer
quantombone authored
415 end
44d239a @quantombone remove endline for pruned verbosity level
quantombone authored
416 %fprintf(1,'\n');
768d80a @quantombone add block-based localizer
quantombone authored
417
eea2ad9 @quantombone Restructured Data types
quantombone authored
418 function rs = prune_nms(rs, params)
419 %Prune via nms to eliminate redundant detections
420
421 %If the field is missing, or it is set to 1, then we don't need to
ddbb13d @quantombone recent changes
quantombone authored
422 %process anything. If it is zero, we also don't do NMS.
ffbd92e @quantombone update parameter names
quantombone authored
423 if ~isfield(params,'detect_exemplar_nms_os_threshold') || (params.detect_exemplar_nms_os_threshold >= 1) ...
424 || (params.detect_exemplar_nms_os_threshold == 0)
eea2ad9 @quantombone Restructured Data types
quantombone authored
425 return;
426 end
427
f5ff12b @quantombone renamed nms to esvm_nms to prevent clash with pedro
quantombone authored
428 rs.bbs = cellfun2(@(x)esvm_nms(x,params.detect_exemplar_nms_os_threshold),rs.bbs);
eea2ad9 @quantombone Restructured Data types
quantombone authored
429
430 if ~isempty(rs.xs)
431 for i = 1:length(rs.bbs)
432 if ~isempty(rs.xs{i})
433 %NOTE: the fifth field must contain elements
434 rs.xs{i} = rs.xs{i}(:,rs.bbs{i}(:,5) );
435 end
768d80a @quantombone add block-based localizer
quantombone authored
436 end
437 end
438
3bb008c @quantombone more minor cleanups
quantombone authored
439 function t = get_pyramid(I, sbin, params)
eea2ad9 @quantombone Restructured Data types
quantombone authored
440 %Extract feature pyramid from variable I (which could be either an image,
441 %or already a feature pyramid)
442
443 if isnumeric(I)
3bb008c @quantombone more minor cleanups
quantombone authored
444 if (params.detect_add_flip == 1)
eea2ad9 @quantombone Restructured Data types
quantombone authored
445 I = flip_image(I);
446 else
447 %take unadulterated "aka" un-flipped image
448 end
449
450 clear t
451 t.size = size(I);
7b27734 @quantombone fixed ind bug
quantombone authored
452
eea2ad9 @quantombone Restructured Data types
quantombone authored
453 %Compute pyramid
8bc60ae @quantombone renamed more functions
quantombone authored
454 [t.hog, t.scales] = esvm_pyramid(I, params);
3bb008c @quantombone more minor cleanups
quantombone authored
455 t.padder = params.detect_pyramid_padding;
eea2ad9 @quantombone Restructured Data types
quantombone authored
456 for level = 1:length(t.hog)
457 t.hog{level} = padarray(t.hog{level}, [t.padder t.padder 0], 0);
458 end
459
460 minsizes = cellfun(@(x)min([size(x,1) size(x,2)]), t.hog);
461 t.hog = t.hog(minsizes >= t.padder*2);
d57c485 @quantombone more local updates
quantombone authored
462 t.scales = t.scales(minsizes >= t.padder*2);
eea2ad9 @quantombone Restructured Data types
quantombone authored
463 else
464 fprintf(1,'Already found features\n');
465
466 if iscell(I)
3bb008c @quantombone more minor cleanups
quantombone authored
467 if params.detect_add_flip==1
eea2ad9 @quantombone Restructured Data types
quantombone authored
468 t = I{2};
469 else
470 t = I{1};
471 end
472 else
473 t = I;
474 end
475 end
2bfba90 @quantombone allow for the NN-flag, which indicates what kind of nn-computation we
quantombone authored
476
Something went wrong with that request. Please try again.