Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
路上走着呢
X2Paddle
提交
1d1bded2
X
X2Paddle
项目概览
路上走着呢
/
X2Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / X2Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1d1bded2
编写于
7月 21, 2020
作者:
J
jiangjiajun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add program
上级
ac63c094
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
137 addition
and
0 deletion
+137
-0
x2paddle/__init__.py
x2paddle/__init__.py
+16
-0
x2paddle/core/program.py
x2paddle/core/program.py
+121
-0
未找到文件。
x2paddle/__init__.py
浏览文件 @
1d1bded2
__version__
=
"0.7.4"
from
.core.program
import
PaddleProgram
program
=
PaddleProgram
()
name_counter
=
dict
()
def
gen_name
(
op_name
,
var_name
):
name
=
"{}.{}"
.
format
(
op_name
,
var_name
)
if
name
not
in
name_counter
:
name_counter
[
name
]
=
0
else
:
name_counter
[
name
]
+=
1
name
=
name
+
"."
+
str
(
name_counter
[
name
])
return
name
x2paddle/core/program.py
0 → 100644
浏览文件 @
1d1bded2
# Copyright (c) 2019 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.
from
__future__
import
print_function
from
__future__
import
division
import
collections
import
os
class
PaddleLayer
(
object
):
def
__init__
(
self
,
kernel
,
inputs
,
outputs
,
**
kwargs
):
assert
isinstance
(
inputs
,
dict
),
"parameter 'inputs' for PaddleLayer should be type of dict"
assert
isinstance
(
outputs
,
list
),
"parameter, 'outputs' for PaddleLayer should be type of list"
self
.
kernel
=
kernel
self
.
inputs
=
inputs
self
.
outputs
=
outputs
self
.
attrs
=
kwargs
class
PaddleProgram
(
object
):
def
__init__
(
self
):
self
.
layers
=
list
()
self
.
edges_out
=
dict
()
self
.
edges_in
=
dict
()
self
.
inputs
=
list
()
self
.
outputs
=
list
()
self
.
parameters
=
dict
()
def
add_layer
(
self
,
kernel
,
inputs
,
outputs
,
**
kwargs
):
layer
=
PaddleLayer
(
kernel
,
inputs
,
outputs
,
**
kwargs
)
self
.
layers
.
append
(
layer
)
def
build
(
self
):
outputs
=
dict
()
for
i
in
range
(
len
(
self
.
layers
)):
layer
=
self
.
layers
[
i
]
for
output
in
layer
.
outputs
:
outputs
[
output
]
=
i
for
k
,
v
in
layer
.
inputs
.
items
():
assert
v
in
outputs
,
"Couldn't find {} in previous layers, the layers should be make by topological sort"
.
format
(
v
)
in_layer_index
=
outputs
[
v
]
if
in_layer_index
not
in
self
.
edges_out
:
self
.
edges_out
[
in_layer_index
]
=
list
()
self
.
edges_out
[
in_layer_index
].
append
(
i
)
if
i
not
in
self
.
edges_in
:
self
.
edges_in
[
i
]
=
list
()
self
.
edges_in
[
i
].
append
(
in_layer_index
)
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
write_code
(
f
,
code_list
,
indent
=
0
):
indent_blank
=
" "
*
indent
for
code_line
in
code_list
:
if
code_line
.
strip
()
==
""
:
f
.
write
(
'
\n
'
)
else
:
f
.
write
(
indent_blank
+
code_line
+
'
\n
'
)
f
=
open
(
os
.
path
.
join
(
code_dir
,
'model.py'
),
'w'
)
write_code
(
f
,
[
"from paddle.fluid.initializer import Constant"
,
"from paddle.fluid.param_attr import ParamAttr"
,
"import paddle.fluid as fluid"
""
,
"def x2paddle_net():"
],
indent
=
0
)
for
i
,
layer
in
enumerate
(
self
.
layers
):
if
self
.
edges_in
.
get
(
i
,
0
)
==
0
and
self
.
edges_out
.
get
(
i
,
0
)
==
0
:
continue
line
=
""
if
len
(
layer
.
outputs
)
==
1
:
line
=
layer
.
outputs
[
0
]
else
:
for
output
in
layer
.
outputs
:
line
+=
"{}, "
.
format
(
output
)
line
=
line
.
strip
(
", "
)
line
+=
" = {}("
.
format
(
layer
.
kernel
)
for
k
,
v
in
layer
.
inputs
.
items
():
line
+=
"{}={}, "
.
format
(
k
,
v
)
for
k
,
v
in
layer
.
attrs
.
items
():
line
+=
"{}={}, "
.
format
(
k
,
v
)
line
=
line
.
strip
(
", "
)
line
+=
")"
write_code
(
f
,
[
line
],
indent
=
1
)
f
.
close
()
def
gen_parameters
(
self
,
code_dir
):
pass
def
gen_inference_model
(
self
,
model_dir
):
pass
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录