run.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env bash
  2. . ./path.sh || exit 1;
  3. # machines configuration
  4. CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7"
  5. gpu_num=8
  6. count=1
  7. gpu_inference=true # Whether to perform gpu decoding, set false for cpu decoding
  8. # for gpu decoding, inference_nj=ngpu*njob; for cpu decoding, inference_nj=njob
  9. njob=5
  10. train_cmd=utils/run.pl
  11. infer_cmd=utils/run.pl
  12. # general configuration
  13. feats_dir="../DATA" #feature output dictionary
  14. exp_dir="."
  15. lang=zh
  16. token_type=char
  17. type=sound
  18. scp=wav.scp
  19. speed_perturb="0.9 1.0 1.1"
  20. stage=0
  21. stop_stage=5
  22. # feature configuration
  23. feats_dim=80
  24. nj=64
  25. # data
  26. raw_data=/nfs/zhifu.gzf/wenetspeech_proc
  27. # exp tag
  28. tag="exp1"
  29. . utils/parse_options.sh || exit 1;
  30. # Set bash to 'debug' mode, it will exit on :
  31. # -e 'error', -u 'undefined variable', -o ... 'error in pipeline', -x 'print commands',
  32. set -e
  33. set -u
  34. set -o pipefail
  35. set=L
  36. train_set=train_l
  37. valid_set=dev
  38. test_sets="dev test_net test_meeting"
  39. asr_config=conf/train_asr_conformer.yaml
  40. model_dir="baseline_$(basename "${asr_config}" .yaml)_${lang}_${token_type}_${tag}"
  41. inference_config=conf/decode_asr_transformer_5beam.yaml
  42. inference_asr_model=valid.acc.ave_10best.pb
  43. # you can set gpu num for decoding here
  44. gpuid_list=$CUDA_VISIBLE_DEVICES # set gpus for decoding, the same as training stage by default
  45. ngpu=$(echo $gpuid_list | awk -F "," '{print NF}')
  46. if ${gpu_inference}; then
  47. inference_nj=$[${ngpu}*${njob}]
  48. _ngpu=1
  49. else
  50. inference_nj=$njob
  51. _ngpu=0
  52. fi
  53. if [ ${stage} -le -1 ] && [ ${stop_stage} -ge -1 ]; then
  54. echo "For downloading data, please refer to https://github.com/wenet-e2e/WenetSpeech."
  55. exit 0;
  56. fi
  57. if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
  58. echo "stage 0: Data preparation"
  59. # Data preparation
  60. # local/data.sh --set ${set} --nj $nj --data_dir $feats_dir --WENETSPEECH $raw_data --train_cmd $train_cmd
  61. mkdir $feats_dir/data
  62. mv $feats_dir/$train_set $feats_dir/data/$train_set
  63. for x in $test_sets; do
  64. mv $feats_dir/$x $feats_dir/data/
  65. done
  66. fi
  67. if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
  68. echo "stage 1: Feature and CMVN Generation"
  69. utils/compute_cmvn.sh --fbankdir ${feats_dir}/data/${train_set} --cmd "$train_cmd" --nj $nj --feats_dim ${feats_dim} --config_file "$asr_config" --scale 0.1
  70. fi
  71. token_list=${feats_dir}/data/${lang}_token_list/$token_type/tokens.txt
  72. echo "dictionary: ${token_list}"
  73. if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
  74. echo "stage 2: Dictionary Preparation"
  75. mkdir -p ${feats_dir}/data/${lang}_token_list/$token_type/
  76. echo "make a dictionary"
  77. echo "<blank>" > ${token_list}
  78. echo "<s>" >> ${token_list}
  79. echo "</s>" >> ${token_list}
  80. utils/text2token.py -s 1 -n 1 --space "" ${feats_dir}/data/$train_set/text | cut -f 2- -d" " | tr " " "\n" \
  81. | sort | uniq | grep -a -v -e '^\s*$' | awk '{print $0}' >> ${token_list}
  82. echo "<unk>" >> ${token_list}
  83. fi