-
Notifications
You must be signed in to change notification settings - Fork 0
/
3-train.sh
executable file
·168 lines (146 loc) · 5.07 KB
/
3-train.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
#!/bin/bash
dir=exp/mono
feat=feat/train.39.cmvn.ark
### parameters that you can modify
numiters=35 # Number of iterations of training
maxiterinc=30 # Last iter to increase #Gauss on.
numgauss=20 # Initial num-Gauss (must be more than #states=3*phones).
totgauss=200 # Target #Gaussians.
incgauss=$[($totgauss-$numgauss)/$maxiterinc] # per-iter increment for #Gauss
realign_iters="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";
scale_opts="--transition-scale=1.0 --acoustic-scale=0.1 --self-loop-scale=0.1"
###
mkdir -p $dir
mkdir -p $dir/log
utility/sym2int.pl train/phones.txt train/phoneset.txt > $dir/phonesets.int
shared_phones_opt="--shared-phones=$dir/phonesets.int"
dim=`feat-to-dim --print-args=false "ark,s,cs:$feat" - 2> /dev/null`
echo "Initializing monophone system with dim = [ $dim ]"
if [ ! -f $dir/00.mdl ] || [ ! -f $dir/tree ]; then
log=$dir/log/mono.init.log
echo " output -> $dir/00.mdl $dir/tree"
echo " log -> $log"
gmm-init-mono --binary=false $shared_phones_opt \
"--train-feats=ark:subset-feats --n=10 \"ark,s,cs:$feat\" ark:- |" train/topo $dim \
$dir/00.mdl $dir/tree 2> $log
else
echo " $dir/00.mdl exists , skipping ..."
fi
echo "Compiling training graphs"
if [ ! -f $dir/log/done.graph ] || [ ! -f $dir/train.graph ]; then
log=$dir/log/compile.graphs.log
echo " output -> $dir/train.graph"
echo " log -> $log"
compile-train-graphs $dir/tree $dir/00.mdl train/L.fst ark:train/train.int \
ark:$dir/train.graph 2> $log
touch $dir/log/done.graph
else
echo " $dir/train.graph exists , skipping ..."
fi
iter=0
x=`printf "%02g" $iter`
y=`printf "%02g" $[$iter+1]`
echo "Iteration 00 :"
echo " aligning training graphs equally"
if [ ! -f $dir/log/done.00.ali ] || [ ! -f $dir/00.ali ]; then
log=$dir/log/align.00.log
echo " output -> $dir/00.ali"
echo " log -> $log"
align-equal-compiled ark:$dir/train.graph "ark,s,cs:$feat" \
ark:$dir/00.ali 2> $log
touch $dir/log/done.00.ali
else
echo " $dir/00.ali exists , skipping ..."
fi
ln -sf 00.ali $dir/train.ali
echo " accumulating GMM statistics"
if [ ! -f $dir/00.acc ]; then
log=$dir/log/acc.00.log
echo " output -> $dir/00.acc"
echo " log -> $log"
gmm-acc-stats-ali --binary=false $dir/00.mdl "ark,s,cs:$feat" \
ark:$dir/train.ali $dir/00.acc 2> $log
else
echo " $dir/00.acc exists , skipping ..."
fi
echo " updating GMM parameters and splitting to [ $numgauss ] gaussians"
if [ ! -f $dir/01.mdl ]; then
log=$dir/log/update.00.log
echo " output -> $dir/01.mdl"
echo " log -> $log"
gmm-est --binary=false --min-gaussian-occupancy=3 --mix-up=$numgauss \
$dir/00.mdl $dir/00.acc $dir/01.mdl 2> $log
else
echo " $dir/01.mdl exists , skipping ..."
fi
iter=1
beam=6
while [ $iter -lt $numiters ]; do
x=`printf "%02g" $iter`
y=`printf "%02g" $[$iter+1]`
echo "Iteration $x :"
if echo $realign_iters | grep -w $iter > /dev/null ; then
echo " aligning training graphs by GMM model"
if [ ! -f $dir/log/done.$x.ali ] || [ ! -f $dir/$x.ali ]; then
log=$dir/log/align.$x.log
echo " output -> $dir/$x.ali"
echo " log -> $log"
gmm-align-compiled $scale_opts --beam=$beam --retry-beam=$[$beam*4] $dir/$x.mdl \
ark:$dir/train.graph "ark,s,cs:$feat" \
ark:$dir/$x.ali 2> $log
touch $dir/log/done.$x.ali
else
echo " $dir/$x.ali exists , skipping ..."
fi
ln -sf $x.ali $dir/train.ali
fi
echo " accumulating GMM statistics"
if [ ! -f $dir/$x.acc ]; then
log=$dir/log/acc.$x.log
echo " output -> $dir/$x.acc"
echo " log -> $log"
gmm-acc-stats-ali --binary=false $dir/$x.mdl "ark,s,cs:$feat" \
ark:$dir/train.ali $dir/$x.acc 2> $log
else
echo " $dir/$x.acc exists , skipping ..."
fi
echo " updating GMM parameters and splitting to [ $numgauss ] gaussians"
if [ ! -f $dir/$y.mdl ]; then
log=$dir/log/update.$x.log
echo " output -> $dir/$y.mdl"
echo " log -> $log"
gmm-est --binary=false --min-gaussian-occupancy=3 --mix-up=$numgauss --write-occs=$dir/$y.occs \
$dir/$x.mdl $dir/$x.acc $dir/$y.mdl 2> $log
else
echo " $dir/$y.mdl exists , skipping ..."
fi
if [ $iter -le $maxiterinc ]; then
numgauss=$[$numgauss+$incgauss]
fi
beam=10
iter=$[$iter+1];
done
echo "Training completed:"
echo " mdl = $dir/final.mdl"
echo " occs = $dir/final.occs"
echo " tree = $dir/tree"
cp -f $dir/$y.mdl $dir/final.mdl
cp -f $dir/$y.occs $dir/final.occs
echo "Cleaning redundant materials generated during training process"
rm -f $dir/phonesets.int
rm -f $dir/train.graph
ali=`readlink $dir/train.ali`
rm -f $dir/train.ali
cp -f $dir/$ali $dir/train.ali
rm -f $dir/00.*
iter=1
while [ $iter -le $numiters ]; do
x=`printf "%02g" $iter`
y=`printf "%02g" $[$iter+1]`
rm -f $dir/$x.* $dir/$y.*
iter=$[$iter+1];
done
sec=$SECONDS
echo ""
echo "Execution time for whole script = `utility/timer.pl $sec`"
echo ""