-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtask1_scene_classification.m
204 lines (179 loc) · 6.32 KB
/
task1_scene_classification.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
function task1_scene_classification(varargin)
%%
download_external_libraries(); % Download external libraries
add_paths(); % Add file paths
rng(123456); % let's make randomization predictable
parser = inputParser;
parser.addOptional('mode', 'challenge', @isstr);
parser.addOptional('yaml_path', 'task1_scattering.yaml', @isstr);
%parser.addOptional('yaml_path', 'task1_baseline.yaml', @isstr);
parse(parser, varargin{:});
params = load_parameters(parser.Results.yaml_path);
params = process_parameters(params);
title('DCASE 2016::Acoustic Scene Classification');
% Check if mode is defined
if(strcmp(parser.Results.mode, 'development')),
args.development = true;
args.challenge = false;
elseif(strcmp(parser.Results.mode, 'challenge')),
args.development = false;
args.challenge = true;
end
dataset_evaluation_mode = 'folds';
if(args.development && ~args.challenge),
disp('Running system in development mode');
dataset_evaluation_mode = 'folds';
elseif(~args.development && args.challenge),
disp('Running system in challenge mode');
dataset_evaluation_mode = 'full';
end
% Get dataset container class
if strcmp(params.general.development_dataset, ...
'TUTAcousticScenes_2016_DevelopmentSet')
dataset = TUTAcousticScenes_2016_DevelopmentSet(params.path.data);
else
error(['Unknown development dataset [', ...
params.general.development_dataset, ']']);
end
% Fetch data over internet and setup the data
% ==================================================
if params.flow.initialize
dataset.fetch();
end
% Extract features for all audio files in the dataset
% ==================================================
if params.flow.extract_features
section_header('Feature extraction');
% Collect files in train sets
files = [];
for fold = dataset.folds(dataset_evaluation_mode)
train_items = dataset.train(fold);
for item_id = 1:length(train_items)
item = train_items(item_id);
if sum(strcmp(item.file,files)) == 0
files = cat(1, files, {item.file});
end
end
test_items = dataset.test(fold);
for item_id = 1:length(test_items)
item = test_items(item_id);
if sum(strcmp(item.file,files)) == 0
files = cat(1, files, {item.file});
end
end
end
files = sort(files);
% Go through files and make sure all features are extracted
do_feature_extraction(files, ...
dataset, ...
params.path.features, ...
params.features, ...
params.general.overwrite);
foot();
end
%% Apply feature selection
% ==================================================
if params.flow.feature_selection
section_header('Feature selection');
do_feature_selection(dataset, ...
params.selection, ...
params.path.feature_selectors, ...
params.path.features, ...
dataset_evaluation_mode, ...
params.general.overwrite);
end
%% Prepare feature normalizers
% ==================================================
if params.flow.feature_normalizer
section_header('Feature normalizer');
do_feature_normalization(dataset, ...
params.path.feature_normalizers, ...
params.path.features, ...
params, ...
dataset_evaluation_mode, ...
params.general.overwrite);
foot();
end
% System training
% ==================================================
if params.flow.train_system
section_header('System training');
model_path = params.path.models;
feature_normalizer_path = params.path.feature_normalizers;
feature_path = params.path.features;
classifier_params = params.classifier.parameters;
classifier_method = params.classifier.method;
overwrite = params.general.overwrite;
do_system_training(dataset, model_path, feature_normalizer_path, ...
feature_path, params, classifier_params, dataset_evaluation_mode, ...
classifier_method, overwrite);
foot();
end
% System evaluation in development mode
if(args.development && ~args.challenge)
% System testing
% ==================================================
if params.flow.test_system
section_header('System testing [Development data]');
feature_path = params.path.features;
result_path = params.path.results;
model_path = params.path.models;
feature_params = params.features;
classifier_method = params.classifier.method;
overwrite = params.general.overwrite;
do_system_testing(dataset,...
feature_path, ...
result_path, ...
model_path, ...
feature_params, ...
params, ...
dataset_evaluation_mode,...
classifier_method,...
overwrite);
foot();
end
% System evaluation
% ==================================================
if params.flow.evaluate_system
section_header('System evaluation');
do_system_evaluation(dataset,...
params.path.results,...
dataset_evaluation_mode);
foot();
end
% System evaluation with challenge data
elseif(~args.development && args.challenge)
% Get dataset container class
if strcmp(params.general.challenge_dataset, 'TUTAcousticScenes_2016_EvaluationSet')
challenge_dataset = TUTAcousticScenes_2016_EvaluationSet(params.path.data);
else
error(['Unknown development dataset [', params.general.evaluation_dataset, ']']);
end
if params.flow.initialize
challenge_dataset.fetch();
end
% System testing
if params.flow.test_system
section_header('System testing [Challenge data]');
feature_path = params.path.features;
result_path = params.path.results;
model_path = params.path.models;
feature_params = params.features;
classifier_method = params.classifier.method;
overwrite = true;
do_system_testing(challenge_dataset,...
feature_path,...
result_path,...
model_path,...
feature_params,...
params, ...
dataset_evaluation_mode,...
classifier_method,...
overwrite);
foot();
disp(' ');
disp(['Your results for the challenge data are stored at [',params.path.challenge_results,']']);
disp(' ');
end
end
end