Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
99c82466
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看板
提交
99c82466
编写于
9月 28, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add the script to parse tuning log
上级
89dd9ae4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
102 addition
and
0 deletion
+102
-0
deep_speech_2/tools/parse_tuning_log.py
deep_speech_2/tools/parse_tuning_log.py
+102
-0
未找到文件。
deep_speech_2/tools/parse_tuning_log.py
0 → 100644
浏览文件 @
99c82466
"""Parse the log for tuning and plot error surface."""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
re
import
numpy
as
np
import
argparse
import
functools
import
_init_paths
from
utils.utility
import
add_arguments
,
print_arguments
import
matplotlib.pyplot
as
plt
from
mpl_toolkits.mplot3d
import
Axes3D
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
add_arg
(
"log_path"
,
str
,
''
,
"log path for parsing"
)
add_arg
(
"fig_name"
,
str
,
'error_surface.png'
,
"name of output figure"
)
args
=
parser
.
parse_args
()
def
plot_error_surface
(
num_alphas
,
alphas
,
betas
,
error_rate_type
,
err_ave
):
fig
=
plt
.
figure
(
figsize
=
(
8
,
6
))
ax
=
Axes3D
(
fig
)
num_betas
=
len
(
alphas
)
//
num_alphas
alphas_2d
=
np
.
reshape
(
alphas
,
(
num_alphas
,
num_betas
))
betas_2d
=
np
.
reshape
(
betas
,
(
num_alphas
,
num_betas
))
err_ave_2d
=
np
.
reshape
(
err_ave
,
(
num_alphas
,
num_betas
))
ax
.
plot_surface
(
alphas_2d
,
betas_2d
,
err_ave_2d
,
rstride
=
1
,
cstride
=
1
,
alpha
=
0.8
,
cmap
=
'rainbow'
)
z_label
=
'WER'
if
error_rate_type
==
'wer'
else
'CER'
ax
.
set_xlabel
(
'alpha'
,
fontsize
=
12
)
ax
.
set_ylabel
(
'beta'
,
fontsize
=
12
)
ax
.
set_zlabel
(
z_label
,
fontsize
=
12
)
plt
.
savefig
(
args
.
fig_name
)
plt
.
show
()
def
parse_log
():
if
not
os
.
path
.
isfile
(
args
.
log_path
):
raise
IOError
(
"Invaid model path: %s"
%
args
.
log_path
)
error_rate_type
=
None
num_alphas
,
num_betas
=
0
,
0
alphas
,
betas
,
err_ave
=
[],
[],
[]
err_rate_pat
=
re
.
compile
(
'\(alpha, beta\) = '
'\([-+]?\d+(?:\.\d+)?, [-+]?\d+(?:\.\d+)?\), \[[wcer]'
)
num_pat
=
re
.
compile
(
r
'[-+]?\d+(?:\.\d+)?'
)
with
open
(
args
.
log_path
,
"r"
)
as
log_file
:
line
=
log_file
.
readline
()
while
line
:
if
line
.
find
(
"error_rate_type:"
)
!=
-
1
:
error_rate_type
=
line
.
strip
().
split
()[
1
]
elif
line
.
find
(
"num_alphas:"
)
!=
-
1
:
num_alphas
=
int
(
line
.
strip
().
split
()[
1
])
elif
line
.
find
(
"num_betas:"
)
!=
-
1
:
num_betas
=
int
(
line
.
strip
().
split
()[
1
])
elif
err_rate_pat
.
match
(
line
)
is
not
None
:
tuples
=
num_pat
.
findall
(
line
)
alphas
.
append
(
float
(
tuples
[
0
]))
betas
.
append
(
float
(
tuples
[
1
]))
err_ave
.
append
(
float
(
tuples
[
2
]))
line
=
log_file
.
readline
()
if
error_rate_type
==
None
:
raise
ValueError
(
"Illegal log format, cannot find error_rate_type"
)
if
num_alphas
<=
0
:
raise
ValueError
(
"Illegal log format, invalid num_alphas"
)
if
num_betas
<=
0
:
raise
ValueError
(
"Illegal log format, invalid num_betas"
)
if
alphas
==
[]:
raise
ValueError
(
"Illegal log format, cannot find grid search result"
)
if
num_alphas
*
num_betas
!=
len
(
alphas
):
raise
ValueError
(
"Illegal log format, data's shape mismatches"
)
return
num_alphas
,
alphas
,
betas
,
error_rate_type
,
err_ave
,
def
main
():
print_arguments
(
args
)
num_alphas
,
alphas
,
betas
,
error_rate_type
,
err_ave
=
parse_log
()
plot_error_surface
(
num_alphas
,
alphas
,
betas
,
error_rate_type
,
err_ave
)
if
__name__
==
'__main__'
:
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录