Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
0d7d65d2
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0d7d65d2
编写于
9月 23, 2020
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Calculate and print the average time for video models.
上级
93c4daa4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
9 deletion
+54
-9
PaddleCV/video/utils/timer.py
PaddleCV/video/utils/timer.py
+33
-0
PaddleCV/video/utils/train_utils.py
PaddleCV/video/utils/train_utils.py
+21
-9
未找到文件。
PaddleCV/video/utils/timer.py
0 → 100644
浏览文件 @
0d7d65d2
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# 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
TimeAverager
(
object
):
def
__init__
(
self
):
self
.
reset
()
def
reset
(
self
):
self
.
_cnt
=
0
self
.
_total_time
=
0
def
record
(
self
,
usetime
):
self
.
_cnt
+=
1
self
.
_total_time
+=
usetime
def
get_average
(
self
):
if
self
.
_cnt
==
0
:
return
0
return
self
.
_total_time
/
self
.
_cnt
PaddleCV/video/utils/train_utils.py
浏览文件 @
0d7d65d2
...
...
@@ -19,6 +19,7 @@ import numpy as np
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid
import
profiler
from
utils.timer
import
TimeAverager
import
logging
import
shutil
...
...
@@ -82,29 +83,40 @@ def train_with_dataloader(exe, train_prog, compiled_train_prog, train_dataloader
is_profiler
=
None
,
profiler_path
=
None
):
if
not
train_dataloader
:
logger
.
error
(
"[TRAIN] get dataloader failed."
)
epoch_periods
=
[]
train_loss
=
0
epoch_periods
=
[]
reader_cost_averager
=
TimeAverager
()
batch_cost_averager
=
TimeAverager
()
for
epoch
in
range
(
epochs
):
log_lr_and_step
()
train_iter
=
0
epoch_periods
=
[]
cur_time
=
time
.
time
()
batch_start
=
time
.
time
()
for
data
in
train_dataloader
():
reader_cost_averager
.
record
(
time
.
time
()
-
batch_start
)
train_outs
=
exe
.
run
(
compiled_train_prog
,
fetch_list
=
train_fetch_list
,
feed
=
data
)
period
=
time
.
time
()
-
cur_time
epoch_periods
.
append
(
period
)
timeStamp
=
time
.
time
()
localTime
=
time
.
localtime
(
timeStamp
)
strTime
=
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
,
localTime
)
batch_cost
=
time
.
time
()
-
batch_start
epoch_periods
.
append
(
batch_cost
)
batch_cost_averager
.
record
(
batch_cost
)
local_time
=
time
.
localtime
(
time
.
time
())
str_time
=
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
,
local_time
)
if
log_interval
>
0
and
(
train_iter
%
log_interval
==
0
):
train_metrics
.
calculate_and_log_out
(
train_outs
,
\
info
=
'[TRAIN {}] Epoch {}, iter {}, time {}, '
.
format
(
strTime
,
epoch
,
train_iter
,
period
))
info
=
'[TRAIN {}] Epoch {}, iter {}, batch_cost {:.5}, reader_cost {:.5}'
.
format
(
str_time
,
epoch
,
train_iter
,
batch_cost_averager
.
get_average
(),
reader_cost_averager
.
get_average
()))
reader_cost_averager
.
reset
()
batch_cost_averager
.
reset
()
train_iter
+=
1
cur_time
=
time
.
time
()
batch_start
=
time
.
time
()
# NOTE: profiler tools, used for benchmark
if
is_profiler
and
epoch
==
0
and
train_iter
==
log_interval
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录