-
Notifications
You must be signed in to change notification settings - Fork 155
/
esvm_show_top_dets.m
264 lines (210 loc) · 6.84 KB
/
esvm_show_top_dets.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
function allbbs = esvm_show_top_dets(test_struct, grid, ...
test_set, models, params, ...
maxk, set_name)
% Show maxk top detections for [models] where [grid] is the set of
% detections from the set [test_set], [test_struct] contains final
% boxes after pooling and calibration. If [dataset_params.localdir] is
% present, then results are saved based on naming convention into a
% "www" subfolder. maxk is the number of top detections we show
%
% NOTE: this function requires some cleanup, but is functional
%
% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
%
% This file is part of the Exemplar-SVM library and is made
% available under the terms of the MIT license (see COPYING file).
% Project homepage: https://github.com/quantombone/exemplarsvm
allbbs = [];
if length(params.dataset_params.localdir) > 0
CACHE_FILES = 1;
else
CACHE_FILES = 0;
end
if ~exist('set_name','var')
set_name = '';
end
%Default exemplar-inpainting show mode
%SHOW_MODE = 1;
%Default segmentation show mode
%SHOW_MODE = 2;
%Mode to show
%SHOW_MODE = 3;
suffix = '';
%maxk is the maximum number of top detections we display
if ~exist('maxk','var')
maxk = 20;
if strcmp(models{1}.cls,'bus')
maxk = 100;
end
end
final_boxes = test_struct.unclipped_boxes;
final_maxos = test_struct.final_maxos;
bbs = cat(1,final_boxes{:});
try
imids = bbs(:,11);
catch
imids = [];
end
moses = cat(1,final_maxos{:});
%% sort detections by score
try
[aa,bb] = sort(bbs(:,end), 'descend');
catch
aa = [];
bb = [];
end
%% only good ones now!
%bb = bb(moses(bb)>.5);
if 0
fprintf(1,'Only segmentation ones here\n');
%% get ones with segmentation only
ids = cellfun2(@(x)x.curid,models(bbs(bb,6)));
%VOCinit
has_seg = cellfun(@(x)fileexists(sprintf('%s/%s/SegmentationObject/%s.png',...
dataset_params.datadir, ...
dataset_params.dataset,x)),ids);
bb = bb(find(has_seg));
test_struct.rc = test_struct.rc(find(has_seg));
suffix = '.seg';
end
if 0
%% get ones with 3d model only
ids = cellfun2(@(x)sprintf('%s.%d.png',x.curid,x.objectid),models(bbs(bb,6)));
VOCinit
extradir = '/nfs/hn22/tmalisie/ddip/renderings/';
has_3d = cellfun(@(x)fileexists(sprintf('%s/%s.%d.chair-3d.png', ...
extradir,...
x.curid, ...
x.objectid)),models(bbs(bb,6)));
bb = bb(find(has_3d));
end
counter = 1;
for k = 1:maxk
try
corr = test_struct.rc(k);
catch
corr = 0;
end
if 1
if counter > length(bb)
break;
end
wwwdir = sprintf('%s/www/%s.%s%s/',params.dataset_params.localdir,...
set_name, ...
models{1}.models_name,test_struct.calib_string);
if ~exist(wwwdir,'dir') && (CACHE_FILES == 1)
mkdir(wwwdir);
end
filer = sprintf('%s/%05d%s.png',wwwdir,k,suffix);
filerlock = [filer '.lock'];
if CACHE_FILES && (fileexists(filer) || (mymkdir_dist(filerlock) == 0))
counter = counter + 1;
fprintf(1,'Already showed detection # %d, score=%.3f\n', k, bbs(bb(counter),end));
continue
end
fprintf(1,'Showing detection # %d, score=%.3f\n', k, bbs(bb(counter),end));
allbbs(k,:) = bbs(bb(counter),:);
curb = bb(counter);
%curid = grid{imids(curb)}.curid;
I = (convert_to_I(test_set{bbs(bb(counter),11)}));
TARGET_BUS = -1;
if TARGET_BUS > 0
gtrecs = PASreadrecord(sprintf(params.dataset_params.annopath,curid));
businds = find(ismember({gtrecs.objects.class},{'bus'}) & ~[gtrecs.objects.difficult]);
gtbbs = cat(1,gtrecs.objects.bbox);
gtbbs = gtbbs(businds,:);
else
businds = [];
end
bbox = bbs(curb,:);
if length(businds) > 0
[alpha,beta] = max(getosmatrix_bb(gtbbs,bbox));
TARGET_BUS = businds(beta);
end
if length(moses) > 0
stuff.os = moses(curb);
else
stuff.os = 0;
end
stuff.score = bbs(curb,end);
stuff.rank = counter;
extra = '';
if ismember(models{1}.models_name,{'dalal'})
extra='-dalal';
end
estring = '';
if exist('betas','var')
estring = 'withbetas';
end
%ccc = bbox(6);
%target_image_id = imids(bb(counter));
%target_cluster_id = bbs(bb(counter),5);
%USE THE RAW DETECTION
%fprintf(1,' -- Taking Final det score\n');
allbb = bbs(bb(counter),:);
%CVPR VERSION: use the top local score within a cluster
%fprintf(1,' -- Finding within-cluster local max\n');
% allbb = test_struct.raw_boxes{target_image_id};
% osmat = getosmatrix_bb(allbb,bbs(bb(counter),:));
% goods = find(osmat>.5);
% allbb = allbb(goods,:);
% [alpha,beta] = sort(allbb(:,end),'descend');
% allbb = allbb(beta,:);
sumI = I*0;
countI = zeros(size(I,1),size(I,2),1);
%ooo = cell(0,1);
%mean0 = mean(allbb,1);
%curoses = getosmatrix_bb(mean0(1,:),allbb);
stuff.I = I;
stuff.dataset_params = params.dataset_params;
clear overlays
for zzz = 1:min(1,size(allbb,1))
overlays{zzz} = esvm_exemplar_inpaint(allbb(zzz,:), ...
models{allbb(zzz,6)}, ...
stuff);
end
%sumI = sumI ./ repmat(countI,[1 1 3]);
if TARGET_BUS > -1
%% load GT for test
%gtfiles = dir(sprintf(['/nfs/baikal/tmalisie/buslabeling/' ...
% '%s*mat'],curid));
gtmat = load(sprintf(['/nfs/baikal/tmalisie/finalbuslabeling/' ...
'%s.%d.mat'], curid, TARGET_BUS));
seg = gtmat.res.seg;
gtim = esvm_faces2colors(seg);
shower = I;
test_set = repmat(double(seg~=0),[1 1 3]);
shower(find(test_set)) = shower(find(test_set))*.0 + 1.0*gtim(find(test_set));
gtim = shower;
gtim(repmat(seg==0,[1 1 3]))=0;
else
gtim = zeros(size(I,1),size(I,2));
end
figure(1)
clf
current_rank = k;
NR = esvm_show_transfer_figure(I, models, allbb, ...
overlays, current_rank, corr);
axis image
drawnow
snapnow
if CACHE_FILES == 1
%print(gcf,'-depsc2',filer);
print(gcf,'-dpng',filer);
%finalfile = strrep(filer,'.eps','.pdf');
%unix(sprintf('zsh "ps2pdf -dEPSCrop -dPDFSETTINGS=/prepress %s %s"',...
% filer,finalfile));
%if fileexists(finalfile)
% unix(sprintf('rm %s',filer));
%end
if CACHE_FILES && exist(filerlock,'dir')
rmdir(filerlock);
end
end
%filer2 = filer;
%filer2(end-2:end) = 'png';
%print(gcf,'-dpng',filer2);
counter = counter+1;
end
end