-
Notifications
You must be signed in to change notification settings - Fork 54
/
imagelist_to_det.m
78 lines (59 loc) · 2.07 KB
/
imagelist_to_det.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
function imagelist_to_det(imnames, imgdir, mcgdir, ovoutdir, sptextdir, regspimgdir, featdir, scorefile,topk, VOCopts)
%%%%%%
%MCG
%%%%%%
fprintf('Computing MCG. Note that this can be parallelized\n');
if(~exist(mcgdir, 'file')) mkdir(mcgdir); end
for i=1:numel(imnames)
fprintf('MCG : %d/%d\n', i, numel(imnames));
imname=imnames{i};
imgfile=fullfile(imgdir, [imname '.jpg']);
img=imread(imgfile);
candidates_file=fullfile(mcgdir,[imname '.mat']);
if(~exist(candidates_file))
candidates=im2mcg(img, 'accurate');
save(candidates_file, 'candidates');
end
end
%%%%%%%%%%%
%Preprocess
%%%%%%%%%%%
fprintf('Preprocessing candidates.\n');
[region_meta_info]=preprocess_mcg_candidates(imnames, mcgdir, [], ovoutdir, sptextdir, regspimgdir, 2000);
%%%%%%%%%%%%%
%Load network
%%%%%%%%%%%%%
model_def_file='prototxts/pinetwork_extract_fc7.prototxt';
model_file='sds_pretrained_models/nets/C';
assert(exist(model_def_file, 'file')>0);
assert(exist(model_file, 'file')>0);
rcnn_model=rcnn_create_model(model_def_file,model_file);
rcnn_model=rcnn_load_model(rcnn_model);
%%%%%%%%%%%%%%%%%
%Extract features
%%%%%%%%%%%%%%%%%
fprintf('Saving features..\n');
save_features(imnames, imgdir, sptextdir, regspimgdir, featdir, rcnn_model);
%%%%%%%%%%%%%%%%%
%Score candidates
%%%%%%%%%%%%%%%%%
fprintf('Scoring using SVMs..\n');
svmfile='sds_pretrained_models/svms_box/C.mat';
tmp=load(svmfile);
scores=test_svms(tmp.models, imnames,featdir);
%%%%%%%%%%%%%%%%%%
%NMS and pick top
%%%%%%%%%%%%%%%%%%
fprintf('Picking top detections\n');
[chosen, chosenscores]=box_nms(imnames, scores, region_meta_info, 20);
%keep only topk per category
[topchosen, topscores]=get_top_regions(chosen, chosenscores, region_meta_info.box_overlaps, topk);
save(scorefile, 'scores', 'topchosen', 'topscores');
%%%%%%%%%%%%%%%%%%%%%%%%
%Write detections
%%%%%%%%%%%%%%%%%%%%%%%
if(~exist(VOCopts.resdir, 'file'))
mkdir(VOCopts.resdir);
mkdir(fullfile(VOCopts.resdir, 'Main'));
end
write_test_boxes(imnames, VOCopts.detrespath, 'comp4',region_meta_info, topchosen, topscores);