test.sh 2.2 KB
Newer Older
H
Hui Zhang 已提交
1 2
#!/bin/bash

3 4 5 6 7 8 9 10 11 12 13 14 15 16
expdir=exp
datadir=data

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

17 18
if [ $# != 3 ];then
    echo "usage: ${0} config_path dict_path ckpt_path_prefix"
H
Hui Zhang 已提交
19 20 21 22 23 24 25
    exit -1
fi

ngpu=$(echo $CUDA_VISIBLE_DEVICES | awk -F "," '{print NF}')
echo "using $ngpu gpus..."

config_path=$1
26
dict=$2
27
ckpt_prefix=$3
H
Hui Zhang 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41

chunk_mode=false
if [[ ${config_path} =~ ^.*chunk_.*yaml$ ]];then
    chunk_mode=true
fi
echo "chunk mode ${chunk_mode}"


# download language model
#bash local/download_lm_en.sh
#if [ $? -ne 0 ]; then
#    exit 1
#fi

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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
H
Hui Zhang 已提交
60
        batch_size=1
61 62 63 64 65 66 67 68 69 70 71 72 73 74
        ${decode_cmd} JOB=1:${nj} ${expdir}/${decode_dir}/log/decode.JOB.log \
            python3 -u ${BIN_DIR}/test.py \
            --model-name u2_kaldi \
            --run-mode test \
            --nproc ${ngpu} \
            --dict-path ${dict} \
            --config ${config_path} \
            --checkpoint_path ${ckpt_prefix} \
            --result-file ${expdir}/${decode_dir}/data.JOB.json \
            --opts decoding.decoding_method ${dmethd} \
            --opts decoding.batch_size ${batch_size} \
            --opts data.test_manifest ${feat_recog_dir}/split${nj}/JOB/manifest.${rtask}

        score_sclite.sh --bpe ${nbpe} --bpemodel ${bpemodel}.model --wer true ${expdir}/${decode_dir} ${dict}
H
Hui Zhang 已提交
75

76 77 78 79 80
    ) &
    pids+=($!) # store background pids
    done
) &
pids+=($!) # store background pids
H
Hui Zhang 已提交
81 82
done

83 84 85
i=0; for pid in "${pids[@]}"; do wait ${pid} || ((++i)); done
[ ${i} -gt 0 ] && echo "$0: ${i} background jobs are failed." && false
echo "Finished"
H
Hui Zhang 已提交
86 87

exit 0