Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
20764265
P
Paddle
项目概览
PaddlePaddle
/
Paddle
12 个月 前同步成功
通知
2292
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
20764265
编写于
1月 08, 2018
作者:
R
ranqiu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add script to plot learning curve
上级
e8a96a8e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
87 addition
and
0 deletion
+87
-0
benchmark/paddle/image/plotlog.py
benchmark/paddle/image/plotlog.py
+87
-0
未找到文件。
benchmark/paddle/image/plotlog.py
0 → 100644
浏览文件 @
20764265
#coding=utf-8
import
sys
import
argparse
import
matplotlib.pyplot
as
plt
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
'Parse Log'
)
parser
.
add_argument
(
'--file_path'
,
'-f'
,
type
=
str
,
help
=
'the path of the log file'
)
parser
.
add_argument
(
'--sample_rate'
,
'-s'
,
type
=
float
,
default
=
1.0
,
help
=
'the rate to take samples from log'
)
parser
.
add_argument
(
'--log_period'
,
'-p'
,
type
=
int
,
default
=
1
,
help
=
'the period of log'
)
args
=
parser
.
parse_args
()
return
args
def
parse_file
(
file_name
):
loss
=
[]
error
=
[]
with
open
(
file_name
)
as
f
:
for
i
,
line
in
enumerate
(
f
):
line
=
line
.
strip
()
if
not
line
.
startswith
(
'pass'
):
continue
line_split
=
line
.
split
(
' '
)
if
len
(
line_split
)
!=
5
:
continue
loss_str
=
line_split
[
2
][:
-
1
]
cur_loss
=
float
(
loss_str
.
split
(
'='
)[
-
1
])
loss
.
append
(
cur_loss
)
err_str
=
line_split
[
3
][:
-
1
]
cur_err
=
float
(
err_str
.
split
(
'='
)[
-
1
])
error
.
append
(
cur_err
)
accuracy
=
[
1.0
-
err
for
err
in
error
]
return
loss
,
accuracy
def
sample
(
metric
,
sample_rate
):
interval
=
int
(
1.0
/
sample_rate
)
if
interval
>
len
(
metric
):
return
metric
[:
1
]
num
=
len
(
metric
)
/
interval
idx
=
[
interval
*
i
for
i
in
range
(
num
)]
metric_sample
=
[
metric
[
id
]
for
id
in
idx
]
return
metric_sample
def
plot_metric
(
metric
,
batch_id
,
graph_title
):
plt
.
figure
()
plt
.
title
(
graph_title
)
plt
.
plot
(
batch_id
,
metric
)
plt
.
xlabel
(
'batch'
)
plt
.
ylabel
(
graph_title
)
plt
.
savefig
(
graph_title
+
'.jpg'
)
plt
.
close
()
def
main
():
args
=
parse_args
()
assert
args
.
sample_rate
>
0.
and
args
.
sample_rate
<=
1.0
,
"The sample rate should in the range (0, 1]."
loss
,
accuracy
=
parse_file
(
args
.
file_path
)
batch
=
[
args
.
log_period
*
i
for
i
in
range
(
len
(
loss
))]
batch_sample
=
sample
(
batch
,
args
.
sample_rate
)
loss_sample
=
sample
(
loss
,
args
.
sample_rate
)
accuracy_sample
=
sample
(
accuracy
,
args
.
sample_rate
)
plot_metric
(
loss_sample
,
batch_sample
,
'loss'
)
plot_metric
(
accuracy_sample
,
batch_sample
,
'accuracy'
)
if
__name__
==
'__main__'
:
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录