-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathIMDBAddMIT67.m
89 lines (75 loc) · 2.93 KB
/
IMDBAddMIT67.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
function [ imdb, select ] = IMDBAddMIT67( imdb, path, task_num, varargin )
% IMDBADDMIT67 Add to imdb the MIT indoor scene dataset.
% Input:
% PATH struct generated by GETPATH() with path.path_OrigNetresponse field adjusted
% TASK_NUM the path number (see CNN_CUSTOMTRAIN) that this dataset corresponds to
% Options:
% See code comments
%
% Authors: Zhizhong Li
%
% See the COPYING file.
opts.partial = 0; % for >0 partial, e.g. 0.3, only include that much portion of # samples.
opts.label = 'class'; % 'class' for class label, 'probdist' for a recorded response distribution (uses path.path_OrigNetresponse.MIT67)
opts.trainval = [1 2]; % 1 for train, 2 for val. By default include train+val.
opts.randstream = []; % use randstream if provided
opts = vl_argparse(opts, varargin);
if ~isfield(imdb, 'images')
imdb.images.name = [];
imdb.images.label = [];
imdb.images.set = [];
imdb.images.task = [];
end
fid = fopen(fullfile(path.path_MIT67root, 'classes.txt'), 'r');
classstrs = textscan(fid, '%s\n'); classstrs = classstrs{1};
fclose(fid);
classmap = containers.Map(classstrs, num2cell(1:numel(classstrs)));
sets = {'train', 'test'}; sets = sets(opts.trainval);
% train or test set
for f = sets
f = char(f);
set = 1; if strcmp(f, 'test'), set = 2; end
% image names
itemread = fileread(fullfile(path.path_MIT67meta, [f 'Images.txt']));
readname.(f){1} = strsplit(itemread, {'\n'})';
itemclss = strsplit(itemread, {'\n', '/'})'; itemclss = itemclss(1:2:end);
itemclss = values(classmap, itemclss);
% selecting partial
if opts.partial
if numel(opts.partial)==1
partial = opts.partial;
else
partial = opts.partial(set);
end
if isempty(opts.randstream)
select.(f) = randperm(numel(readname.(f){1}), ceil(numel(readname.(f){1}) * partial));
else
select.(f) = randperm(opts.randstream, numel(readname.(f){1}), ceil(numel(readname.(f){1}) * partial));
end
else
select.(f) = 1:numel(readname.(f){1});
end
% names
names = readname.(f){1}(select.(f));
n_set = size(names,1);
% labels...
switch opts.label
case 'probdist'
% distribution: just load
probdist = load(path.path_OrigNetresponse.MIT67.(f));
classes = num2cell( probdist.lastfc_out, 1 )';
case 'class'
% induct from file folder name
classes = itemclss;
otherwise
throw(MException('opts.label:notRecognized', 'probdist/class'));
end
classes = classes(select.(f),:);
imdb.images.name = [ imdb.images.name; names ];
imdb.images.label = [ imdb.images.label; classes ];
imdb.images.set = [ imdb.images.set;
ones(n_set,1) * set ];
imdb.images.task = [ imdb.images.task;
task_num * ones(n_set, 1) ];
end
if isfield(select, 'test'), select.val = select.test; select = rmfield(select, 'test'); end