-
Notifications
You must be signed in to change notification settings - Fork 36
/
os_setup.m
164 lines (148 loc) · 5.58 KB
/
os_setup.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
function [opts, imdb] = os_setup(varargin)
global is_iasonas
if (exist('is_iasonas', 'var') ||isempty(is_iasonas) || ~is_iasonas)
setup ;
end
opts.transf = {};
opts.seed = 1 ;
opts.batchSize = 128 ;
opts.useGpu = true ;
opts.regionBorder = 0.05 ;
opts.numDCNNWords = 64 ;
opts.numDSIFTWords = 256 ;
opts.numSamplesPerWord = 1000 ;
opts.printDatasetInfo = false ;
opts.excludeDifficult = true ;
opts.encoders = {struct('type', 'rcnn', 'opts', {})} ;
opts.dataset = 'os' ;
opts.osDir = 'data/os' ;
opts.fmdDir = 'data/fmd' ;
opts.dtdDir = 'data/dtd';
opts.kthDir = 'data/kth';
opts.alotDir = 'data/alot';
opts.mitDir = 'data/mit_indoor';
opts.msrcDir = 'data/msrc_c';
opts.cubDir = 'data/cub';
opts.vocDir = 'data/VOC2007';
opts.vocDir12 = 'data/VOC2012';
opts.writeResults = false;
opts.compid = 'comp2';
opts.suffix = 'baseline' ;
opts.prefix = 'v22' ;
opts.model = 'imagenet-vgg-m.mat';
opts.layer = 13 ; % for D-CNN (R-CNN is the penultimate)
opts.segProposalType = 'crisp' ;
opts.gpuId = 1;
opts.crf = [];
[opts, varargin] = vl_argparse(opts,varargin) ;
opts.expDir = sprintf('data/%s/%s-seed-%02d', opts.prefix, opts.dataset, opts.seed) ;
opts.imdbDir = fullfile(opts.expDir, 'imdb') ;
if ~iscell(opts.suffix)
opts.resultPath = fullfile(opts.expDir, sprintf('result-%s.mat', opts.suffix)) ;
opts.segResultPath = fullfile(opts.expDir, sprintf('%s/result-%s-seg.mat', opts.segProposalType, opts.suffix)) ;
opts.segPublishDir = fullfile(opts.expDir, sprintf('%s/result-%s-seg-figures', opts.segProposalType, opts.suffix)) ;
vl_xmkdir(opts.segPublishDir);
if opts.writeResults
opts.vocResultPath = fullfile(opts.expDir, [sprintf('result-%s/Main/%s_cls_', opts.suffix, opts.compid) '%s_%s.txt']);
end
else
for s = 1:numel(opts.suffix)
opts.resultPath{s} = fullfile(opts.expDir, sprintf('result-%s.mat', opts.suffix{s})) ;
opts.segResultPath{s} = fullfile(opts.expDir, sprintf('%s/result-%s-seg.mat', opts.segProposalType, opts.suffix{s})) ;
opts.segPublishDir{s} = fullfile(opts.expDir, sprintf('%s/result-%s-seg-figures', opts.segProposalType, opts.suffix{s})) ;
vl_xmkdir(opts.segPublishDir{s});
end
end
opts = vl_argparse(opts,varargin) ;
if nargout <= 1, return ; end
% Setup GPU if needed
if opts.useGpu
gpuDevice(opts.gpuId) ;
end
% -------------------------------------------------------------------------
% Setup encoders
% -------------------------------------------------------------------------
models = {} ;
for i = 1:numel(opts.encoders)
if isstruct(opts.encoders{i})
name = opts.encoders{i}.name ;
opts.encoders{i}.path = fullfile(opts.expDir, [name '-encoder.mat']) ;
opts.encoders{i}.codePath = fullfile(opts.expDir, [name '-codes.mat']) ;
models = horzcat(models, get_cnn_model_from_encoder_opts(opts.encoders{i})) ;
else
for j = 1:numel(opts.encoders{i})
name = opts.encoders{i}{j}.name ;
opts.encoders{i}{j}.path = fullfile(opts.expDir, [name '-encoder.mat']) ;
opts.encoders{i}{j}.codePath = fullfile(opts.expDir, [name '-codes.mat']) ;
models = horzcat(models, get_cnn_model_from_encoder_opts(opts.encoders{i}{j})) ;
end
end
end
% -------------------------------------------------------------------------
% Download CNN models
% -------------------------------------------------------------------------
for i = 1:numel(models)
crt_model_path = fullfile('data/models', models{i});
vl_xmkdir('data/models');
if ~exist(crt_model_path, 'file')
fprintf('downloading model %s\n', models{i});
urlwrite(fullfile('http://www.vlfeat.org/matconvnet/models', ...
models{i}), crt_model_path);
% backwards compatibility for the model:
fix_load_nn(crt_model_path);
end
end
% -------------------------------------------------------------------------
% Load dataset
% -------------------------------------------------------------------------
vl_xmkdir(opts.expDir) ;
vl_xmkdir(opts.imdbDir) ;
imdbPath = fullfile(opts.imdbDir, sprintf('imdb-seed-%d.mat', opts.seed)) ;
if exist(imdbPath)
imdb = load(imdbPath) ;
return ;
end
switch opts.dataset
case 'os'
imdb = os_get_database(opts.osDir) ;
case 'os-a'
imdb = os_attr_get_database(opts.osDir);
case 'fmd'
imdb = fmd_get_database(opts.fmdDir, 'seed', opts.seed) ;
case 'dtd'
imdb = dtd_get_database(opts.dtdDir, 'seed', opts.seed);
case 'kth'
imdb = kth_get_database(opts.kthDir, 'seed', opts.seed);
case 'voc07'
imdb = voc_get_database(opts.vocDir, 'seed', opts.seed);
case 'voc12'
imdb = voc_get_database(opts.vocDir12, 'seed', opts.seed);
case 'voc12s'
imdb = voc_get_seg_database(opts.vocDir12, 'seed', opts.seed);
case 'mit'
imdb = mit_indoor_get_database(opts.mitDir);
case 'msrc'
imdb = msrc_c_get_database(opts.msrcDir);
case 'cubcrop'
imdb = cub_get_database(opts.cubDir, true);
case 'cub'
imdb = cub_get_database(opts.cubDir, false);
case 'alot'
imdb = alot_get_database(opts.alotDir, 'seed', opts.seed);
otherwise
serror('Unknown dataset %s', opts.dataset) ;
end
save(imdbPath, '-struct', 'imdb') ;
if opts.printDatasetInfo
print_dataset_info(imdb) ;
end
% -------------------------------------------------------------------------
function model = get_cnn_model_from_encoder_opts(encoder)
% -------------------------------------------------------------------------
p = find(strcmp('model', encoder.opts)) ;
if ~isempty(p)
[~,m,e] = fileparts(encoder.opts{p+1}) ;
model = {[m e]} ;
else
model = {} ;
end