run.sh 2.9 KB
Newer Older
H
Hui Zhang 已提交
1 2 3 4 5 6 7
#!/bin/bash

set -e

. path.sh

stage=0
8 9 10 11 12
stop_stage=50
tarfile=asr0_deepspeech2_online_wenetspeech_ckpt_1.0.2.model.tar.gz
#tarfile=asr0_deepspeech2_online_aishell_fbank161_ckpt_1.0.1.model.tar.gz
model_prefix=avg_10.jit
#model_prefix=avg_1.jit
H
Hui Zhang 已提交
13 14
model=${model_prefix}.pdmodel
param=${model_prefix}.pdiparams
H
Hui Zhang 已提交
15 16 17 18

. utils/parse_options.sh

data=data
H
Hui Zhang 已提交
19 20 21
exp=exp

mkdir -p $data $exp
H
Hui Zhang 已提交
22

H
Hui Zhang 已提交
23 24 25 26 27
dir=$data/exp/deepspeech2_online/checkpoints

# wenetspeech or aishell
model_type=$(echo $tarfile | cut -d '_' -f 4)

H
Hui Zhang 已提交
28
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ];then
H
Hui Zhang 已提交
29
    test -f $data/$tarfile || wget -P $data -c https://paddlespeech.bj.bcebos.com/s2t/$model_type/asr0/$tarfile
H
Hui Zhang 已提交
30

H
Hui Zhang 已提交
31
    # wenetspeech ds2 model
H
Hui Zhang 已提交
32
    pushd $data
H
Hui Zhang 已提交
33
    tar zxvf $tarfile 
H
Hui Zhang 已提交
34 35
    popd

H
Hui Zhang 已提交
36 37 38 39 40
    # ds2 model demo inputs
    pushd $exp
    wget -c http://paddlespeech.bj.bcebos.com/speechx/examples/ds2_ol/onnx/static_ds2online_inputs.pickle
    popd
fi
H
Hui Zhang 已提交
41

H
Hui Zhang 已提交
42 43
input_file=$exp/static_ds2online_inputs.pickle
test -e $input_file
H
Hui Zhang 已提交
44

45
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ];then
H
to onnx  
Hui Zhang 已提交
46
    # to onnx
H
Hui Zhang 已提交
47
   ./local/tonnx.sh $dir $model $param $exp/model.onnx
H
Hui Zhang 已提交
48

H
Hui Zhang 已提交
49
   ./local/infer_check.py --input_file $input_file --model_type $model_type --model_dir $dir --model_prefix $model_prefix --onnx_model $exp/model.onnx
H
Hui Zhang 已提交
50 51
fi

H
Hui Zhang 已提交
52

53
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ] ;then
54 55 56 57 58 59 60
    # ort graph optmize
    ./local/ort_opt.py --model_in $exp/model.onnx --opt_level 0 --model_out $exp/model.ort.opt.onnx

    ./local/infer_check.py --input_file $input_file --model_type $model_type  --model_dir $dir --model_prefix $model_prefix --onnx_model $exp/model.ort.opt.onnx
fi


61
if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ];then
H
Hui Zhang 已提交
62 63 64 65 66 67 68 69 70 71 72
    # convert opset_num to 11
    ./local/onnx_convert_opset.py --target-opset 11  --model-file $exp/model.ort.opt.onnx --save-model $exp/model.optset11.onnx 

    # quant model
    nodes_to_exclude='p2o.Conv.0,p2o.Conv.2'
    ./local/ort_dyanmic_quant.py --model-in $exp/model.optset11.onnx --model-out $exp/model.optset11.quant.onnx --nodes-to-exclude "${nodes_to_exclude}"

    ./local/infer_check.py --input_file $input_file --model_type $model_type  --model_dir $dir --model_prefix $model_prefix --onnx_model $exp/model.optset11.quant.onnx
fi


H
Hui Zhang 已提交
73 74 75 76 77 78 79 80 81 82 83
# aishell rnn hidden is 1024
# wenetspeech rnn hiddn is 2048
if [ $model_type == 'aishell' ];then
    input_shape="audio_chunk:1,-1,161  audio_chunk_lens:1 chunk_state_c_box:5,1,1024 chunk_state_h_box:5,1,1024"  
elif [ $model_type == 'wenetspeech' ];then
    input_shape="audio_chunk:1,-1,161  audio_chunk_lens:1 chunk_state_c_box:5,1,2048 chunk_state_h_box:5,1,2048"  
else
    echo "not support: $model_type"
    exit -1
fi

84 85

if [ ${stage} -le 51 ] && [ ${stop_stage} -ge 51 ] ;then
H
Hui Zhang 已提交
86
    # wenetspeech ds2 model execed 2GB limit, will error.
H
Hui Zhang 已提交
87
    # simplifying onnx model
H
Hui Zhang 已提交
88
    ./local/onnx_opt.sh $exp/model.onnx $exp/model.opt.onnx  "$input_shape"
H
Hui Zhang 已提交
89

H
Hui Zhang 已提交
90 91
    ./local/infer_check.py --input_file $input_file --model_type $model_type  --model_dir $dir --model_prefix $model_prefix --onnx_model $exp/model.opt.onnx
fi