-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearning_curve.sh
executable file
·248 lines (232 loc) · 7.42 KB
/
learning_curve.sh
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
# set -xe
usage="$(basename "$0") [-h|--help] [-r|--run_id <string>] [-d|--destination <path>] [-t|--train_files <path>] [-v|--valid_files <path>] [-g|--gpu] [-b|--batch_size <int>] [-e|--epochs <int>] [-l|--lm <path>] [-a|--lm_vocab <path>] [-i|--language <string>] [-p|--dropouts] [-o|--optimizer <string>]
where:
-h|--help show this help text
-r|--run_id <string> run-id to use (used to resume training)
-d|--destination <path> destination directory to store results
-l|--lm <path> path to n-gram KenLM model (if possible binary)
-a|--lm_vocab <path> path to file containing the vocabulary of the LM specified by -lm.
The file must contain the words used for training delimited by space (no newlines)
-i|--language <string> The language to train on ('en' or 'de'). This will determine the number of labels and therefore the model architecture. (default: en)
-t|--train_files <path> one or more comma-separated paths to CSV files containing the samples to use for training
-v|--valid_files <path> one or more comma-separated paths to CSV files containing the samples to use for validation
-z|--test_files <path> one or more comma-separated paths to CSV files contatining the samples to use for testing
-g|--gpu <int> GPU to use
-b|--batch_size <int> batch size (default: 16)
-e|--epochs <int> number of epochs to train (default: 30)
-u|--valid_batches <int> number of batches to use for validation (default: all)
-p|--dropouts whether to use dropout regularization (default: no)
-x|--use_synth whether to use synthesized data for training (default: no)
-o|--optimizer optimizer to use ('adam' or 'sgd'). (default: 'adam')
Create data to plot a learning curve by running a simplified version of the DeepSpeech-BRNN. This script will call run-train.py with increasing amounts of training data (1 to 1000 minutes).
For each amount of training data a separate training run is started. A unique run-id is assigned to each training run from which the value of each dimension can be derived.
"
# Defaults
lc_run_id="learning_run_$(uuidgen)"
lm=''
lm_vocab=''
language='en'
train_files=''
valid_files=''
test_files=''
target_dir=''
gpu=''
batch_size='16'
epochs='30'
valid_batches='0'
dropouts=''
use_synth=''
optimizer='sgd'
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
echo ${usage}
shift
exit
;;
-r|--run_id)
lc_run_id="$2"
shift
shift
;;
-d|--destination)
target_dir="$2"
shift
shift
;;
-l|--lm)
lm="$2"
shift
shift
;;
-a|--lm_vocab)
lm_vocab="$2"
shift
shift
;;
-i|--language)
language="$2"
shift
shift
;;
-t|--train_files)
train_files="$2"
shift
shift
;;
-v|--valid_files)
valid_files="$2"
shift
shift
;;
-z|--test_files)
test_files="$2"
shift
shift
;;
-g|--gpu)
gpu="$2"
shift
shift
;;
-b|--batch_size)
batch_size="$2"
shift
shift
;;
-e|--epochs)
epochs="$2"
shift
shift
;;
-u|--valid_batches)
valid_batches="$2"
shift
shift
;;
-p|--dropout)
dropouts='--dropouts'
shift
;;
-x|--use_synth)
use_synth='--use_synth'
shift
;;
-o|--optimizer)
optimizer="$2"
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
lc_result_dir=${target_dir%/}/${lc_run_id}
mkdir -p ${lc_result_dir}
logfile=${lc_result_dir%/}/${lc_run_id}.log
SECONDS=0
git status > ${logfile}
git rev-parse HEAD >> ${logfile}
echo "
-----------------------------------------------------
Start time: $(date)
starting learning curve with the following parameters
-----------------------------------------------------
lc_run_id = ${lc_run_id}
target_dir = ${target_dir}
lc_result_dir = ${lc_result_dir}
lm = ${lm}
lm_vocab = ${lm_vocab}
language = ${language}
train_files = ${train_files}
valid_files = ${valid_files}
test_files = ${test_files}
gpu = ${gpu}
batch_size = ${batch_size}
epochs = ${epochs}
valid_batches = ${valid_batches}
dropouts = ${dropouts}
use_synth = ${use_synth}
optimizer = ${optimizer}
-----------------------------------------------------
" | tee -a ${logfile}
if [[ ${gpu} = '' ]]; then
echo "Enter GPU # to use for training"
read gpu
fi
echo "using GPU #${gpu} for all training runs!"
cd ./src/
for minutes in 1 10 100 1000
do
run_id="${minutes}_min"
model_dir="${lc_result_dir}/${run_id}"
echo "
#################################################################################################
Training on $minutes minutes
learning run id: $lc_run_id
run id: $run_id
target subdirectory: $lc_result_dir
model directory: $model_dir
-------------------------------------------------------------------------------------------------
"
python3 run-train.py \
--run_id ${run_id} \
--target_dir ${lc_result_dir} \
--minutes ${minutes} \
--lm ${lm} \
--lm_vocab ${lm_vocab} \
--language ${language} \
${dropouts} \
${use_synth} \
--optimizer ${optimizer} \
--gpu ${gpu} \
--batch_size ${batch_size} \
--epochs ${epochs} \
--valid_batches ${valid_batches} \
--train_files ${train_files} \
--valid_files ${valid_files} \
2>&1 | tee ${lc_result_dir}/${run_id}.log # write to stdout and log file
echo "
-------------------------------------------------------------------------------------------------
Testing model in $model_dir
using samples from $test_files
-------------------------------------------------------------------------------------------------
"
python3 run-test.py \
--model_dir ${model_dir} \
--test_files ${test_files} \
--lm ${lm} \
--lm_vocab ${lm_vocab} \
--language ${language} \
--gpu ${gpu}
echo "
-------------------------------------------------------------------------------------------------
Finished training $run_id
Model and test results saved in $model_dir
#################################################################################################
"
done
echo "
=================================================================================================
Visualizing learning curve
-------------------------------------------------------------------------------------------------
"
python3 visualize_learning_curve.py ${lc_result_dir} --silent
echo "
-------------------------------------------------------------------------------------------------
done!
=================================================================================================
"
duration=$SECONDS
echo "
-----------------------------------------------------
End time: $(date)
Finished in ${duration} seconds
-----------------------------------------------------
"