Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
5b6f11fd
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看板
未验证
提交
5b6f11fd
编写于
8月 11, 2020
作者:
S
SunAhong1993
提交者:
GitHub
8月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6 from PaddlePaddle/develop_jason
Develop jason
上级
96f9ba5f
23ba3b50
变更
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
浏览文件 @
5b6f11fd
...
@@ -16,7 +16,9 @@ from __future__ import print_function
...
@@ -16,7 +16,9 @@ from __future__ import print_function
from
__future__
import
division
from
__future__
import
division
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid.proto
import
framework_pb2
from
paddle.fluid.proto
import
framework_pb2
from
collections
import
OrderedDict
import
numpy
import
numpy
import
time
import
collections
import
collections
import
sys
import
sys
import
os
import
os
...
@@ -49,19 +51,25 @@ class PaddleLayer(object):
...
@@ -49,19 +51,25 @@ class PaddleLayer(object):
self
.
inputs
=
inputs
self
.
inputs
=
inputs
self
.
outputs
=
outputs
self
.
outputs
=
outputs
self
.
attrs
=
kwargs
self
.
attrs
=
kwargs
self
.
id
=
str
(
time
.
time
())
def
add_block
(
self
,
block
):
block
.
father_layer
=
self
self
.
blocks
.
append
(
block
)
class
PaddleProgram
(
object
):
class
PaddleProgram
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
layers
=
lis
t
()
self
.
layers
=
OrderedDic
t
()
self
.
edges_out
=
dict
()
self
.
edges_out
=
dict
()
self
.
edges_in
=
dict
()
self
.
edges_in
=
dict
()
self
.
inputs
=
list
()
self
.
inputs
=
list
()
self
.
outputs
=
list
()
self
.
outputs
=
list
()
self
.
parameters
=
dict
()
self
.
parameters
=
dict
()
self
.
father_layer
=
None
def
clear
(
self
):
def
clear
(
self
):
self
.
layers
=
lis
t
()
self
.
layers
=
OrderedDic
t
()
self
.
edges_out
=
dict
()
self
.
edges_out
=
dict
()
self
.
edges_in
=
dict
()
self
.
edges_in
=
dict
()
self
.
inputs
=
list
()
self
.
inputs
=
list
()
...
@@ -70,13 +78,15 @@ class PaddleProgram(object):
...
@@ -70,13 +78,15 @@ class PaddleProgram(object):
def
add_layer
(
self
,
kernel
,
inputs
,
outputs
,
**
kwargs
):
def
add_layer
(
self
,
kernel
,
inputs
,
outputs
,
**
kwargs
):
layer
=
PaddleLayer
(
kernel
,
inputs
,
outputs
,
**
kwargs
)
layer
=
PaddleLayer
(
kernel
,
inputs
,
outputs
,
**
kwargs
)
index
=
len
(
self
.
layers
)
layer_id
=
str
(
len
(
self
.
layers
))
self
.
layers
.
append
(
layer
)
if
self
.
father_layer
is
not
None
:
return
index
layer_id
=
"{}.{}.{}"
.
format
(
layer_id
,
len
(
self
.
father_layer
.
blocks
()),
self
.
father_layer
.
id
)
self
.
layers
[
layer_id
]
=
layer
return
layer_id
def
build
(
self
):
def
build
(
self
):
outputs_from_nodes
=
dict
()
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
():
for
input_key
,
input_var
in
layer
.
inputs
.
items
():
vs
=
input_var
vs
=
input_var
if
not
isinstance
(
vs
,
list
):
if
not
isinstance
(
vs
,
list
):
...
@@ -84,22 +94,16 @@ class PaddleProgram(object):
...
@@ -84,22 +94,16 @@ class PaddleProgram(object):
for
v
in
vs
:
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
(
assert
v
in
outputs_from_nodes
,
"Couldn't find {} in previous layers, the layers should be make by topological sort"
.
format
(
v
)
v
)
in_layer_i
ndex
=
outputs_from_nodes
[
v
]
in_layer_i
d
=
outputs_from_nodes
[
v
]
if
in_layer_i
ndex
not
in
self
.
edges_out
:
if
in_layer_i
d
not
in
self
.
edges_out
:
self
.
edges_out
[
in_layer_i
ndex
]
=
list
()
self
.
edges_out
[
in_layer_i
d
]
=
list
()
self
.
edges_out
[
in_layer_i
ndex
].
append
(
i
)
self
.
edges_out
[
in_layer_i
d
].
append
(
layer_id
)
if
i
not
in
self
.
edges_in
:
if
layer_id
not
in
self
.
edges_in
:
self
.
edges_in
[
i
]
=
list
()
self
.
edges_in
[
layer_id
]
=
list
()
self
.
edges_in
[
i
].
append
(
in_layer_index
)
self
.
edges_in
[
layer_id
].
append
(
in_layer_id
)
for
output
in
layer
.
outputs
:
for
output
in
layer
.
outputs
:
outputs_from_nodes
[
output
]
=
i
outputs_from_nodes
[
output
]
=
layer_id
def
get_layer_outputs
(
self
,
i
):
return
self
.
edges_out
[
i
]
def
get_layer_inputs
(
self
,
i
):
return
self
.
edges_in
[
i
]
def
gen_code
(
self
,
code_dir
):
def
gen_code
(
self
,
code_dir
):
def
write_code
(
f
,
code_list
,
indent
=
0
):
def
write_code
(
f
,
code_list
,
indent
=
0
):
...
@@ -122,9 +126,9 @@ class PaddleProgram(object):
...
@@ -122,9 +126,9 @@ class PaddleProgram(object):
""
,
"def x2paddle_net():"
""
,
"def x2paddle_net():"
],
],
indent
=
0
)
indent
=
0
)
for
i
,
layer
in
enumerate
(
self
.
layers
):
for
layer_id
,
layer
in
self
.
layers
.
items
(
):
edges_in
=
self
.
edges_in
.
get
(
i
,
[])
edges_in
=
self
.
edges_in
.
get
(
layer_id
,
[])
edges_out
=
self
.
edges_out
.
get
(
i
,
[])
edges_out
=
self
.
edges_out
.
get
(
layer_id
,
[])
if
len
(
edges_in
)
==
0
and
len
(
edges_out
)
==
0
:
if
len
(
edges_in
)
==
0
and
len
(
edges_out
)
==
0
:
continue
continue
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录