Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
4e55315e
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
286
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4e55315e
编写于
6月 23, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add time computation
上级
dbad6f4c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
4 deletion
+87
-4
dygraph/train.py
dygraph/train.py
+26
-4
dygraph/utils/__init__.py
dygraph/utils/__init__.py
+1
-0
dygraph/utils/timer.py
dygraph/utils/timer.py
+60
-0
未找到文件。
dygraph/train.py
浏览文件 @
4e55315e
...
...
@@ -14,6 +14,7 @@
import
argparse
import
os
import
time
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
...
...
@@ -27,6 +28,7 @@ import utils.logging as logging
from
utils
import
get_environ_info
from
utils
import
load_pretrained_model
from
utils
import
resume
from
utils
import
Timer
,
calculate_eta
from
val
import
evaluate
...
...
@@ -111,6 +113,12 @@ def parse_args():
dest
=
'do_eval'
,
help
=
'Eval while training'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--log_steps'
,
dest
=
'log_steps'
,
help
=
'Display logging information at every log_steps'
,
default
=
10
,
type
=
int
)
return
parser
.
parse_args
()
...
...
@@ -126,6 +134,7 @@ def train(model,
pretrained_model
=
None
,
resume_model
=
None
,
save_interval_epochs
=
1
,
log_steps
=
10
,
num_classes
=
None
,
num_workers
=
8
):
ignore_index
=
model
.
ignore_index
...
...
@@ -156,6 +165,10 @@ def train(model,
return_list
=
True
,
)
timer
=
Timer
()
timer
.
start
()
steps_per_epoch
=
len
(
batch_sampler
)
avg_loss
=
0.0
for
epoch
in
range
(
start_epoch
,
num_epochs
):
for
step
,
data
in
enumerate
(
loader
):
images
=
data
[
0
]
...
...
@@ -170,11 +183,19 @@ def train(model,
loss
.
backward
()
optimizer
.
minimize
(
loss
)
model
.
clear_gradients
()
avg_loss
+=
loss
.
numpy
()
lr
=
optimizer
.
current_step_lr
()
logging
.
info
(
"[TRAIN] Epoch={}/{}, Step={}/{}, loss={}, lr={}"
.
format
(
epoch
+
1
,
num_epochs
,
step
+
1
,
len
(
batch_sampler
),
loss
.
numpy
(),
lr
))
if
step
%
log_steps
==
0
:
avg_loss
/=
log_steps
time_step
=
timer
.
elapsed_time
()
/
log_steps
remain_step
=
(
num_epochs
-
epoch
)
*
steps_per_epoch
-
step
+
1
logging
.
info
(
"[TRAIN] Epoch={}/{}, Step={}/{}, loss={:.4f}, lr={:.6f}, sec/step={:.4f} | ETA {}"
.
format
(
epoch
+
1
,
num_epochs
,
step
+
1
,
steps_per_epoch
,
avg_loss
,
lr
,
time_step
,
calculate_eta
(
remain_step
,
time_step
)))
avg_loss
=
0.0
timer
.
restart
()
if
((
epoch
+
1
)
%
save_interval_epochs
==
0
or
epoch
==
num_epochs
-
1
)
and
ParallelEnv
().
local_rank
==
0
:
...
...
@@ -260,6 +281,7 @@ def main(args):
pretrained_model
=
args
.
pretrained_model
,
resume_model
=
args
.
resume_model
,
save_interval_epochs
=
args
.
save_interval_epochs
,
log_steps
=
args
.
log_steps
,
num_classes
=
train_dataset
.
num_classes
,
num_workers
=
args
.
num_workers
)
...
...
dygraph/utils/__init__.py
浏览文件 @
4e55315e
...
...
@@ -16,3 +16,4 @@ from . import logging
from
.
import
download
from
.metrics
import
ConfusionMatrix
from
.utils
import
*
from
.timer
import
Timer
,
calculate_eta
dygraph/utils/timer.py
0 → 100644
浏览文件 @
4e55315e
# Copyright (c) 2020 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
time
class
Timer
(
object
):
""" Simple timer class for measuring time consuming """
def
__init__
(
self
):
self
.
_start_time
=
0.0
self
.
_end_time
=
0.0
self
.
_elapsed_time
=
0.0
self
.
_is_running
=
False
def
start
(
self
):
self
.
_is_running
=
True
self
.
_start_time
=
time
.
time
()
def
restart
(
self
):
self
.
start
()
def
stop
(
self
):
self
.
_is_running
=
False
self
.
_end_time
=
time
.
time
()
def
elapsed_time
(
self
):
self
.
_end_time
=
time
.
time
()
self
.
_elapsed_time
=
self
.
_end_time
-
self
.
_start_time
if
not
self
.
is_running
:
return
0.0
return
self
.
_elapsed_time
@
property
def
is_running
(
self
):
return
self
.
_is_running
def
calculate_eta
(
remaining_step
,
speed
):
if
remaining_step
<
0
:
remaining_step
=
0
remaining_time
=
int
(
remaining_step
*
speed
)
result
=
"{:0>2}:{:0>2}:{:0>2}"
arr
=
[]
for
i
in
range
(
2
,
-
1
,
-
1
):
arr
.
append
(
int
(
remaining_time
/
60
**
i
))
remaining_time
%=
60
**
i
return
result
.
format
(
*
arr
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录