Blame view
Scripts/steps/.svn/text-base/align_raw_fmllr.sh.svn-base
5.49 KB
ec85f8892 first commit |
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 |
#!/bin/bash # Copyright 2012-2013 Johns Hopkins University (Author: Daniel Povey) # Apache 2.0 # Computes training alignments; assumes features are (LDA+MLLT or delta+delta-delta) # + fMLLR (probably with SAT models). # It first computes an alignment with the final.alimdl (or the final.mdl if final.alimdl # is not present), then does 2 iterations of fMLLR estimation. # If you supply the --use-graphs option, it will use the training # graphs from the source directory (where the model is). In this # case the number of jobs must match the source directory. # Begin configuration section. stage=0 nj=4 cmd=run.pl use_graphs=false # Begin configuration. scale_opts="--transition-scale=1.0 --acoustic-scale=0.1 --self-loop-scale=0.1" beam=10 retry_beam=40 boost_silence=1.0 # factor by which to boost silence during alignment. norm_vars=false # End configuration options. echo "$0 $@" # Print the command line for logging [ -f path.sh ] && . ./path.sh # source the path. . parse_options.sh || exit 1; if [ $# != 4 ]; then echo "usage: steps/align_fmllr.sh <data-dir> <lang-dir> <src-dir> <align-dir>" echo "e.g.: steps/align_fmllr.sh data/train data/lang exp/tri1 exp/tri1_ali" echo "main options (for others, see top of script file)" echo " --config <config-file> # config containing options" echo " --nj <nj> # number of parallel jobs" echo " --use-graphs true # use graphs in src-dir" echo " --cmd (utils/run.pl|utils/queue.pl <queue opts>) # how to run jobs." exit 1; fi data=$1 lang=$2 srcdir=$3 dir=$4 oov=`cat $lang/oov.int` || exit 1; silphonelist=`cat $lang/phones/silence.csl` || exit 1; sdata=$data/split$nj mkdir -p $dir/log echo $nj > $dir/num_jobs [[ -d $sdata && $data/feats.scp -ot $sdata ]] || split_data.sh $data $nj || exit 1; cp $srcdir/{tree,final.mdl} $dir || exit 1; cp $srcdir/final.occs $dir; splice_opts=`cat $srcdir/splice_opts 2>/dev/null` # frame-splicing options. cp $srcdir/splice_opts $dir 2>/dev/null # frame-splicing options. if [[ ! -f $srcdir/final.mat || ! -f $srcdir/full.mat ]]; then echo "$0: we require final.mat and full.mat in the source directory $srcdir" fi full_lda_mat="get-full-lda-mat --print-args=false $srcdir/final.mat $srcdir/full.mat -|" cp $srcdir/full.mat $srcdir/final.mat $dir splicedfeats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- |" sifeats="$splicedfeats transform-feats $srcdir/final.mat ark:- ark:- |" ## Set up model and alignment model. mdl=$srcdir/final.mdl if [ -f $srcdir/final.alimdl ]; then alimdl=$srcdir/final.alimdl else alimdl=$srcdir/final.mdl fi [ ! -f $mdl ] && echo "$0: no such model $mdl" && exit 1; alimdl_cmd="gmm-boost-silence --boost=$boost_silence `cat $lang/phones/optional_silence.csl` $alimdl - |" mdl_cmd="gmm-boost-silence --boost=$boost_silence `cat $lang/phones/optional_silence.csl` $mdl - |" ## Work out where we're getting the graphs from. if $use_graphs; then [ "$nj" != "`cat $srcdir/num_jobs`" ] && \ echo "$0: you specified --use-graphs true, but #jobs mismatch." && exit 1; [ ! -f $srcdir/fsts.1.gz ] && echo "No graphs in $srcdir" && exit 1; graphdir=$srcdir else graphdir=$dir if [ $stage -le 0 ]; then echo "$0: compiling training graphs" tra="ark:utils/sym2int.pl --map-oov $oov -f 2- $lang/words.txt $sdata/JOB/text|"; $cmd JOB=1:$nj $dir/log/compile_graphs.JOB.log \ compile-train-graphs $dir/tree $dir/final.mdl $lang/L.fst "$tra" \ "ark:|gzip -c >$dir/fsts.JOB.gz" || exit 1; fi fi if [ $stage -le 1 ]; then echo "$0: aligning data in $data using $alimdl and speaker-independent features." $cmd JOB=1:$nj $dir/log/align_pass1.JOB.log \ gmm-align-compiled $scale_opts --beam=$beam --retry-beam=$retry_beam "$alimdl_cmd" \ "ark:gunzip -c $graphdir/fsts.JOB.gz|" "$sifeats" "ark:|gzip -c >$dir/pre_ali.JOB.gz" || exit 1; fi if [ $stage -le 2 ]; then echo "$0: computing fMLLR transforms" if [ "$alimdl" != "$mdl" ]; then $cmd JOB=1:$nj $dir/log/fmllr.JOB.log \ ali-to-post "ark:gunzip -c $dir/pre_ali.JOB.gz|" ark:- \| \ weight-silence-post 0.0 $silphonelist $alimdl ark:- ark:- \| \ gmm-post-to-gpost $alimdl "$sifeats" ark:- ark:- \| \ gmm-est-fmllr-raw-gpost --spk2utt=ark:$sdata/JOB/spk2utt \ $mdl "$full_lda_mat" "$splicedfeats" ark,s,cs:- ark:$dir/raw_trans.JOB || exit 1; else $cmd JOB=1:$nj $dir/log/fmllr.JOB.log \ ali-to-post "ark:gunzip -c $dir/pre_ali.JOB.gz|" ark:- \| \ weight-silence-post 0.0 $silphonelist $alimdl ark:- ark:- \| \ gmm-est-fmllr-raw --spk2utt=ark:$sdata/JOB/spk2utt $mdl "$full_lda_mat" \ "$splicedfeats" ark,s,cs:- ark:$dir/raw_trans.JOB || exit 1; fi fi feats="ark,s,cs:apply-cmvn --norm-vars=$norm_vars --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | transform-feats --utt2spk=ark:$sdata/JOB/utt2spk ark:$dir/raw_trans.JOB ark:- ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |" if [ $stage -le 3 ]; then echo "$0: doing final alignment." $cmd JOB=1:$nj $dir/log/align_pass2.JOB.log \ gmm-align-compiled $scale_opts --beam=$beam --retry-beam=$retry_beam "$mdl_cmd" \ "ark:gunzip -c $graphdir/fsts.JOB.gz|" "$feats" "ark:|gzip -c >$dir/ali.JOB.gz" || exit 1; fi rm $dir/pre_ali.*.gz echo "$0: done aligning data." utils/summarize_warnings.pl $dir/log exit 0; |