Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
d2a05df0
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看板
未验证
提交
d2a05df0
编写于
11月 21, 2021
作者:
H
Hui Zhang
提交者:
GitHub
11月 21, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1014 from Jackwaterveg/auto_log
[asr]hidden the auto_log
上级
13067281
fb6974f9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
66 addition
and
26 deletion
+66
-26
paddlespeech/s2t/exps/deepspeech2/bin/test_export.py
paddlespeech/s2t/exps/deepspeech2/bin/test_export.py
+2
-0
paddlespeech/s2t/exps/deepspeech2/model.py
paddlespeech/s2t/exps/deepspeech2/model.py
+64
-26
未找到文件。
paddlespeech/s2t/exps/deepspeech2/bin/test_export.py
浏览文件 @
d2a05df0
...
...
@@ -39,6 +39,8 @@ if __name__ == "__main__":
"--export_path"
,
type
=
str
,
help
=
"path of the jit model to save"
)
parser
.
add_argument
(
"--model_type"
,
type
=
str
,
default
=
'offline'
,
help
=
'offline/online'
)
parser
.
add_argument
(
"--enable-auto-log"
,
action
=
"store_true"
,
help
=
"use auto log"
)
args
=
parser
.
parse_args
()
print_arguments
(
args
,
globals
())
print
(
"model_type:{}"
.
format
(
args
.
model_type
))
...
...
paddlespeech/s2t/exps/deepspeech2/model.py
浏览文件 @
d2a05df0
...
...
@@ -42,7 +42,6 @@ from paddlespeech.s2t.training.trainer import Trainer
from
paddlespeech.s2t.utils
import
error_rate
from
paddlespeech.s2t.utils
import
layer_tools
from
paddlespeech.s2t.utils
import
mp_tools
from
paddlespeech.s2t.utils.log
import
Autolog
from
paddlespeech.s2t.utils.log
import
Log
from
paddlespeech.s2t.utils.utility
import
UpdateConfig
...
...
@@ -339,8 +338,6 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
error_rate_type
=
cfg
.
error_rate_type
)
def
compute_result_transcripts
(
self
,
audio
,
audio_len
,
vocab_list
,
cfg
):
self
.
autolog
.
times
.
start
()
self
.
autolog
.
times
.
stamp
()
result_transcripts
=
self
.
model
.
decode
(
audio
,
audio_len
,
...
...
@@ -354,19 +351,12 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
)
self
.
autolog
.
times
.
stamp
()
self
.
autolog
.
times
.
stamp
()
self
.
autolog
.
times
.
end
()
return
result_transcripts
@
mp_tools
.
rank_zero_only
@
paddle
.
no_grad
()
def
test
(
self
):
logger
.
info
(
f
"Test Total Examples:
{
len
(
self
.
test_loader
.
dataset
)
}
"
)
self
.
autolog
=
Autolog
(
batch_size
=
self
.
config
.
decoding
.
batch_size
,
model_name
=
"deepspeech2"
,
model_precision
=
"fp32"
).
getlog
()
self
.
model
.
eval
()
cfg
=
self
.
config
error_rate_type
=
None
...
...
@@ -390,7 +380,6 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
msg
+=
"Final error rate [%s] (%d/%d) = %f"
%
(
error_rate_type
,
num_ins
,
num_ins
,
errors_sum
/
len_refs
)
logger
.
info
(
msg
)
self
.
autolog
.
report
()
@
paddle
.
no_grad
()
def
export
(
self
):
...
...
@@ -414,6 +403,43 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester):
def
__init__
(
self
,
config
,
args
):
super
().
__init__
(
config
,
args
)
self
.
apply_static
=
True
self
.
args
=
args
@
mp_tools
.
rank_zero_only
@
paddle
.
no_grad
()
def
test
(
self
):
logger
.
info
(
f
"Test Total Examples:
{
len
(
self
.
test_loader
.
dataset
)
}
"
)
if
self
.
args
.
enable_auto_log
==
True
:
from
paddlespeech.s2t.utils.log
import
Autolog
self
.
autolog
=
Autolog
(
batch_size
=
self
.
config
.
decoding
.
batch_size
,
model_name
=
"deepspeech2"
,
model_precision
=
"fp32"
).
getlog
()
self
.
model
.
eval
()
cfg
=
self
.
config
error_rate_type
=
None
errors_sum
,
len_refs
,
num_ins
=
0.0
,
0
,
0
with
jsonlines
.
open
(
self
.
args
.
result_file
,
'w'
)
as
fout
:
for
i
,
batch
in
enumerate
(
self
.
test_loader
):
utts
,
audio
,
audio_len
,
texts
,
texts_len
=
batch
metrics
=
self
.
compute_metrics
(
utts
,
audio
,
audio_len
,
texts
,
texts_len
,
fout
)
errors_sum
+=
metrics
[
'errors_sum'
]
len_refs
+=
metrics
[
'len_refs'
]
num_ins
+=
metrics
[
'num_ins'
]
error_rate_type
=
metrics
[
'error_rate_type'
]
logger
.
info
(
"Error rate [%s] (%d/?) = %f"
%
(
error_rate_type
,
num_ins
,
errors_sum
/
len_refs
))
# logging
msg
=
"Test: "
msg
+=
"epoch: {}, "
.
format
(
self
.
epoch
)
msg
+=
"step: {}, "
.
format
(
self
.
iteration
)
msg
+=
"Final error rate [%s] (%d/%d) = %f"
%
(
error_rate_type
,
num_ins
,
num_ins
,
errors_sum
/
len_refs
)
logger
.
info
(
msg
)
if
self
.
args
.
enable_auto_log
==
True
:
self
.
autolog
.
report
()
def
compute_result_transcripts
(
self
,
audio
,
audio_len
,
vocab_list
,
cfg
):
if
self
.
args
.
model_type
==
"online"
:
...
...
@@ -486,8 +512,8 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester):
x_len_list
=
np
.
split
(
x_len_batch
,
batch_size
,
axis
=
0
)
for
x
,
x_len
in
zip
(
x_list
,
x_len_list
):
if
self
.
args
.
enable_auto_log
==
True
:
self
.
autolog
.
times
.
start
()
self
.
autolog
.
times
.
stamp
()
x_len
=
x_len
[
0
]
assert
(
chunk_size
<=
x_len
)
...
...
@@ -521,6 +547,10 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester):
probs_chunk_list
=
[]
probs_chunk_lens_list
=
[]
if
self
.
args
.
enable_auto_log
==
True
:
# record the model preprocessing time
self
.
autolog
.
times
.
stamp
()
for
i
in
range
(
0
,
num_chunk
):
start
=
i
*
chunk_stride
end
=
start
+
chunk_size
...
...
@@ -576,7 +606,10 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester):
[
output_probs
,
output_probs_padding
],
axis
=
1
)
output_probs_list
.
append
(
output_probs
)
output_lens_list
.
append
(
output_lens
)
if
self
.
args
.
enable_auto_log
==
True
:
# record the model inference time
self
.
autolog
.
times
.
stamp
()
# record the post processing time
self
.
autolog
.
times
.
stamp
()
self
.
autolog
.
times
.
end
()
output_probs
=
np
.
concatenate
(
output_probs_list
,
axis
=
0
)
...
...
@@ -608,10 +641,15 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester):
audio_len_handle
.
reshape
(
x_len
.
shape
)
audio_len_handle
.
copy_from_cpu
(
x_len
)
if
self
.
args
.
enable_auto_log
==
True
:
self
.
autolog
.
times
.
start
()
# record the prefix processing time
self
.
autolog
.
times
.
stamp
()
self
.
predictor
.
run
()
if
self
.
args
.
enable_auto_log
==
True
:
# record the model inference time
self
.
autolog
.
times
.
stamp
()
# record the post processing time
self
.
autolog
.
times
.
stamp
()
self
.
autolog
.
times
.
end
()
...
...
@@ -624,11 +662,11 @@ class DeepSpeech2ExportTester(DeepSpeech2Tester):
def
setup_model
(
self
):
super
().
setup_model
()
speedy
speech_config
=
inference
.
Config
(
deep
speech_config
=
inference
.
Config
(
self
.
args
.
export_path
+
".pdmodel"
,
self
.
args
.
export_path
+
".pdiparams"
)
if
(
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
].
strip
()
!=
''
):
speedy
speech_config
.
enable_use_gpu
(
100
,
0
)
speedy
speech_config
.
enable_memory_optim
()
speedyspeech_predictor
=
inference
.
create_predictor
(
speedy
speech_config
)
self
.
predictor
=
speedy
speech_predictor
deep
speech_config
.
enable_use_gpu
(
100
,
0
)
deep
speech_config
.
enable_memory_optim
()
deepspeech_predictor
=
inference
.
create_predictor
(
deep
speech_config
)
self
.
predictor
=
deep
speech_predictor
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录