-
Notifications
You must be signed in to change notification settings - Fork 188
/
cnn_ucf101_setup_data.m
149 lines (116 loc) · 4.34 KB
/
cnn_ucf101_setup_data.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
function imdb = cnn_ucf101_setup_data(varargin)
opts.nSplit = 1;
opts.dataPath = '';
opts.flowDir = '';
opts.dataSet = 'ucf101' ;
[opts, varargin] = vl_argparse(opts, varargin) ;
opts.dataDir = fullfile(opts.dataPath,opts.dataSet) ;
opts.imageDir = fullfile(opts.dataDir, 'jpegs_256') ;
[opts, varargin] = vl_argparse(opts, varargin) ;
switch opts.dataSet
case 'ucf101'
nClasses = 101 ;
case 'hmdb51'
nClasses = 51 ;
opts.flowDir = strrep(opts.flowDir, 'ucf101','hmdb51');
opts.imageDir = strrep(opts.imageDir, 'ucf101','hmdb51');
end
opts.splitDir = [opts.dataSet '_splits'];
% -------------------------------------------------------------------------
% Load categories metadata
% -------------------------------------------------------------------------
[Training_set, Testing_set, cats]= feval(sprintf('get_%s_split', lower(opts.dataSet)),opts.nSplit,opts.splitDir);
naction = length(Training_set);
nTrain = 0; nTest = 0;
for iaction = 1:naction
nTrain = nTrain + numel(Training_set{iaction});
nTest = nTest + numel(Testing_set{iaction});
labels_train{iaction} = repmat(iaction,1,numel(Training_set{iaction}));
labels_test{iaction} = repmat(iaction,1,numel(Testing_set{iaction}));
end
labels_train = [labels_train{:}];
labels_test = [labels_test{:}];
imdb.classes.name = cats ;
imdb.videoDir = fullfile(opts.dataDir, 'avis') ;
imdb.imageDir = opts.imageDir;
imdb.flowDir = opts.flowDir;
imdb.images.name = horzcat(Training_set{:},Testing_set{:}) ;
imdb.images.set = horzcat(ones(1, nTrain), 2*ones(1, nTest)) ;
imdb.images.label = horzcat(labels_train, labels_test) ;
imdb.images.labels = double(repmat(imdb.images.label,nClasses,1)' == repmat(1:nClasses,length(imdb.images.label),1));
imdb.images.nFrames = zeros(1, numel(imdb.images.name)) ;
imdb.images.flowScales = cell(1,numel(imdb.images.name));
% get frames
vids = imdb.images.name;
for v=1:numel(vids)
vid_name = vids(v); vid_name = vid_name{1}(1:end-4);
ims = dir(fullfile(imdb.imageDir, vid_name, '*.jpg'));
imdb.images.nFrames(v) = numel(ims);
end
function [train_fnames,test_fnames, saction]= get_ucf101_split(isplit,splitdir)
fid = fopen([splitdir '/classInd.txt']);
classes = textscan(fid, '%s');
saction = classes{1}(2:2:end);
fname = sprintf('%s/testlist0%d.txt',splitdir,isplit);
fid = fopen(fname);
test_fnames = cell(length(saction),1);
train_fnames = cell(length(saction),1);
while 1
tline = fgetl(fid);
if tline==-1
break
end
[tline, u] = strtok(tline,' ');
video = sprintf('%s.avi',tline(1:end-4));
[className, vidName] = strtok(video,'/');
iaction = find(strcmp(saction, className));
test_fnames{iaction}{end+1} = vidName(2:end);
end
fclose(fid);
itr = 1;
fname = sprintf('%s/trainlist0%d.txt',splitdir,isplit);
fid = fopen(fname);
while 1
tline = fgetl(fid);
if tline==-1
break
end
[tline, u] = strtok(tline,' ');
video = sprintf('%s.avi',tline(1:end-4));
[className, vidName] = strtok(video,'/');
iaction = find(strcmp(saction, className));
train_fnames{iaction}{end+1} = vidName(2:end);
end
fclose(fid);
function [train_fnames,test_fnames, saction]= get_hmdb51_split(isplit,splitdir)
saction = {'brush_hair','cartwheel','catch','chew','clap','climb','climb_stairs',...
'dive','draw_sword','dribble','drink','eat','fall_floor','fencing',...
'flic_flac','golf','handstand','hit','hug','jump','kick_ball',...
'kick','kiss','laugh','pick','pour','pullup','punch',...
'push','pushup','ride_bike','ride_horse','run','shake_hands','shoot_ball',...
'shoot_bow','shoot_gun','sit','situp','smile','smoke','somersault',...
'stand','swing_baseball','sword_exercise','sword','talk','throw','turn',...
'walk','wave'};
for iaction = 1:length(saction)
itr = 1;
ite = 1;
fname = sprintf('%s/%s_test_split%d.txt',splitdir,saction{iaction},isplit);
fid = fopen(fname);
while 1
tline = fgetl(fid);
if tline==-1
break
end
[tline, u] = strtok(tline,' ');
u = str2num(u);
video = sprintf('%s.avi',tline(1:end-4));
if u==1 % ignore testing
train_fnames{iaction}{itr} = tline;
itr = itr + 1;
elseif u==2
test_fnames{iaction}{ite} = tline;
ite = ite + 1;
end
end
fclose(fid);
end