Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
17a96cd6
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 2 年 前同步成功
通知
210
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
17a96cd6
编写于
6月 14, 2022
作者:
H
Hui Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pd ort infer check
上级
c90be853
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
92 addition
and
1 deletion
+92
-1
speechx/examples/ds2_ol/onnx/local/infer_check.py
speechx/examples/ds2_ol/onnx/local/infer_check.py
+86
-0
speechx/examples/ds2_ol/onnx/run.sh
speechx/examples/ds2_ol/onnx/run.sh
+6
-1
未找到文件。
speechx/examples/ds2_ol/onnx/local/infer_check.py
0 → 100755
浏览文件 @
17a96cd6
#!/usr/bin/env python3
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
argparse
import
numpy
as
np
import
onnxruntime
import
paddle
import
os
import
pickle
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
parser
.
add_argument
(
'--input_file'
,
type
=
str
,
default
=
"static_ds2online_inputs.pickle"
,
help
=
"ds2 input pickle file."
,
)
parser
.
add_argument
(
'--model_dir'
,
type
=
str
,
default
=
"."
,
help
=
"paddle model dir."
)
parser
.
add_argument
(
'--onnx_model'
,
type
=
str
,
default
=
'./model.old.onnx'
,
help
=
"onnx model."
)
return
parser
.
parse_args
()
if
__name__
==
'__main__'
:
FLAGS
=
parse_args
()
# input and output
with
open
(
FLAGS
.
input_file
,
'rb'
)
as
f
:
iodict
=
pickle
.
load
(
f
)
print
(
iodict
.
keys
())
audio_chunk
=
iodict
[
'audio_chunk'
]
audio_chunk_lens
=
iodict
[
'audio_chunk_lens'
]
chunk_state_h_box
=
iodict
[
'chunk_state_h_box'
]
chunk_state_c_box
=
iodict
[
'chunk_state_c_bos'
]
# paddle
model
=
paddle
.
jit
.
load
(
os
.
path
.
join
(
FLAGS
.
model_dir
,
"avg_1.jit"
))
res_chunk
,
res_lens
,
chunk_state_h
,
chunk_state_c
=
model
(
paddle
.
to_tensor
(
audio_chunk
),
paddle
.
to_tensor
(
audio_chunk_lens
),
paddle
.
to_tensor
(
chunk_state_h_box
),
paddle
.
to_tensor
(
chunk_state_c_box
),
)
# onnxruntime
options
=
onnxruntime
.
SessionOptions
()
options
.
enable_profiling
=
True
sess
=
onnxruntime
.
InferenceSession
(
FLAGS
.
onnx_model
,
sess_options
=
options
)
ort_res_chunk
,
ort_res_lens
,
ort_chunk_state_h
,
ort_chunk_state_c
=
sess
.
run
(
[
'softmax_0.tmp_0'
,
'tmp_5'
,
'concat_0.tmp_0'
,
'concat_1.tmp_0'
],
{
"audio_chunk"
:
audio_chunk
,
"audio_chunk_lens"
:
audio_chunk_lens
,
"chunk_state_h_box"
:
chunk_state_h_box
,
"chunk_state_c_box"
:
chunk_state_c_box
})
print
(
sess
.
end_profiling
())
# assert paddle equal ort
print
(
np
.
allclose
(
ort_res_chunk
,
res_chunk
,
atol
=
1e-6
))
print
(
np
.
allclose
(
ort_res_lens
,
res_lens
,
atol
=
1e-6
))
print
(
np
.
allclose
(
ort_chunk_state_h
,
chunk_state_h
,
atol
=
1e-6
))
print
(
np
.
allclose
(
ort_chunk_state_c
,
chunk_state_c
,
atol
=
1e-6
))
\ No newline at end of file
speechx/examples/ds2_ol/onnx/run.sh
浏览文件 @
17a96cd6
...
@@ -22,10 +22,12 @@ if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ];then
...
@@ -22,10 +22,12 @@ if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ];then
popd
popd
fi
fi
dir
=
$data
/exp/deepspeech2_online/checkpoints
dir
=
$data
/exp/deepspeech2_online/checkpoints
model
=
avg_1.jit.pdmodel
model
=
avg_1.jit.pdmodel
param
=
avg_1.jit.pdiparams
param
=
avg_1.jit.pdiparams
output_names
=
softmax_0.tmp_0,tmp_5,concat_0.tmp_0,concat_1.tmp_0
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
if
[
${
stage
}
-le
1
]
&&
[
${
stop_stage
}
-ge
1
]
;
then
# prune model by outputs
# prune model by outputs
...
@@ -47,7 +49,10 @@ if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ];then
...
@@ -47,7 +49,10 @@ if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ];then
--input_shape_dict
=
${
input_shape_dict
}
--input_shape_dict
=
${
input_shape_dict
}
fi
fi
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
# to onnx
# to onnx
./local/tonnx.sh
$dir
$model
$param
$exp
/model.onnx
./local/tonnx.sh
$dir
$model
$param
$exp
/model.onnx
fi
./local/infer_check.py
--input_file
'static_ds2online_inputs.pickle'
--model_dir
$dir
--onnx_model
$exp
/model.onnx
\ No newline at end of file
fi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录