-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcnn_setup_imdb.m
More file actions
64 lines (57 loc) · 1.79 KB
/
Copy pathcnn_setup_imdb.m
File metadata and controls
64 lines (57 loc) · 1.79 KB
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
% cnn_setup_data:
% function imdb = cnn_setup_imdb(data, opts)
% imdb:
% -inputSize
% -labelSize
% -images
% -id
% -name
% -set
% -label
function imdb = cnn_setup_imdb(opts)
rng(0);
imdb.imageDir = fullfile(opts.dataDir, 'images');
imdb.labelDir = fullfile(opts.dataDir, 'labels');
imdb.classes.KeyName2Idx = get_keyname_index();
imdb.imageSize = [256,224,3];
imdb.labelSize = [256,224,imdb.classes.KeyName2Idx.Count];
% train/val
names = {};
labels = {};
for d = dir(fullfile(opts.dataDir, 'images/train/*.jpg'))'
names{end+1} = ['train/' d.name];
labels{end+1} = ['train/' strrep(d.name, 'jpg', 'mat')];
end
num = numel(names);
imdb.images.id = 1:num;
imdb.images.set = ones(1, num);
imdb.images.name = names;
imdb.images.label = labels;
% randomly split 20% for validation
if ~exist(fullfile(opts.dataDir, 'images/val'))
imdb.images.set(randperm(num, round(0.2*num))) = 2;
else
names = {};
labels = {};
for d = dir(fullfile(opts.dataDir, 'images/val/*.jpg'))'
names{end+1} = ['val/' d.name];
labels{end+1} = ['val/' strrep(d.name, 'jpg', 'mat')];
end
num = numel(names);
imdb.images.id = horzcat(imdb.images.id, (1:num) + 1e7);
imdb.images.set = horzcat(imdb.images.set, 2*ones(1, num));
imdb.images.name = horzcat(imdb.images.name, names);
imdb.images.label = horzcat(imdb.images.label, labels);
end
% test
names = {};
labels = {};
for d = dir(fullfile(opts.dataDir, 'images/test/*.jpg'))'
names{end+1} = ['test/' d.name];
labels{end+1} = ['test/' strrep(d.name, 'jpg', 'mat')];
end
num = numel(names);
imdb.images.id = horzcat(imdb.images.id, (1:num) + 2e7);
imdb.images.set = horzcat(imdb.images.set, 3*ones(1, num));
imdb.images.name = horzcat(imdb.images.name, names);
imdb.images.label = horzcat(imdb.images.label, labels);