Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
c087d20e
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c087d20e
编写于
8月 11, 2020
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify program
上级
96f9ba5f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
24 deletion
+28
-24
x2paddle/core/program.py
x2paddle/core/program.py
+28
-24
未找到文件。
x2paddle/core/program.py
浏览文件 @
c087d20e
...
...
@@ -16,7 +16,9 @@ from __future__ import print_function
from
__future__
import
division
import
paddle.fluid
as
fluid
from
paddle.fluid.proto
import
framework_pb2
from
collections
import
OrderedDict
import
numpy
import
time
import
collections
import
sys
import
os
...
...
@@ -49,19 +51,25 @@ class PaddleLayer(object):
self
.
inputs
=
inputs
self
.
outputs
=
outputs
self
.
attrs
=
kwargs
self
.
id
=
str
(
time
.
time
())
def
add_block
(
self
,
block
):
block
.
father_unique_id
=
self
.
unique_id
self
.
blocks
.
append
(
block
)
class
PaddleProgram
(
object
):
def
__init__
(
self
):
self
.
layers
=
lis
t
()
self
.
layers
=
OrderedDic
t
()
self
.
edges_out
=
dict
()
self
.
edges_in
=
dict
()
self
.
inputs
=
list
()
self
.
outputs
=
list
()
self
.
parameters
=
dict
()
self
.
father_layer_id
=
None
def
clear
(
self
):
self
.
layers
=
lis
t
()
self
.
layers
=
OrderedDic
t
()
self
.
edges_out
=
dict
()
self
.
edges_in
=
dict
()
self
.
inputs
=
list
()
...
...
@@ -70,13 +78,15 @@ class PaddleProgram(object):
def
add_layer
(
self
,
kernel
,
inputs
,
outputs
,
**
kwargs
):
layer
=
PaddleLayer
(
kernel
,
inputs
,
outputs
,
**
kwargs
)
index
=
len
(
self
.
layers
)
self
.
layers
.
append
(
layer
)
return
index
layer_id
=
str
(
len
(
self
.
layers
))
if
self
.
father_layer_id
is
not
None
:
layer_id
=
"{}.{}"
.
format
(
layer_id
,
self
.
father_layer_id
)
self
.
layers
[
layer_id
]
=
layer
return
layer_id
def
build
(
self
):
outputs_from_nodes
=
dict
()
for
i
,
layer
in
enumerate
(
self
.
layers
):
for
layer_id
,
layer
in
self
.
layers
.
items
(
):
for
input_key
,
input_var
in
layer
.
inputs
.
items
():
vs
=
input_var
if
not
isinstance
(
vs
,
list
):
...
...
@@ -84,22 +94,16 @@ class PaddleProgram(object):
for
v
in
vs
:
assert
v
in
outputs_from_nodes
,
"Couldn't find {} in previous layers, the layers should be make by topological sort"
.
format
(
v
)
in_layer_i
ndex
=
outputs_from_nodes
[
v
]
if
in_layer_i
ndex
not
in
self
.
edges_out
:
self
.
edges_out
[
in_layer_i
ndex
]
=
list
()
self
.
edges_out
[
in_layer_i
ndex
].
append
(
i
)
if
i
not
in
self
.
edges_in
:
self
.
edges_in
[
i
]
=
list
()
self
.
edges_in
[
i
].
append
(
in_layer_index
)
in_layer_i
d
=
outputs_from_nodes
[
v
]
if
in_layer_i
d
not
in
self
.
edges_out
:
self
.
edges_out
[
in_layer_i
d
]
=
list
()
self
.
edges_out
[
in_layer_i
d
].
append
(
layer_id
)
if
layer_id
not
in
self
.
edges_in
:
self
.
edges_in
[
layer_id
]
=
list
()
self
.
edges_in
[
layer_id
].
append
(
in_layer_id
)
for
output
in
layer
.
outputs
:
outputs_from_nodes
[
output
]
=
i
def
get_layer_outputs
(
self
,
i
):
return
self
.
edges_out
[
i
]
def
get_layer_inputs
(
self
,
i
):
return
self
.
edges_in
[
i
]
outputs_from_nodes
[
output
]
=
layer_id
def
gen_code
(
self
,
code_dir
):
def
write_code
(
f
,
code_list
,
indent
=
0
):
...
...
@@ -122,9 +126,9 @@ class PaddleProgram(object):
""
,
"def x2paddle_net():"
],
indent
=
0
)
for
i
,
layer
in
enumerate
(
self
.
layers
):
edges_in
=
self
.
edges_in
.
get
(
i
,
[])
edges_out
=
self
.
edges_out
.
get
(
i
,
[])
for
layer_id
,
layer
in
self
.
layers
.
items
(
):
edges_in
=
self
.
edges_in
.
get
(
layer_id
,
[])
edges_out
=
self
.
edges_out
.
get
(
layer_id
,
[])
if
len
(
edges_in
)
==
0
and
len
(
edges_out
)
==
0
:
continue
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录