forked from peiyunh/tiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnn_setup_imdb.m
100 lines (84 loc) · 3.01 KB
/
cnn_setup_imdb.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
% FILE: cnn_setup_imdb.m
%
% This function reads WIDER FACE dataset and generates a MATLAB struct
% variable that is more friendly and eaiser to work with.
%
% INPUT:
%
% OUTPUT: imdb (a more user-friendly struct variable for the dataset)
function imdb = cnn_setup_imdb(varargin)
opts.dataDir = fullfile('data','widerface') ;
opts = vl_argparse(opts, varargin) ;
% construct imdb
imdb = struct();
imdb.imageDir = opts.dataDir;
imdb.images = struct();
imdb.labels = struct();
imdb.images.name = {};
cnt = 0;
% train
load(fullfile(opts.dataDir, 'wider_face_train.mat'));
for i = 1:numel(event_list)
imageDir = fullfile('WIDER_train/images', event_list{i});
imageList = file_list{i};
bboxList = face_bbx_list{i};
for j = 1:numel(imageList)
cnt = cnt + 1;
imagePath = fullfile(imageDir, [imageList{j} '.jpg']);
imdb.images.name{cnt} = imagePath;
info = imfinfo(fullfile(opts.dataDir, imagePath));
imdb.images.size(cnt,1:2) = [info.Height info.Width];
imdb.images.set(cnt) = 1;
rects = bboxList{j};
imdb.labels.rects{cnt} = horzcat(...
rects(:,[1 2]), rects(:,[1 2])+rects(:,[3 4])-1);
imdb.labels.eventid(cnt) = i;
end
end
% setup event list ( index is consistent with face_bbx_list )
imdb.events.name = event_list;
%load(fullfile(opts.dataDir, 'event_diffmap.mat'));
%for i = 1:numel(event_list)
% imdb.events.diff(i) = diffmap(event_list{i});
%end
% clear variables
fprintf('Setup imdb: processed %d images.\n', cnt);
clear face_bbx_list event_list file_list;
% val
load(fullfile(opts.dataDir, 'wider_face_val.mat'));
for i = 1:numel(event_list)
imageDir = fullfile('WIDER_val/images', event_list{i});
imageList = file_list{i};
bboxList = face_bbx_list{i};
for j = 1:numel(imageList)
cnt = cnt + 1;
imagePath = fullfile(imageDir, [imageList{j} '.jpg']);
imdb.images.name{cnt} = imagePath;
info = imfinfo(fullfile(opts.dataDir, imagePath));
imdb.images.size(cnt,1:2) = [info.Height info.Width];
imdb.images.set(cnt) = 2;
rects = bboxList{j};
imdb.labels.rects{cnt} = horzcat(...
rects(:,[1 2]), rects(:,[1 2])+rects(:,[3 4])-1);
imdb.labels.eventid(cnt) = i;
end
end
fprintf('Setup imdb: processed %d images.\n', cnt);
clear face_bbx_list event_list file_list;
% test
load(fullfile(opts.dataDir, 'wider_face_test.mat'));
for i = 1:numel(event_list)
imageDir = fullfile('WIDER_test/images', event_list{i});
imageList = file_list{i};
for j = 1:numel(imageList)
cnt = cnt + 1;
imagePath = fullfile(imageDir, [imageList{j} '.jpg']);
imdb.images.name{cnt} = imagePath;
info = imfinfo(fullfile(opts.dataDir, imagePath));
imdb.images.size(cnt,1:2) = [info.Height info.Width];
imdb.images.set(cnt) = 3;
imdb.labels.eventid(cnt) = i;
end
end
fprintf('Setup imdb: processed %d images.\n', cnt);
clear event_list file_list;