-
Notifications
You must be signed in to change notification settings - Fork 19
/
06_train_classifier.py
205 lines (173 loc) · 7.57 KB
/
06_train_classifier.py
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
205
import argparse
from classifier.train import *
def parse_arguments():
"""
Parse arguments from the command line
Returns:
args: Argument dictionary
(Type: dict[str, *])
"""
parser = argparse.ArgumentParser(description='Generate embedding data for training an urban sound classification model')
parser.add_argument('-e',
'--num-epochs',
dest='num_epochs',
action='store',
type=int,
default=150,
help='(MLP) Maximum number of training epochs')
parser.add_argument('-tbs',
'--train-batch-size',
dest='train_batch_size',
action='store',
type=int,
default=64,
help='(MLP) Number of training examples per batch')
parser.add_argument('-eap',
'--early-stopping-patience',
dest='patience',
action='store',
type=int,
default=20,
help='(MLP) Patience for early stopping')
parser.add_argument('-ps',
'--parameter-search',
dest='parameter_search',
action='store_true',
help='If True, parameter search will be run')
parser.add_argument('-psnv',
'--parameter-search-no-valid-fold',
dest='parameter_search_valid_fold',
action='store_false',
help='If True, include validation set in train set and instead get the validation set as a ratio of the training set')
parser.add_argument('-psvr',
'--parameter-search-valid-ratio',
dest='parameter_search_valid_ratio',
action='store',
type=float,
default=0.15,
help='If no validation fold is used, the ratio of the extended training set to set aside for validation')
parser.add_argument('-pstwv',
'--parameter-search-train-without-valid',
dest='parameter_search_train_with_valid',
action='store_false',
help='If set, do not retrain with validation set')
parser.add_argument('-lr',
'--learning-rate',
dest='learning_rate',
action='store',
type=float,
default=1e-4,
help='(MLP) Optimization learning rate')
parser.add_argument('-wd',
'--weight-decay',
dest='weight_decay',
action='store',
type=float,
default=1e-5,
help='(MLP) L2 regularization penalty factor')
parser.add_argument('-npf',
'--norm-penalty-factor',
dest='C',
action='store',
type=float,
default=1.0,
help='(SVM) norm penalization factor')
parser.add_argument('-sct',
'--svm-conv-tolerance',
dest='tol',
action='store',
type=float,
default=0.00001,
help='(SVM) convergence tolerance threshold')
parser.add_argument('-smi',
'--svm-max-iterations',
dest='max_iterations',
action='store',
type=int,
default=-1,
help='(SVM) maximum iterations')
parser.add_argument('-skt',
'--svm-kernel-type',
dest='kernel',
action='store',
type=str,
default='rbf',
choices=['rbf', 'sigmoid', 'linear', 'poly'],
help='(SVM) kernel type')
parser.add_argument('-rfne',
'--rf-num-estimators',
dest='n_estimators',
action='store',
type=int,
default=100,
help='(RF) Number of decision trees in the random forest')
parser.add_argument('-gsid',
'--gsheet-id',
dest='gsheet_id',
type=str,
help='Google Spreadsheet ID for centralized logging of experiments')
parser.add_argument('-gdan',
'--google-dev-app-name',
dest='google_dev_app_name',
type=str,
help='Google Developer Application Name for using API')
parser.add_argument('-r',
'--random-state',
dest='random_state',
action='store',
type=int,
default=20171021,
help='Random seed used to set the RNG state')
parser.add_argument('-v',
'--verbose',
dest='verbose',
action='store_true',
default=False,
help='If True, print detailed messages')
parser.add_argument('-fm',
'--feature-mode',
dest='feature_mode',
action='store',
type=str,
default='framewise',
choices=['framewise', 'stats'],
help='Type of inputs used for model')
parser.add_argument('-mt',
'--model-type',
dest='model_type',
action='store',
type=str,
default='svm',
choices=['svm', 'mlp', 'rf'],
help='Type of model used for training classifier')
parser.add_argument('-no',
'--non-overlap',
dest='non_overlap',
action='store_true',
default=False)
parser.add_argument('-nocs',
'--non-overlap-chunk-size',
dest='non_overlap_chunk_size',
action='store',
default=10)
parser.add_argument('-umm',
'--use-min-max',
dest='use_min_max',
action='store_true',
default=False)
parser.add_argument('features_dir',
action='store',
type=str,
help='Path to directory where feature files are stored')
parser.add_argument('output_dir',
action='store',
type=str,
help='Path to directory where output files will be stored')
parser.add_argument('fold_num',
action='store',
type=int,
help='Fold ordinal to train/test with')
return vars(parser.parse_args())
if __name__ == '__main__':
args = parse_arguments()
train(**args)