-
Notifications
You must be signed in to change notification settings - Fork 17
/
run.sh
executable file
·171 lines (145 loc) · 5.86 KB
/
run.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
#!/bin/bash
# Copyright 2019 IIIT-Bangalore (Shreekantha Nadig)
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
. ./path.sh || exit 1;
. ./cmd.sh || exit 1;
# general configuration
stage=3 # start from -1 if you need to start from data download
stop_stage=100
ngpu=1 # number of gpus ("0" uses cpu, otherwise use gpu)
debugmode=1
dumpdir=dump # directory to dump full features
N=1 # number of minibatches to be used (mainly for debugging). "0" uses all minibatches.
verbose=1 # verbose option
resume= # Resume the training from ckpt
# feature configuration
do_delta=false
train_config=conf/train_transformer_transducer.yaml
decode_config=conf/decode.yaml
# decoding parameter
recog_model='epoch=38-step=38.ckpt' # set a model to be used for decoding: 'model.acc.best' or 'model.loss.best'
# data
timit=/home/oshindo/TIMIT
trans_type=char
# exp tag
tag="" # tag for managing experiments.
./parse_options.sh || exit 1;
# Set bash to 'debug' mode, it will exit on :
# -e 'error', -u 'undefined variable', -o ... 'error in pipeline', -x 'print commands',
set -e
set -u
set -o pipefail
train_set=train_nodev
# train_set=train_sp
train_dev=train_dev
# train_dev=dev
recog_set="test"
if [ ${stage} -le -1 ] && [ ${stop_stage} -ge -1 ]; then
local/timit_data_prep.sh ${timit} ${trans_type} || exit 1
fi
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
local/timit_format_data.sh
fi
feat_tr_dir=${dumpdir}/${train_set}/delta${do_delta}; mkdir -p ${feat_tr_dir}
feat_dt_dir=${dumpdir}/${train_dev}/delta${do_delta}; mkdir -p ${feat_dt_dir}
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
### Task dependent. You have to design training and dev sets by yourself.
### But you can utilize Kaldi recipes in most cases
echo "stage 1: Feature Generation"
fbankdir=fbank
# Generate the fbank features; by default 80-dimensional fbanks with pitch on each frame
for x in test train dev; do
steps/make_fbank.sh --cmd "$train_cmd" --nj 4 data/${x} exp/make_fbank/${x} ${fbankdir}
done
# make a dev set
# Move train and dev folders (kaldi style naming) to train_nodev and train_dev
mv data/dev data/${train_dev}
mv data/train data/${train_set}
# compute global CMVN
compute-cmvn-stats scp:data/${train_set}/feats.scp data/${train_set}/cmvn.ark
# dump features
dump.sh --cmd "$train_cmd" --nj 8 --do_delta ${do_delta} \
data/${train_set}/feats.scp data/${train_set}/cmvn.ark exp/dump_feats/train ${feat_tr_dir}
dump.sh --cmd "$train_cmd" --nj 8 --do_delta ${do_delta} \
data/${train_dev}/feats.scp data/${train_set}/cmvn.ark exp/dump_feats/dev ${feat_dt_dir}
for rtask in ${recog_set}; do
feat_recog_dir=${dumpdir}/${rtask}/delta${do_delta}; mkdir -p ${feat_recog_dir}
dump.sh --cmd "$train_cmd" --nj 8 --do_delta ${do_delta} \
data/${rtask}/feats.scp data/${train_set}/cmvn.ark exp/dump_feats/recog/${rtask} \
${feat_recog_dir}
done
fi
dict=data/lang_1char/${train_set}_units.txt
echo "dictionary: ${dict}"
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
### Task dependent. You have to check non-linguistic symbols used in the corpus.
echo "stage 2: Dictionary and Json Data Preparation"
mkdir -p data/lang_1char/
echo "<unk> 1" > ${dict} # <unk> must be 1, 0 will be used for "blank" in CTC
text2token.py -s 1 -n 1 data/${train_set}/text --trans_type ${trans_type} | cut -f 2- -d" " | tr " " "\n" \
| sort | uniq | grep -v -e '^\s*$' | awk '{print $0 " " NR+1}' >> ${dict}
wc -l ${dict}
# make json labels
data2json.sh --feat ${feat_tr_dir}/feats.scp --trans_type ${trans_type} \
data/${train_set} ${dict} > ${feat_tr_dir}/data.json
data2json.sh --feat ${feat_dt_dir}/feats.scp --trans_type ${trans_type} \
data/${train_dev} ${dict} > ${feat_dt_dir}/data.json
for rtask in ${recog_set}; do
feat_recog_dir=${dumpdir}/${rtask}/delta${do_delta}
data2json.sh --feat ${feat_recog_dir}/feats.scp --trans_type ${trans_type} \
data/${rtask} ${dict} > ${feat_recog_dir}/data.json
done
fi
if [ -z ${tag} ]; then
expname=${train_set}_$(basename ${train_config%.*})
if ${do_delta}; then
expname=${expname}_delta
fi
else
expname=${train_set}_${tag}
fi
expdir=exp/${expname}
mkdir -p ${expdir}
if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then
echo "stage 3: Network Training"
${cuda_cmd} --gpu ${ngpu} ${expdir}/train.log \
asr_train.py \
--train_config ${train_config} \
--ngpu ${ngpu} \
--outdir ${expdir}/results \
--tensorboard-dir tensorboard/${expname} \
--debugmode ${debugmode} \
--dict ${dict} \
--debugdir ${expdir} \
--minibatches ${N} \
--verbose ${verbose} \
--resume ${resume} \
--train-json ${feat_tr_dir}/data.json \
--valid-json ${feat_dt_dir}/data.json
fi
if [ ${stage} -le 4 ] && [ ${stop_stage} -ge 4 ]; then
echo "stage 4: Decoding"
nj=4
for rtask in ${recog_set}; do
(
decode_dir=decode_${rtask}_$(basename ${decode_config%.*})
feat_recog_dir=${dumpdir}/${rtask}/delta${do_delta}
# split data
splitjson.py --parts ${nj} ${feat_recog_dir}/data.json
#### use CPU for decoding
${decode_cmd} JOB=1:${nj} ${expdir}/${decode_dir}/log/decode.JOB.log \
asr_recog.py \
--train_config ${train_config} \
--recog_config ${decode_config} \
--dict ${dict} \
--verbose ${verbose} \
--debugmode ${debugmode} \
--recog-json ${feat_recog_dir}/split${nj}utt/data.JOB.json \
--result-label ${expdir}/${decode_dir}/data.JOB.json \
--model ${expdir}/results/${recog_model}
score_sclite.sh ${expdir}/${decode_dir} ${dict}
) &
done
wait
echo "Finished"
fi