steps/decode.sh

  1. #!/bin/bash
  2.  
  3. # Copyright 2012 Johns Hopkins University (Author: Daniel Povey)
  4. # Apache 2.0
  5.  
  6. # Begin configuration section.
  7. transform_dir= # this option won't normally be used, but it can be used if you want to
  8. # supply existing fMLLR transforms when decoding.
  9. iter=
  10. model= # You can specify the model to use (e.g. if you want to use the .alimdl)
  11. stage=0
  12. nj=4
  13. cmd=run.pl
  14. max_active=7000
  15. beam=13.0
  16. lattice_beam=6.0
  17. acwt=0.083333 # note: only really affects pruning (scoring is on lattices).
  18. num_threads=1 # if >1, will use gmm-latgen-faster-parallel
  19. parallel_opts= # ignored now.
  20. scoring_opts=
  21. # note: there are no more min-lmwt and max-lmwt options, instead use
  22. # e.g. --scoring-opts "--min-lmwt 1 --max-lmwt 20"
  23. skip_scoring=false
  24. decode_extra_opts=
  25. # End configuration section.
  26.  
  27. echo "$0 $@" # Print the command line for logging
  28.  
  29. [ -f ./path.sh ] && . ./path.sh; # source the path.
  30. . parse_options.sh || exit 1;
  31.  
  32. if [ $# != 3 ]; then
  33. echo "Usage: steps/decode.sh [options] <graph-dir> <data-dir> <decode-dir>"
  34. echo "... where <decode-dir> is assumed to be a sub-directory of the directory"
  35. echo " where the model is."
  36. echo "e.g.: steps/decode.sh exp/mono/graph_tgpr data/test_dev93 exp/mono/decode_dev93_tgpr"
  37. echo ""
  38. echo "This script works on CMN + (delta+delta-delta | LDA+MLLT) features; it works out"
  39. echo "what type of features you used (assuming it's one of these two)"
  40. echo ""
  41. echo "main options (for others, see top of script file)"
  42. echo " --config <config-file> # config containing options"
  43. echo " --nj <nj> # number of parallel jobs"
  44. echo " --iter <iter> # Iteration of model to test."
  45. echo " --model <model> # which model to use (e.g. to"
  46. echo " # specify the final.alimdl)"
  47. echo " --cmd (utils/run.pl|utils/queue.pl <queue opts>) # how to run jobs."
  48. echo " --transform-dir <trans-dir> # dir to find fMLLR transforms "
  49. echo " --acwt <float> # acoustic scale used for lattice generation "
  50. echo " --scoring-opts <string> # options to local/score.sh"
  51. echo " --num-threads <n> # number of threads to use, default 1."
  52. echo " --parallel-opts <opts> # ignored now, present for historical reasons."
  53. exit 1;
  54. fi
  55.  
  56. graphdir=$1 #解码图
  57. data=$2 #测试数据
  58. dir=$3 #输出测试结果文件夹
  59. srcdir=`dirname $dir`; # The model directory is one level up from decoding directory.
  60. sdata=$data/split$nj;#切分文件夹
  61.  
  62. mkdir -p $dir/log #创建结果文件夹/log文件夹
  63. [[ -d $sdata && $data/feats.scp -ot $sdata ]] || split_data.sh $data $nj || exit 1;#$sdata文件夹是否存在 里面的feats.scp是否比该文件夹旧;文件夹切分
  64. echo $nj > $dir/num_jobs #打印线程数字 保存在结果文件夹/num_jobs文件
  65.  
  66. if [ -z "$model" ]; then # if --model <mdl> was not specified on the command line... 命令行里,模型文件没有指定
  67. if [ -z $iter ]; then model=$srcdir/final.mdl; #$iter也没有指定迭代次数, 则模型文件 赋值
  68. else model=$srcdir/$iter.mdl; fi #如果$iter有指定,则模型文件 重新赋值;
  69. fi
  70.  
  71. if [ $(basename $model) != final.alimdl ] ; then #如模型文件 不为 final.alidl
  72. # Do not use the $srcpath -- look at the path where the model is 则不使用srcpath路径,查看你下模型文件再哪里
  73. if [ -f $(dirname $model)/final.alimdl ] && [ -z "$transform_dir" ]; then #如果/final.alimdl不存在,切transform_dir没有指定
  74. echo -e '\n\n'
  75. echo $0 'WARNING: Running speaker independent system decoding using a SAT model!'
  76. echo $0 'WARNING: This is OK if you know what you are doing...'
  77. echo -e '\n\n'
  78. fi
  79. fi
  80.  
  81. for f in $sdata/1/feats.scp $sdata/1/cmvn.scp $model $graphdir/HCLG.fst; do
  82. [ ! -f $f ] && echo "decode.sh: no such file $f" && exit 1; #以上文件如果不存在,则 打印提示,退出
  83. done
  84.  
  85. if [ -f $srcdir/final.mat ]; then feat_type=lda; else feat_type=delta; fi
  86. echo "decode.sh: feature type is $feat_type";#根据final.mat是否存在来判断feat_type 特征类型
  87.  
  88. splice_opts=`cat $srcdir/splice_opts 2>/dev/null` # frame-splicing options.
  89. cmvn_opts=`cat $srcdir/cmvn_opts 2>/dev/null`
  90. delta_opts=`cat $srcdir/delta_opts 2>/dev/null`
  91.  
  92. thread_string=
  93. [ $num_threads -gt 1 ] && thread_string="-parallel --num-threads=$num_threads"

  94. #根据feat_type类型,提取的特征处理不一样
  95. case $feat_type in
  96. delta) feats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas $delta_opts ark:- ark:- |";;
  97. lda) feats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |";;
  98. *) echo "Invalid feature type $feat_type" && exit 1;
  99. esac
  100. if [ ! -z "$transform_dir" ]; then # add transforms to features... 如果没有指定变换输出的文件夹
  101. echo "Using fMLLR transforms from $transform_dir"
  102. [ ! -f $transform_dir/trans.1 ] && echo "Expected $transform_dir/trans.1 to exist."
  103. [ ! -s $transform_dir/num_jobs ] && \
  104. echo "$0: expected $transform_dir/num_jobs to contain the number of jobs." && exit 1;
  105. nj_orig=$(cat $transform_dir/num_jobs)
  106. if [ $nj -ne $nj_orig ]; then #jobs数目 与transform_dir里面的jobs数目不相等,则文档后缀用索引数字
  107. # Copy the transforms into an archive with an index.
  108. echo "$0: num-jobs for transforms mismatches, so copying them."
  109. for n in $(seq $nj_orig); do cat $transform_dir/trans.$n; done | \
  110. copy-feats ark:- ark,scp:$dir/trans.ark,$dir/trans.scp || exit 1;
  111. feats="$feats transform-feats --utt2spk=ark:$sdata/JOB/utt2spk scp:$dir/trans.scp ark:- ark:- |"
  112. else
  113. # number of jobs matches with alignment dir.
  114. feats="$feats transform-feats --utt2spk=ark:$sdata/JOB/utt2spk ark:$transform_dir/trans.JOB ark:- ark:- |"
  115. fi
  116. fi
  117.  
  118. if [ $stage -le 0 ]; then #小于0
  119. if [ -f "$graphdir/num_pdfs" ]; then
  120. [ "`cat $graphdir/num_pdfs`" -eq `am-info --print-args=false $model | grep pdfs | awk '{print $NF}'` ] || \
  121. { echo "Mismatch in number of pdfs with $model"; exit 1; }
  122. fi
  123. $cmd --num-threads $num_threads JOB=1:$nj $dir/log/decode.JOB.log \
  124. gmm-latgen-faster$thread_string --max-active=$max_active --beam=$beam --lattice-beam=$lattice_beam \
  125. --acoustic-scale=$acwt --allow-partial=true --word-symbol-table=$graphdir/words.txt $decode_extra_opts \
  126. $model $graphdir/HCLG.fst "$feats" "ark:|gzip -c > $dir/lat.JOB.gz" || exit 1;#gmm-latgen-faster解码
  127. fi
  128.  
  129. if [ $stage -le 1 ]; then #小于1
  130. [ ! -z $iter ] && iter_opt="--iter $iter"
  131. steps/diagnostic/analyze_lats.sh --cmd "$cmd" $iter_opt $graphdir $dir
  132. fi
  133.  
  134. if ! $skip_scoring ; then #是否执行评分脚本
  135. [ ! -x local/score.sh ] && \
  136. echo "Not scoring because local/score.sh does not exist or not executable." && exit 1;
  137. local/score.sh --cmd "$cmd" $scoring_opts $data $graphdir $dir ||
  138. { echo "$0: Scoring failed. (ignore by '--skip-scoring true')"; exit 1; }
  139. fi
  140.  
  141. exit 0;

kaldi脚本注释二的更多相关文章

  1. kaldi脚本注释一

    utils/split_data.sh ##再$data文件夹下,创建split{num_split}文件夹,再split×里面创建所有的数字文件夹#后面基本上是把$data文件夹下的各个文件都进行s ...

  2. Linux shell脚本编程(二)

    Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...

  3. shell脚本(二)

              shell脚本(二)——变量 一.定义:用来存放各种数据,编程语言组成部分 变量的命名规则: 变量名由数字 字母下划线组成 必须以字母或者下划线开头 不能使用shell里面的关键词 ...

  4. NET中的规范标准注释(二) -- 创建帮助文档入门篇

    一.摘要 在本系列的第一篇文章介绍了.NET中XML注释的用途, 本篇文章将讲解如何使用XML注释生成与MSDN一样的帮助文件.主要介绍NDoc的继承者:SandCastle. 二.背景 要生成帮助文 ...

  5. SecureCrt脚本(二)二级对象之Dialog

    Crt自动化 测试 SecureCrt脚本 JS脚本   1.引言 2.Dialog属性和方法 2.1.属性 2.2.方法 2.2.1.FileOpenDialog 2.2.2.MessageBox ...

  6. 在C#环境中动态调用IronPython脚本(二)

    一.Python数据类型与C#数据类型的对应 Python中数据类型中的简单类型,例如int,float,string可以对应到C#环境中的int32,double,string,这些对应比较直观,P ...

  7. JsDoc脚本注释文档生成

    使用jsDoc可使用特定注释,将注释的内容生成文档,可用于生成脚本库的API文档 jsdoc 文档:   http://usejsdoc.org/

  8. yesno孤立词识别kaldi脚本

    path.sh主要设定路径等 export KALDI_ROOT=`pwd`/../../.. [ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ ...

  9. Python文件中执行脚本注释和编码声明

    在 Python 脚本的第一行经常见到这样的注释: #!/usr/bin/env python3 或者 #!/usr/bin/python3 含义 在脚本中, 第一行以 #! 开头的代码, 在计算机行 ...

随机推荐

  1. 3Linux常用命令

    文件目录管理命令 1.touch touch 文件名   #创建空白文件 -a  修改读取(访问)时间atime -m  修改修改时间mtime -d  同时修改atime 和 mtime touch ...

  2. 20165304第4次实验《Android程序设计》实验报告

    一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:李松杨 学号:20165304 指导教师:娄嘉鹏 实验日期:2018年5月14日 实验时间:15:35 - 17:15 实验序号:实验 ...

  3. ecs主机被破解后下载的执行文件的脚本

    #!/bin/bashchmod 777 xiaochattr 777 haha/etc/init.d/iptables stop;service iptables stop;SuSEfirewall ...

  4. cmd创建文件命令

    一.建立空文件的几种方法 1.cd.>a.txt cd.表示改变当前目录为当前目录,即等于没改变:而且此命令不会有输出. >表示把命令输出写入到文件.后面跟着a.txt,就表示写入到a.t ...

  5. m3u8文件什么合成便于播放的MP4的方法

    先大家要知道M3U8文件不是一个视频文件,里面全是一些路径,说白了就是一个目录而已,所以要看视频,要找到对应存放视频的文件夹.如果不知道怎么找,可以使用文本格式打开M3U8文件,里面会有路径提示.   ...

  6. SVD及其在推荐系统中的作用

    本文先从几何意义上对奇异值分解SVD进行简单介绍,然后分析了特征值分解与奇异值分解的区别与联系,最后用python实现将SVD应用于推荐系统. 1.SVD详解 SVD(singular value d ...

  7. 飞鱼星、H3C企业路由器配置

    飞鱼星企业路由器配置外网访问IIS 只配置端口映射就行,配置好了,如果不立即重启,需要等几分钟才能生效 H3C路由器配置虚拟服务器即可

  8. OOm是否可以try catch ?

    只有在一种情况下,这样做是可行的: 在try语句中声明了很大的对象,导致OOM,并且可以确认OOM是由try语句中的对象声明导致的,那么在catch语句中,可以释放掉这些对象,解决OOM的问题,继续执 ...

  9. Linux-echo、cat命令详解(14)

    echo:显示一段文字 比如: echo hello,串口上就显示hello echo hello > /dev/tty1, LCD上便显示hello字段 cat:查看一个文件的内容 比如: c ...

  10. 28.Mysql权限与安全

    28.Mysql权限与安全28.1 Mysql权限管理 28.1.1 权限系统的工作原理对连接的用户进行身份认证,合法的用户通过认证,不合法的用户拒绝连接:对通过认证的合法用户赋予相应的权限,用户可以 ...