diff --git a/examples/librispeech/s1/local/test.sh b/examples/librispeech/s1/local/test.sh index 7f48d3d5152d2946ba5bee80926c2eaef4de4934..ceaa77cfa12b7a073391eaf7d6544f8cac884ced 100755 --- a/examples/librispeech/s1/local/test.sh +++ b/examples/librispeech/s1/local/test.sh @@ -11,14 +11,12 @@ lmtag= recog_set="test-clean test-other dev-clean dev-other" recog_set="test-clean" -# bpemode (unigram or bpe) -nbpe=5000 -bpemode=unigram -bpeprefix="data/bpe_${bpemode}_${nbpe}" -bpemodel=${bpeprefix}.model - -if [ $# != 3 ];then - echo "usage: ${0} config_path dict_path ckpt_path_prefix" + +stage=0 +stop_stage=100 + +if [ $# != 2 ];then + echo "usage: ${0} config_path ckpt_path_prefix" exit -1 fi @@ -26,8 +24,7 @@ ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}') echo "using $ngpu gpus..." config_path=$1 -dict=$2 -ckpt_prefix=$3 +ckpt_prefix=$2 chunk_mode=false if [[ ${config_path} =~ ^.*chunk_.*yaml$ ]];then @@ -42,46 +39,75 @@ echo "chunk mode ${chunk_mode}" # exit 1 #fi -pids=() # initialize pids - -for dmethd in attention ctc_greedy_search ctc_prefix_beam_search attention_rescoring; do -( - for rtask in ${recog_set}; do - ( - decode_dir=decode_${rtask}_${dmethd}_$(basename ${config_path%.*})_${lmtag} - feat_recog_dir=${datadir} - mkdir -p ${expdir}/${decode_dir} - mkdir -p ${feat_recog_dir} - - # split data - split_json.sh ${feat_recog_dir}/manifest.${rtask} ${nj} - #### use CPU for decoding - ngpu=0 - - # set batchsize 0 to disable batch decoding - batch_size=1 - ${decode_cmd} JOB=1:${nj} ${expdir}/${decode_dir}/log/decode.JOB.log \ - python3 -u ${BIN_DIR}/test.py \ +if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then + for type in attention; do + echo "decoding ${type}" + if [ ${chunk_mode} == true ];then + # stream decoding only support batchsize=1 + batch_size=1 + else + batch_size=64 + fi + python3 -u ${BIN_DIR}/test.py \ --nproc ${ngpu} \ --config ${config_path} \ - --result_file ${expdir}/${decode_dir}/data.JOB.json \ + --result_file ${ckpt_prefix}.${type}.rsl \ --checkpoint_path ${ckpt_prefix} \ - --opts decoding.decoding_method ${dmethd} \ - --opts decoding.batch_size ${batch_size} \ - --opts data.test_manifest ${feat_recog_dir}/split${nj}/JOB/manifest.${rtask} + --opts decoding.decoding_method ${type} \ + --opts decoding.batch_size ${batch_size} + + if [ $? -ne 0 ]; then + echo "Failed in evaluation!" + exit 1 + fi + echo "decoding ${type} done." + done +fi - score_sclite.sh --bpe ${nbpe} --bpemodel ${bpemodel}.model --wer true ${expdir}/${decode_dir} ${dict} +for type in ctc_greedy_search; do + echo "decoding ${type}" + if [ ${chunk_mode} == true ];then + # stream decoding only support batchsize=1 + batch_size=1 + else + batch_size=64 + fi + python3 -u ${BIN_DIR}/test.py \ + --nproc ${ngpu} \ + --config ${config_path} \ + --result_file ${ckpt_prefix}.${type}.rsl \ + --checkpoint_path ${ckpt_prefix} \ + --opts decoding.decoding_method ${type} \ + --opts decoding.batch_size ${batch_size} + + if [ $? -ne 0 ]; then + echo "Failed in evaluation!" + exit 1 + fi + echo "decoding ${type} done." +done - ) & - pids+=($!) # store background pids - done -) & -pids+=($!) # store background pids + + +for type in ctc_prefix_beam_search attention_rescoring; do + echo "decoding ${type}" + batch_size=1 + python3 -u ${BIN_DIR}/test.py \ + --nproc ${ngpu} \ + --config ${config_path} \ + --result_file ${ckpt_prefix}.${type}.rsl \ + --checkpoint_path ${ckpt_prefix} \ + --opts decoding.decoding_method ${type} \ + --opts decoding.batch_size ${batch_size} + + if [ $? -ne 0 ]; then + echo "Failed in evaluation!" + exit 1 + fi + echo "decoding ${type} done." done -i=0; for pid in "${pids[@]}"; do wait ${pid} || ((++i)); done -[ ${i} -gt 0 ] && echo "$0: ${i} background jobs are failed." && false echo "Finished" exit 0 diff --git a/examples/librispeech/s1/run.sh b/examples/librispeech/s1/run.sh index 8749039b774a9194752418b34ce9d8b2b621fb05..4c8bf514ec49141a4349f65774994023b2bb22eb 100755 --- a/examples/librispeech/s1/run.sh +++ b/examples/librispeech/s1/run.sh @@ -7,7 +7,7 @@ set -e stage=0 stop_stage=100 conf_path=conf/transformer.yaml -avg_num=5 +avg_num=30 . ${MAIN_ROOT}/utils/parse_options.sh || exit 1;