Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
932889d9
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看板
未验证
提交
932889d9
编写于
9月 08, 2021
作者:
H
Hui Zhang
提交者:
GitHub
9月 08, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #815 from PaddlePaddle/timer
add timer
上级
75cd366d
c29ee83a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
15 deletion
+66
-15
deepspeech/training/timer.py
deepspeech/training/timer.py
+49
-0
deepspeech/training/trainer.py
deepspeech/training/trainer.py
+17
-15
未找到文件。
deepspeech/training/timer.py
0 → 100644
浏览文件 @
932889d9
# Copyright (c) 2021 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
datetime
import
time
from
deepspeech.utils.log
import
Log
__all__
=
[
"Timer"
]
logger
=
Log
(
__name__
).
getlog
()
class
Timer
():
"""To be used like this:
with Timer("Message") as value:
do some thing
"""
def
__init__
(
self
,
message
):
self
.
message
=
message
def
duration
(
self
)
->
str
:
elapsed_time
=
time
.
time
()
-
self
.
start
time_str
=
str
(
datetime
.
timedelta
(
seconds
=
elapsed_time
))
return
time_str
def
__enter__
(
self
):
self
.
start
=
time
.
time
()
return
self
def
__exit__
(
self
,
type
,
value
,
traceback
):
logger
.
info
(
self
.
message
.
format
(
self
.
duration
()))
def
__call__
(
self
)
->
float
:
return
time
.
time
()
-
self
.
start
def
__str__
(
self
):
return
self
.
duration
()
deepspeech/training/trainer.py
浏览文件 @
932889d9
...
@@ -18,6 +18,7 @@ import paddle
...
@@ -18,6 +18,7 @@ import paddle
from
paddle
import
distributed
as
dist
from
paddle
import
distributed
as
dist
from
tensorboardX
import
SummaryWriter
from
tensorboardX
import
SummaryWriter
from
deepspeech.training.timer
import
Timer
from
deepspeech.utils
import
mp_tools
from
deepspeech.utils
import
mp_tools
from
deepspeech.utils.checkpoint
import
Checkpoint
from
deepspeech.utils.checkpoint
import
Checkpoint
from
deepspeech.utils.log
import
Log
from
deepspeech.utils.log
import
Log
...
@@ -184,13 +185,14 @@ class Trainer():
...
@@ -184,13 +185,14 @@ class Trainer():
def
train
(
self
):
def
train
(
self
):
"""The training process control by epoch."""
"""The training process control by epoch."""
from_scratch
=
self
.
resume_or_scratch
()
with
Timer
(
"Load/Init Model: {}"
):
if
from_scratch
:
from_scratch
=
self
.
resume_or_scratch
()
# save init model, i.e. 0 epoch
if
from_scratch
:
self
.
save
(
tag
=
'init'
,
infos
=
None
)
# save init model, i.e. 0 epoch
self
.
lr_scheduler
.
step
(
self
.
epoch
)
self
.
save
(
tag
=
'init'
,
infos
=
None
)
if
self
.
parallel
and
hasattr
(
self
.
train_loader
,
"batch_sampler"
):
self
.
lr_scheduler
.
step
(
self
.
epoch
)
self
.
train_loader
.
batch_sampler
.
set_epoch
(
self
.
epoch
)
if
self
.
parallel
and
hasattr
(
self
.
train_loader
,
"batch_sampler"
):
self
.
train_loader
.
batch_sampler
.
set_epoch
(
self
.
epoch
)
logger
.
info
(
f
"Train Total Examples:
{
len
(
self
.
train_loader
.
dataset
)
}
"
)
logger
.
info
(
f
"Train Total Examples:
{
len
(
self
.
train_loader
.
dataset
)
}
"
)
while
self
.
epoch
<
self
.
config
.
training
.
n_epoch
:
while
self
.
epoch
<
self
.
config
.
training
.
n_epoch
:
...
@@ -240,14 +242,14 @@ class Trainer():
...
@@ -240,14 +242,14 @@ class Trainer():
"""The routine of the experiment after setup. This method is intended
"""The routine of the experiment after setup. This method is intended
to be used by the user.
to be used by the user.
"""
"""
try
:
with
Timer
(
"Training Done: {}"
)
:
self
.
train
()
try
:
except
KeyboardInterrupt
:
self
.
train
()
self
.
save
()
except
KeyboardInterrupt
:
exit
(
-
1
)
self
.
save
(
)
finally
:
exit
(
-
1
)
self
.
destory
()
finally
:
logger
.
info
(
"Training Done."
)
self
.
destory
(
)
def
setup_output_dir
(
self
):
def
setup_output_dir
(
self
):
"""Create a directory used for output.
"""Create a directory used for output.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录