Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
2b8c08e3
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看板
未验证
提交
2b8c08e3
编写于
4月 21, 2022
作者:
H
Hui Zhang
提交者:
GitHub
4月 21, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1673 from Jackwaterveg/CER
[asr] Add new cer tools
上级
f39de8d7
8d1ee826
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
667 addition
and
566 deletion
+667
-566
examples/aishell/asr0/local/test.sh
examples/aishell/asr0/local/test.sh
+39
-10
examples/aishell/asr1/local/test.sh
examples/aishell/asr1/local/test.sh
+81
-42
examples/aishell/asr1/run.sh
examples/aishell/asr1/run.sh
+1
-1
paddlespeech/s2t/exps/deepspeech2/model.py
paddlespeech/s2t/exps/deepspeech2/model.py
+1
-1
utils/compute-wer.py
utils/compute-wer.py
+455
-512
utils/format_rsl.py
utils/format_rsl.py
+90
-0
未找到文件。
examples/aishell/asr0/local/test.sh
浏览文件 @
2b8c08e3
...
@@ -5,6 +5,8 @@ if [ $# != 4 ];then
...
@@ -5,6 +5,8 @@ if [ $# != 4 ];then
exit
-1
exit
-1
fi
fi
stage
=
0
stop_stage
=
100
ngpu
=
$(
echo
$CUDA_VISIBLE_DEVICES
|
awk
-F
","
'{print NF}'
)
ngpu
=
$(
echo
$CUDA_VISIBLE_DEVICES
|
awk
-F
","
'{print NF}'
)
echo
"using
$ngpu
gpus..."
echo
"using
$ngpu
gpus..."
...
@@ -19,18 +21,45 @@ if [ $? -ne 0 ]; then
...
@@ -19,18 +21,45 @@ if [ $? -ne 0 ]; then
exit
1
exit
1
fi
fi
python3
-u
${
BIN_DIR
}
/test.py
\
if
[
${
stage
}
-le
0
]
&&
[
${
stop_stage
}
-ge
0
]
;
then
--ngpu
${
ngpu
}
\
# format the reference test file
--config
${
config_path
}
\
python utils/format_rsl.py
\
--decode_cfg
${
decode_config_path
}
\
--origin_ref
data/manifest.test.raw
\
--result_file
${
ckpt_prefix
}
.rsl
\
--trans_ref
data/manifest.test.text
--checkpoint_path
${
ckpt_prefix
}
\
--model_type
${
model_type
}
if
[
$?
-ne
0
]
;
then
python3
-u
${
BIN_DIR
}
/test.py
\
echo
"Failed in evaluation!"
--ngpu
${
ngpu
}
\
exit
1
--config
${
config_path
}
\
--decode_cfg
${
decode_config_path
}
\
--result_file
${
ckpt_prefix
}
.rsl
\
--checkpoint_path
${
ckpt_prefix
}
\
--model_type
${
model_type
}
if
[
$?
-ne
0
]
;
then
echo
"Failed in evaluation!"
exit
1
fi
# format the hyp file
python utils/format_rsl.py
\
--origin_hyp
${
ckpt_prefix
}
.rsl
\
--trans_hyp
${
ckpt_prefix
}
.rsl.text
python utils/compute-wer.py
--char
=
1
--v
=
1
\
data/manifest.test.text
${
ckpt_prefix
}
.rsl.text
>
${
ckpt_prefix
}
.error
fi
fi
if
[
${
stage
}
-le
101
]
&&
[
${
stop_stage
}
-ge
101
]
;
then
python utils/format_rsl.py
\
--origin_ref
data/manifest.test.raw
\
--trans_ref_sclite
data/manifest.test.text.sclite
python utils/format_rsl.py
\
--origin_hyp
${
ckpt_prefix
}
.rsl
\
--trans_hyp_sclite
${
ckpt_prefix
}
.rsl.text.sclite
mkdir
-p
${
ckpt_prefix
}
_sclite
sclite
-i
wsj
-r
data/manifest.test.text.sclite
-h
${
ckpt_prefix
}
.rsl.text.sclite
-e
utf-8
-o
all
-O
${
ckpt_prefix
}
_sclite
-c
NOASCII
fi
exit
0
exit
0
examples/aishell/asr1/local/test.sh
浏览文件 @
2b8c08e3
...
@@ -5,6 +5,8 @@ if [ $# != 3 ];then
...
@@ -5,6 +5,8 @@ if [ $# != 3 ];then
exit
-1
exit
-1
fi
fi
stage
=
0
stop_stage
=
100
ngpu
=
$(
echo
$CUDA_VISIBLE_DEVICES
|
awk
-F
","
'{print NF}'
)
ngpu
=
$(
echo
$CUDA_VISIBLE_DEVICES
|
awk
-F
","
'{print NF}'
)
echo
"using
$ngpu
gpus..."
echo
"using
$ngpu
gpus..."
...
@@ -24,49 +26,86 @@ fi
...
@@ -24,49 +26,86 @@ fi
#fi
#fi
for
type
in
attention ctc_greedy_search
;
do
if
[
${
stage
}
-le
0
]
&&
[
${
stop_stage
}
-ge
0
]
;
then
echo
"decoding
${
type
}
"
# format the reference test file
if
[
${
chunk_mode
}
==
true
]
;
then
python utils/format_rsl.py
\
# stream decoding only support batchsize=1
--origin_ref
data/manifest.test.raw
\
--trans_ref
data/manifest.test.text
for
type
in
attention ctc_greedy_search
;
do
echo
"decoding
${
type
}
"
if
[
${
chunk_mode
}
==
true
]
;
then
# stream decoding only support batchsize=1
batch_size
=
1
else
batch_size
=
64
fi
output_dir
=
${
ckpt_prefix
}
mkdir
-p
${
output_dir
}
python3
-u
${
BIN_DIR
}
/test.py
\
--ngpu
${
ngpu
}
\
--config
${
config_path
}
\
--decode_cfg
${
decode_config_path
}
\
--result_file
${
output_dir
}
/
${
type
}
.rsl
\
--checkpoint_path
${
ckpt_prefix
}
\
--opts
decode.decoding_method
${
type
}
\
--opts
decode.decode_batch_size
${
batch_size
}
if
[
$?
-ne
0
]
;
then
echo
"Failed in evaluation!"
exit
1
fi
# format the hyp file
python utils/format_rsl.py
\
--origin_hyp
${
output_dir
}
/
${
type
}
.rsl
\
--trans_hyp
${
output_dir
}
/
${
type
}
.rsl.text
python utils/compute-wer.py
--char
=
1
--v
=
1
\
data/manifest.test.text
${
output_dir
}
/
${
type
}
.rsl.text
>
${
output_dir
}
/
${
type
}
.error
done
for
type
in
ctc_prefix_beam_search attention_rescoring
;
do
echo
"decoding
${
type
}
"
batch_size
=
1
batch_size
=
1
else
output_dir
=
${
ckpt_prefix
}
batch_size
=
64
mkdir
-p
${
output_dir
}
fi
python3
-u
${
BIN_DIR
}
/test.py
\
output_dir
=
${
ckpt_prefix
}
--ngpu
${
ngpu
}
\
mkdir
-p
${
output_dir
}
--config
${
config_path
}
\
python3
-u
${
BIN_DIR
}
/test.py
\
--decode_cfg
${
decode_config_path
}
\
--ngpu
${
ngpu
}
\
--result_file
${
output_dir
}
/
${
type
}
.rsl
\
--config
${
config_path
}
\
--checkpoint_path
${
ckpt_prefix
}
\
--decode_cfg
${
decode_config_path
}
\
--opts
decode.decoding_method
${
type
}
\
--result_file
${
output_dir
}
/
${
type
}
.rsl
\
--opts
decode.decode_batch_size
${
batch_size
}
--checkpoint_path
${
ckpt_prefix
}
\
--opts
decode.decoding_method
${
type
}
\
if
[
$?
-ne
0
]
;
then
--opts
decode.decode_batch_size
${
batch_size
}
echo
"Failed in evaluation!"
exit
1
if
[
$?
-ne
0
]
;
then
fi
echo
"Failed in evaluation!"
python utils/format_rsl.py
\
exit
1
--origin_hyp
${
output_dir
}
/
${
type
}
.rsl
fi
--trans_hyp
${
output_dir
}
/
${
type
}
.rsl.text
done
python utils/compute-wer.py
--char
=
1
--v
=
1
\
data/manifest.test.text
${
output_dir
}
/
${
type
}
.rsl.text
>
${
output_dir
}
/
${
type
}
.error
for
type
in
ctc_prefix_beam_search attention_rescoring
;
do
done
echo
"decoding
${
type
}
"
fi
batch_size
=
1
if
[
${
stage
}
-le
101
]
&&
[
${
stop_stage
}
-ge
101
]
;
then
# format the reference test file for sclite
python utils/format_rsl.py
\
--origin_ref
data/manifest.test.raw
\
--trans_ref_sclite
data/manifest.test.text.sclite
output_dir
=
${
ckpt_prefix
}
output_dir
=
${
ckpt_prefix
}
mkdir
-p
${
output_dir
}
for
type
in
attention ctc_greedy_search ctc_prefix_beam_search attention_rescoring
;
do
python3
-u
${
BIN_DIR
}
/test.py
\
python utils/format_rsl.py
\
--ngpu
${
ngpu
}
\
--origin_hyp
${
output_dir
}
/
${
type
}
.rsl
--config
${
config_path
}
\
--trans_hyp_sclite
${
output_dir
}
/
${
type
}
.rsl.text.sclite
--decode_cfg
${
decode_config_path
}
\
--result_file
${
output_dir
}
/
${
type
}
.rsl
\
mkdir
-p
${
output_dir
}
/
${
type
}
_sclite
--checkpoint_path
${
ckpt_prefix
}
\
sclite
-i
wsj
-r
data/manifest.test.text.sclite
-h
${
output_dir
}
/
${
type
}
.rsl.text.sclite
-e
utf-8
-o
all
-O
${
output_dir
}
/
${
type
}
_sclite
-c
NOASCII
--opts
decode.decoding_method
${
type
}
\
done
--opts
decode.decode_batch_size
${
batch_size
}
fi
if
[
$?
-ne
0
]
;
then
echo
"Failed in evaluation!"
exit
1
fi
done
exit
0
exit
0
examples/aishell/asr1/run.sh
浏览文件 @
2b8c08e3
...
@@ -7,7 +7,7 @@ stage=0
...
@@ -7,7 +7,7 @@ stage=0
stop_stage
=
50
stop_stage
=
50
conf_path
=
conf/conformer.yaml
conf_path
=
conf/conformer.yaml
decode_conf_path
=
conf/tuning/decode.yaml
decode_conf_path
=
conf/tuning/decode.yaml
avg_num
=
2
0
avg_num
=
3
0
audio_file
=
data/demo_01_03.wav
audio_file
=
data/demo_01_03.wav
source
${
MAIN_ROOT
}
/utils/parse_options.sh
||
exit
1
;
source
${
MAIN_ROOT
}
/utils/parse_options.sh
||
exit
1
;
...
...
paddlespeech/s2t/exps/deepspeech2/model.py
浏览文件 @
2b8c08e3
...
@@ -278,7 +278,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
...
@@ -278,7 +278,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
len_refs
+=
len_ref
len_refs
+=
len_ref
num_ins
+=
1
num_ins
+=
1
if
fout
:
if
fout
:
fout
.
write
({
"utt"
:
utt
,
"ref
"
:
target
,
"hyp"
:
result
})
fout
.
write
({
"utt"
:
utt
,
"ref
s"
:
[
target
],
"hyps"
:
[
result
]
})
logger
.
info
(
f
"Utt:
{
utt
}
"
)
logger
.
info
(
f
"Utt:
{
utt
}
"
)
logger
.
info
(
f
"Ref:
{
target
}
"
)
logger
.
info
(
f
"Ref:
{
target
}
"
)
logger
.
info
(
f
"Hyp:
{
result
}
"
)
logger
.
info
(
f
"Hyp:
{
result
}
"
)
...
...
utils/compute-wer.py
浏览文件 @
2b8c08e3
此差异已折叠。
点击以展开。
utils/format_rsl.py
0 → 100644
浏览文件 @
2b8c08e3
import
os
import
argparse
import
jsonlines
def
trans_hyp
(
origin_hyp
,
trans_hyp
=
None
,
trans_hyp_sclite
=
None
):
"""
Args:
origin_hyp: The input json file which contains the model output
trans_hyp: The output file for caculate CER/WER
trans_hyp_sclite: The output file for caculate CER/WER using sclite
"""
input_dict
=
{}
with
open
(
origin_hyp
,
"r+"
,
encoding
=
"utf8"
)
as
f
:
for
item
in
jsonlines
.
Reader
(
f
):
input_dict
[
item
[
"utt"
]]
=
item
[
"hyps"
][
0
]
if
trans_hyp
is
not
None
:
with
open
(
trans_hyp
,
"w+"
,
encoding
=
"utf8"
)
as
f
:
for
key
in
input_dict
.
keys
():
f
.
write
(
key
+
" "
+
input_dict
[
key
]
+
"
\n
"
)
if
trans_hyp_sclite
is
not
None
:
with
open
(
trans_hyp_sclite
,
"w+"
)
as
f
:
for
key
in
input_dict
.
keys
():
line
=
input_dict
[
key
]
+
"("
+
key
+
".wav"
+
")"
+
"
\n
"
f
.
write
(
line
)
def
trans_ref
(
origin_ref
,
trans_ref
=
None
,
trans_ref_sclite
=
None
):
"""
Args:
origin_hyp: The input json file which contains the model output
trans_hyp: The output file for caculate CER/WER
trans_hyp_sclite: The output file for caculate CER/WER using sclite
"""
input_dict
=
{}
with
open
(
origin_ref
,
"r"
,
encoding
=
"utf8"
)
as
f
:
for
item
in
jsonlines
.
Reader
(
f
):
input_dict
[
item
[
"utt"
]]
=
item
[
"text"
]
if
trans_ref
is
not
None
:
with
open
(
trans_ref
,
"w"
,
encoding
=
"utf8"
)
as
f
:
for
key
in
input_dict
.
keys
():
f
.
write
(
key
+
" "
+
input_dict
[
key
]
+
"
\n
"
)
if
trans_ref_sclite
is
not
None
:
with
open
(
trans_ref_sclite
,
"w"
)
as
f
:
for
key
in
input_dict
.
keys
():
line
=
input_dict
[
key
]
+
"("
+
key
+
".wav"
+
")"
+
"
\n
"
f
.
write
(
line
)
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
prog
=
'format hyp file for compute CER/WER'
,
add_help
=
True
)
parser
.
add_argument
(
'--origin_hyp'
,
type
=
str
,
default
=
None
,
help
=
'origin hyp file'
)
parser
.
add_argument
(
'--trans_hyp'
,
type
=
str
,
default
=
None
,
help
=
'hyp file for caculating CER/WER'
)
parser
.
add_argument
(
'--trans_hyp_sclite'
,
type
=
str
,
default
=
None
,
help
=
'hyp file for caculating CER/WER by sclite'
)
parser
.
add_argument
(
'--origin_ref'
,
type
=
str
,
default
=
None
,
help
=
'origin ref file'
)
parser
.
add_argument
(
'--trans_ref'
,
type
=
str
,
default
=
None
,
help
=
'ref file for caculating CER/WER'
)
parser
.
add_argument
(
'--trans_ref_sclite'
,
type
=
str
,
default
=
None
,
help
=
'ref file for caculating CER/WER by sclite'
)
parser_args
=
parser
.
parse_args
()
if
parser_args
.
origin_hyp
is
not
None
:
trans_hyp
(
origin_hyp
=
parser_args
.
origin_hyp
,
trans_hyp
=
parser_args
.
trans_hyp
,
trans_hyp_sclite
=
parser_args
.
trans_hyp_sclite
,
)
if
parser_args
.
origin_ref
is
not
None
:
trans_ref
(
origin_ref
=
parser_args
.
origin_ref
,
trans_ref
=
parser_args
.
trans_ref
,
trans_ref_sclite
=
parser_args
.
trans_ref_sclite
,
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录