Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
745df04f
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
1 年多 前同步成功
通知
207
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看板
提交
745df04f
编写于
7月 30, 2021
作者:
H
huangyuxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
complete the pipline of tiny
上级
6baf9f06
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
96 addition
and
29 deletion
+96
-29
deepspeech/exps/deepspeech2/bin/export.py
deepspeech/exps/deepspeech2/bin/export.py
+3
-1
deepspeech/exps/deepspeech2/bin/test.py
deepspeech/exps/deepspeech2/bin/test.py
+2
-1
deepspeech/exps/deepspeech2/bin/train.py
deepspeech/exps/deepspeech2/bin/train.py
+2
-1
deepspeech/exps/deepspeech2/config.py
deepspeech/exps/deepspeech2/config.py
+17
-7
deepspeech/exps/deepspeech2/model.py
deepspeech/exps/deepspeech2/model.py
+15
-9
examples/tiny/s0/local/export.sh
examples/tiny/s0/local/export.sh
+4
-3
examples/tiny/s0/local/test.sh
examples/tiny/s0/local/test.sh
+4
-2
examples/tiny/s0/local/train.sh
examples/tiny/s0/local/train.sh
+4
-2
examples/tiny/s0/run.sh
examples/tiny/s0/run.sh
+4
-3
examples/tiny/s0/run_online.sh
examples/tiny/s0/run_online.sh
+41
-0
未找到文件。
deepspeech/exps/deepspeech2/bin/export.py
浏览文件 @
745df04f
...
...
@@ -30,11 +30,13 @@ def main(config, args):
if
__name__
==
"__main__"
:
parser
=
default_argument_parser
()
parser
.
add_argument
(
"--model_type"
)
args
=
parser
.
parse_args
()
print_arguments
(
args
)
# https://yaml.org/type/float.html
config
=
get_cfg_defaults
()
config
=
get_cfg_defaults
(
args
.
model_type
)
if
args
.
config
:
config
.
merge_from_file
(
args
.
config
)
if
args
.
opts
:
...
...
deepspeech/exps/deepspeech2/bin/test.py
浏览文件 @
745df04f
...
...
@@ -30,11 +30,12 @@ def main(config, args):
if
__name__
==
"__main__"
:
parser
=
default_argument_parser
()
parser
.
add_argument
(
"--model_type"
)
args
=
parser
.
parse_args
()
print_arguments
(
args
,
globals
())
# https://yaml.org/type/float.html
config
=
get_cfg_defaults
()
config
=
get_cfg_defaults
(
args
.
model_type
)
if
args
.
config
:
config
.
merge_from_file
(
args
.
config
)
if
args
.
opts
:
...
...
deepspeech/exps/deepspeech2/bin/train.py
浏览文件 @
745df04f
...
...
@@ -35,11 +35,12 @@ def main(config, args):
if
__name__
==
"__main__"
:
parser
=
default_argument_parser
()
parser
.
add_argument
(
"--model_type"
)
args
=
parser
.
parse_args
()
print_arguments
(
args
,
globals
())
# https://yaml.org/type/float.html
config
=
get_cfg_defaults
()
config
=
get_cfg_defaults
(
args
.
model_type
)
if
args
.
config
:
config
.
merge_from_file
(
args
.
config
)
if
args
.
opts
:
...
...
deepspeech/exps/deepspeech2/config.py
浏览文件 @
745df04f
...
...
@@ -18,21 +18,31 @@ from deepspeech.exps.deepspeech2.model import DeepSpeech2Trainer
from
deepspeech.io.collator
import
SpeechCollator
from
deepspeech.io.dataset
import
ManifestDataset
from
deepspeech.models.ds2
import
DeepSpeech2Model
from
deepspeech.models.ds2_online
import
DeepSpeech2ModelOnline
_C
=
CfgNode
()
_C
.
data
=
ManifestDataset
.
params
()
def
get_cfg_defaults
(
model_type
):
_C
=
CfgNode
()
if
(
model_type
==
'offline'
):
_C
.
data
=
ManifestDataset
.
params
()
_C
.
collator
=
SpeechCollator
.
params
()
_C
.
collator
=
SpeechCollator
.
params
()
_C
.
model
=
DeepSpeech2Model
.
params
()
_C
.
model
=
DeepSpeech2Model
.
params
()
_C
.
training
=
DeepSpeech2Trainer
.
params
()
_C
.
training
=
DeepSpeech2Trainer
.
params
()
_C
.
decoding
=
DeepSpeech2Tester
.
params
()
_C
.
decoding
=
DeepSpeech2Tester
.
params
()
else
:
_C
.
data
=
ManifestDataset
.
params
()
_C
.
collator
=
SpeechCollator
.
params
()
def
get_cfg_defaults
():
_C
.
model
=
DeepSpeech2ModelOnline
.
params
()
_C
.
training
=
DeepSpeech2Trainer
.
params
()
_C
.
decoding
=
DeepSpeech2Tester
.
params
()
"""Get a yacs CfgNode object with default values for my_project."""
# Return a clone so that the defaults will not be altered
# This is for the "local variable" use pattern
...
...
deepspeech/exps/deepspeech2/model.py
浏览文件 @
745df04f
...
...
@@ -122,7 +122,7 @@ class DeepSpeech2Trainer(Trainer):
def
setup_model
(
self
):
config
=
self
.
config
if
config
.
model
.
apply_online
==
True
:
if
self
.
args
.
model_type
==
'offline'
:
model
=
DeepSpeech2Model
(
feat_size
=
self
.
train_loader
.
collate_fn
.
feature_size
,
dict_size
=
self
.
train_loader
.
collate_fn
.
vocab_size
,
...
...
@@ -131,7 +131,7 @@ class DeepSpeech2Trainer(Trainer):
rnn_size
=
config
.
model
.
rnn_layer_size
,
use_gru
=
config
.
model
.
use_gru
,
share_rnn_weights
=
config
.
model
.
share_rnn_weights
)
el
se
:
el
if
self
.
args
.
model_type
==
'online'
:
model
=
DeepSpeech2ModelOnline
(
feat_size
=
self
.
train_loader
.
collate_fn
.
feature_size
,
dict_size
=
self
.
train_loader
.
collate_fn
.
vocab_size
,
...
...
@@ -142,6 +142,8 @@ class DeepSpeech2Trainer(Trainer):
rnn_size
=
config
.
model
.
rnn_layer_size
,
use_gru
=
config
.
model
.
use_gru
,
share_rnn_weights
=
config
.
model
.
share_rnn_weights
)
else
:
raise
Exception
(
"wrong model type"
)
if
self
.
parallel
:
model
=
paddle
.
DataParallel
(
model
)
...
...
@@ -343,12 +345,14 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
exit
(
-
1
)
def
export
(
self
):
if
self
.
config
.
model
.
apply_online
==
True
:
if
self
.
args
.
model_type
==
'offline'
:
infer_model
=
DeepSpeech2InferModel
.
from_pretrained
(
self
.
test_loader
,
self
.
config
,
self
.
args
.
checkpoint_path
)
elif
self
.
args
.
model_type
==
'online'
:
infer_model
=
DeepSpeech2InferModelOnline
.
from_pretrained
(
self
.
test_loader
,
self
.
config
,
self
.
args
.
checkpoint_path
)
else
:
infer_model
=
DeepSpeech2InferModel
.
from_pretrained
(
self
.
test_loader
,
self
.
config
,
self
.
args
.
checkpoint_path
)
raise
Exception
(
"wrong model tyep"
)
infer_model
.
eval
()
feat_dim
=
self
.
test_loader
.
collate_fn
.
feature_size
...
...
@@ -386,7 +390,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
def
setup_model
(
self
):
config
=
self
.
config
if
config
.
model
.
apply_online
==
True
:
if
self
.
args
.
model_type
==
'offline'
:
model
=
DeepSpeech2Model
(
feat_size
=
self
.
test_loader
.
collate_fn
.
feature_size
,
dict_size
=
self
.
test_loader
.
collate_fn
.
vocab_size
,
...
...
@@ -395,10 +399,10 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
rnn_size
=
config
.
model
.
rnn_layer_size
,
use_gru
=
config
.
model
.
use_gru
,
share_rnn_weights
=
config
.
model
.
share_rnn_weights
)
el
se
:
el
if
self
.
args
.
model_type
==
'online'
:
model
=
DeepSpeech2ModelOnline
(
feat_size
=
self
.
t
rain
_loader
.
collate_fn
.
feature_size
,
dict_size
=
self
.
t
rain
_loader
.
collate_fn
.
vocab_size
,
feat_size
=
self
.
t
est
_loader
.
collate_fn
.
feature_size
,
dict_size
=
self
.
t
est
_loader
.
collate_fn
.
vocab_size
,
num_conv_layers
=
config
.
model
.
num_conv_layers
,
num_rnn_layers
=
config
.
model
.
num_rnn_layers
,
num_fc_layers
=
config
.
model
.
num_fc_layers
,
...
...
@@ -406,6 +410,8 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
rnn_size
=
config
.
model
.
rnn_layer_size
,
use_gru
=
config
.
model
.
use_gru
,
share_rnn_weights
=
config
.
model
.
share_rnn_weights
)
else
:
raise
Exception
(
"Wrong model type"
)
self
.
model
=
model
logger
.
info
(
"Setup model!"
)
...
...
examples/tiny/s0/local/export.sh
浏览文件 @
745df04f
#!/bin/bash
if
[
$#
!=
3
]
;
then
if
[
$#
!=
4
]
;
then
echo
"usage:
$0
config_path ckpt_prefix jit_model_path"
exit
-1
fi
...
...
@@ -11,6 +11,7 @@ echo "using $ngpu gpus..."
config_path
=
$1
ckpt_path_prefix
=
$2
jit_model_export_path
=
$3
model_type
=
$4
device
=
gpu
if
[
${
ngpu
}
==
0
]
;
then
...
...
@@ -22,8 +23,8 @@ python3 -u ${BIN_DIR}/export.py \
--nproc
${
ngpu
}
\
--config
${
config_path
}
\
--checkpoint_path
${
ckpt_path_prefix
}
\
--export_path
${
jit_model_export_path
}
--export_path
${
jit_model_export_path
}
\
--model_type
${
model_type
}
if
[
$?
-ne
0
]
;
then
echo
"Failed in export!"
...
...
examples/tiny/s0/local/test.sh
浏览文件 @
745df04f
#!/bin/bash
if
[
$#
!=
2
]
;
then
if
[
$#
!=
3
]
;
then
echo
"usage:
${
0
}
config_path ckpt_path_prefix"
exit
-1
fi
...
...
@@ -14,6 +14,7 @@ if [ ${ngpu} == 0 ];then
fi
config_path
=
$1
ckpt_prefix
=
$2
model_type
=
$3
# download language model
bash
local
/download_lm_en.sh
...
...
@@ -26,7 +27,8 @@ python3 -u ${BIN_DIR}/test.py \
--nproc
1
\
--config
${
config_path
}
\
--result_file
${
ckpt_prefix
}
.rsl
\
--checkpoint_path
${
ckpt_prefix
}
--checkpoint_path
${
ckpt_prefix
}
\
--model_type
${
model_type
}
if
[
$?
-ne
0
]
;
then
echo
"Failed in evaluation!"
...
...
examples/tiny/s0/local/train.sh
浏览文件 @
745df04f
#!/bin/bash
if
[
$#
!=
2
]
;
then
if
[
$#
!=
3
]
;
then
echo
"usage: CUDA_VISIBLE_DEVICES=0
${
0
}
config_path ckpt_name"
exit
-1
fi
...
...
@@ -10,6 +10,7 @@ echo "using $ngpu gpus..."
config_path
=
$1
ckpt_name
=
$2
model_type
=
$3
device
=
gpu
if
[
${
ngpu
}
==
0
]
;
then
...
...
@@ -22,7 +23,8 @@ python3 -u ${BIN_DIR}/train.py \
--device
${
device
}
\
--nproc
${
ngpu
}
\
--config
${
config_path
}
\
--output
exp/
${
ckpt_name
}
--output
exp/
${
ckpt_name
}
\
--model_type
${
model_type
}
if
[
$?
-ne
0
]
;
then
echo
"Failed in training!"
...
...
examples/tiny/s0/run.sh
浏览文件 @
745df04f
...
...
@@ -7,6 +7,7 @@ stage=0
stop_stage
=
100
conf_path
=
conf/deepspeech2.yaml
avg_num
=
1
model_type
=
online
source
${
MAIN_ROOT
}
/utils/parse_options.sh
||
exit
1
;
...
...
@@ -21,7 +22,7 @@ fi
if
[
${
stage
}
-le
1
]
&&
[
${
stop_stage
}
-ge
1
]
;
then
# train model, all `ckpt` under `exp` dir
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/train.sh
${
conf_path
}
${
ckpt
}
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/train.sh
${
conf_path
}
${
ckpt
}
${
model_type
}
fi
if
[
${
stage
}
-le
2
]
&&
[
${
stop_stage
}
-ge
2
]
;
then
...
...
@@ -31,10 +32,10 @@ fi
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
# test ckpt avg_n
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/test.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
||
exit
-1
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/test.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
${
model_type
}
||
exit
-1
fi
if
[
${
stage
}
-le
4
]
&&
[
${
stop_stage
}
-ge
4
]
;
then
# export ckpt avg_n
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/export.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
.jit
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/export.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
.jit
${
model_type
}
fi
examples/tiny/s0/run_online.sh
0 → 100755
浏览文件 @
745df04f
#!/bin/bash
set
-e
source
path.sh
gpus
=
7
stage
=
1
stop_stage
=
100
conf_path
=
conf/deepspeech2.yaml
avg_num
=
1
model_type
=
online
source
${
MAIN_ROOT
}
/utils/parse_options.sh
||
exit
1
;
avg_ckpt
=
avg_
${
avg_num
}
ckpt
=
$(
basename
${
conf_path
}
|
awk
-F
'.'
'{print $1}'
)
###ckpt = deepspeech2
echo
"checkpoint name
${
ckpt
}
"
if
[
${
stage
}
-le
0
]
&&
[
${
stop_stage
}
-ge
0
]
;
then
# prepare data
bash ./local/data.sh
||
exit
-1
fi
if
[
${
stage
}
-le
1
]
&&
[
${
stop_stage
}
-ge
1
]
;
then
# train model, all `ckpt` under `exp` dir
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/train.sh
${
conf_path
}
${
ckpt
}
${
model_type
}
fi
if
[
${
stage
}
-le
2
]
&&
[
${
stop_stage
}
-ge
2
]
;
then
# avg n best model
avg.sh exp/
${
ckpt
}
/checkpoints
${
avg_num
}
fi
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
# test ckpt avg_n
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/test.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
${
model_type
}
||
exit
-1
fi
if
[
${
stage
}
-le
4
]
&&
[
${
stop_stage
}
-ge
4
]
;
then
# export ckpt avg_n
CUDA_VISIBLE_DEVICES
=
${
gpus
}
./local/export.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
.jit
${
model_type
}
fi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录