Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e0c3a668
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
e0c3a668
编写于
11月 01, 2017
作者:
D
dzhwinter
提交者:
GitHub
11月 01, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"add net drawer for visualizing the graph" (#5292)
* "add net drawer for visualizing the graph" * "fix " * "add dep"
上级
0a32e74d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
110 addition
and
0 deletion
+110
-0
python/paddle/v2/framework/net_drawer.py
python/paddle/v2/framework/net_drawer.py
+109
-0
python/requirements.txt
python/requirements.txt
+1
-0
未找到文件。
python/paddle/v2/framework/net_drawer.py
0 → 100644
浏览文件 @
e0c3a668
import
argparse
import
json
import
logging
from
collections
import
defaultdict
import
paddle.v2.framework.core
as
core
import
paddle.v2.framework.proto.framework_pb2
as
framework_pb2
logger
=
logging
.
getLogger
(
__name__
)
logger
.
setLevel
(
logging
.
INFO
)
try
:
from
graphviz
import
Digraph
except
ImportError
:
logger
.
info
(
'Cannot import graphviz, which is required for drawing a network. This '
'can usually be installed in python with "pip install graphviz". Also, '
'pydot requires graphviz to convert dot files to pdf: in ubuntu, this '
'can usually be installed with "sudo apt-get install graphviz".'
)
print
(
'net_drawer will not run correctly. Please install the correct '
'dependencies.'
)
exit
(
0
)
OP_STYLE
=
{
'shape'
:
'oval'
,
'color'
:
'#0F9D58'
,
'style'
:
'filled'
,
'fontcolor'
:
'#FFFFFF'
}
VAR_STYLE
=
{}
GRAPH_STYLE
=
{
"rankdir"
:
"TB"
,
}
GRAPH_ID
=
0
def
unique_id
():
def
generator
():
GRAPH_ID
+=
1
return
GRAPH_ID
return
generator
def
draw_node
(
op
):
node
=
OP_STYLE
node
[
"name"
]
=
op
.
type
node
[
"label"
]
=
op
.
type
return
node
def
draw_edge
(
var_parent
,
op
,
var
,
arg
):
edge
=
VAR_STYLE
edge
[
"label"
]
=
"%s(%s)"
%
(
var
.
parameter
,
arg
)
edge
[
"head_name"
]
=
op
.
type
edge
[
"tail_name"
]
=
var_parent
[
arg
]
return
edge
def
parse_graph
(
program
,
graph
,
var_dict
,
**
kwargs
):
# fill the known variables
for
block
in
program
.
blocks
:
for
var
in
block
.
vars
:
if
not
var_dict
.
has_key
(
var
):
var_dict
[
var
]
=
"Feed"
proto
=
framework_pb2
.
ProgramDesc
.
FromString
(
program
.
desc
.
serialize_to_string
())
for
block
in
proto
.
blocks
:
for
op
in
block
.
ops
:
graph
.
node
(
**
draw_node
(
op
))
for
o
in
op
.
outputs
:
for
arg
in
o
.
arguments
:
var_dict
[
arg
]
=
op
.
type
for
e
in
op
.
inputs
:
for
arg
in
e
.
arguments
:
if
var_dict
.
has_key
(
arg
):
graph
.
edge
(
**
draw_edge
(
var_dict
,
op
,
e
,
arg
))
def
draw_graph
(
init_program
,
program
,
**
kwargs
):
if
kwargs
.
has_key
(
"graph_attr"
):
GRAPH_STYLE
.
update
(
kwargs
[
graph_attr
])
if
kwargs
.
has_key
(
"node_attr"
):
OP_STYLE
.
update
(
kwargs
[
node_attr
])
if
kwargs
.
has_key
(
"edge_attr"
):
VAR_STYLE
.
update
(
kwargs
[
edge_attr
])
graph_id
=
unique_id
()
filename
=
kwargs
.
get
(
"filename"
)
if
filename
==
None
:
filename
=
str
(
graph_id
)
+
".gv"
g
=
Digraph
(
name
=
str
(
graph_id
),
filename
=
filename
,
graph_attr
=
GRAPH_STYLE
,
node_attr
=
OP_STYLE
,
edge_attr
=
VAR_STYLE
,
**
kwargs
)
var_dict
=
{}
parse_graph
(
init_program
,
g
,
var_dict
)
parse_graph
(
program
,
g
,
var_dict
)
if
filename
!=
None
:
g
.
save
()
return
g
python/requirements.txt
浏览文件 @
e0c3a668
...
...
@@ -7,3 +7,4 @@ rarfile
scipy>=0.19.0
Pillow
nltk>=3.2.2
graphviz
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录