Skip to content

Commit

Permalink
Merge pull request #2116 from zh794390558/onnx
Browse files Browse the repository at this point in the history
[speechx]remove fluid tools for onnx export
  • Loading branch information
zh794390558 authored Jul 5, 2022
2 parents 8817bf8 + a9a3cb4 commit 803fec2
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 326 deletions.
111 changes: 0 additions & 111 deletions speechx/examples/ds2_ol/onnx/local/pd_infer_shape.py

This file was deleted.

158 changes: 0 additions & 158 deletions speechx/examples/ds2_ol/onnx/local/pd_prune_model.py

This file was deleted.

23 changes: 0 additions & 23 deletions speechx/examples/ds2_ol/onnx/local/prune.sh

This file was deleted.

37 changes: 3 additions & 34 deletions speechx/examples/ds2_ol/onnx/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,26 @@ if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ];then
popd
fi

output_names=softmax_0.tmp_0,tmp_5,concat_0.tmp_0,concat_1.tmp_0
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ];then
# prune model by outputs
mkdir -p $exp/prune

# prune model deps on output_names.
./local/prune.sh $dir $model $param $output_names $exp/prune
fi

# aishell rnn hidden is 1024
# wenetspeech rnn hiddn is 2048
if [ $model_type == 'aishell' ];then
input_shape_dict="{'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_dict="{'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
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ];then
# infer shape by new shape
mkdir -p $exp/shape
echo $input_shape_dict
python3 local/pd_infer_shape.py \
--model_dir $dir \
--model_filename $model \
--params_filename $param \
--save_dir $exp/shape \
--input_shape_dict="${input_shape_dict}"
fi

input_file=$exp/static_ds2online_inputs.pickle
test -e $input_file

if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ];then
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ];then
# to onnx
./local/tonnx.sh $dir $model $param $exp/model.onnx

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


if [ ${stage} -le 4 ] && [ ${stop_stage} -ge 4 ] ;then
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ] ;then
# 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


if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ];then
if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ];then
# 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

Expand Down

0 comments on commit 803fec2

Please sign in to comment.