-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathIMDBAddPlaces2.m
86 lines (73 loc) · 2.58 KB
/
IMDBAddPlaces2.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
function [ imdb, select ] = IMDBAddPlaces2( imdb, path, task_num, varargin )
% IMDBADDPLACES2 Add to imdb the Places2 dataset (401 classes version).
%
% IMPORTANT NOTE: Here we use Places2 with 401 classes, which was used in
% ILSVRC2015 taster challenge. However, it has become obsolete after our paper
% submission. Places365 now replaces it as a better dataset.
%
% Input:
% PATH struct generated by GETPATH()
% 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' only.
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
sets = {'train', 'val', 'test'}; sets = sets(opts.trainval);
% train or val set
for f = sets
f = char(f);
set = 1; if strcmp(f, 'val'), set = 2; elseif strcmp(f, 'test'), set = 3; end
% image names
fid = fopen(fullfile(path.path_Placesmeta, [f '.txt']), 'r');
readname.(f) = textscan(fid, '%s %d');
fclose(fid);
% 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 'class'
% stuff.
classes = num2cell(double(1 + readname.(f){2}));
otherwise
throw(MException('opts.label:notRecognized', 'class'));
end
classes = classes(select.(f),:);
names = strcat([f '/'], names);
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