Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
暴走的小小菜鸟
Paddle
提交
e8483dde
P
Paddle
项目概览
暴走的小小菜鸟
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e8483dde
编写于
1月 10, 2018
作者:
R
ranqiu92
提交者:
GitHub
1月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7311 from ranqiu92/plot
Add script to plot learning curve
上级
6ecbf083
893a15f5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
114 addition
and
0 deletion
+114
-0
benchmark/paddle/image/plotlog.py
benchmark/paddle/image/plotlog.py
+114
-0
未找到文件。
benchmark/paddle/image/plotlog.py
0 → 100644
浏览文件 @
e8483dde
# Copyright (c) 2016 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
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
,
line_style
=
'b-'
,
line_label
=
'y'
,
line_num
=
1
):
plt
.
figure
()
plt
.
title
(
graph_title
)
if
line_num
==
1
:
plt
.
plot
(
batch_id
,
metric
,
line_style
,
label
=
line_label
)
else
:
for
i
in
range
(
line_num
):
plt
.
plot
(
batch_id
,
metric
[
i
],
line_style
[
i
],
label
=
line_label
[
i
])
plt
.
xlabel
(
'batch'
)
plt
.
ylabel
(
graph_title
)
plt
.
legend
()
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'
,
line_label
=
'loss'
)
plot_metric
(
accuracy_sample
,
batch_sample
,
'accuracy'
,
line_style
=
'g-'
,
line_label
=
'accuracy'
)
if
__name__
==
'__main__'
:
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录