Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
5fddd288
P
Paddle
项目概览
wzpei9
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5fddd288
编写于
10月 10, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'feature/add_persistable_in_var_desc' into dev_opdesc_in_python
上级
a281b383
86451b30
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
76 addition
and
18 deletion
+76
-18
python/paddle/v2/framework/graph.py
python/paddle/v2/framework/graph.py
+76
-18
未找到文件。
python/paddle/v2/framework/graph.py
浏览文件 @
5fddd288
import
paddle.v2.framework.core
as
core
import
paddle.v2.framework.proto.framework_pb2
as
framework_pb2
import
collections
__all__
=
[
'Block'
,
'Variable'
,
'Program'
,
'Operator'
]
def
get_all_op_protos
():
"""
Get all registered op proto from PaddlePaddle C++ end.
:return: A list of registered OpProto.
"""
protostrs
=
core
.
get_all_op_protos
()
ret_values
=
[]
for
pbstr
in
protostrs
:
op_proto
=
framework_pb2
.
OpProto
.
FromString
(
str
(
pbstr
))
ret_values
.
append
(
op_proto
)
return
ret_values
class
OpProtoHolder
(
object
):
@
classmethod
def
instance
(
cls
):
if
not
hasattr
(
cls
,
'_instance'
):
cls
.
_instance
=
cls
()
return
cls
.
_instance
def
__init__
(
self
):
assert
not
hasattr
(
self
.
__class__
,
'_instance'
),
'Please use `instance()` to get OpProtoHolder opject!'
op_protos
=
get_all_op_protos
()
self
.
op_proto_map
=
{}
for
proto
in
op_protos
:
sefl
.
op_proto_map
[
proto
.
type
]
=
proto
def
get_op_proto
(
self
,
type
):
assert
type
in
self
.
op_proto_map
,
"Operator with type
\"
%s
\"
has not been registered."
%
type
return
self
.
op_proto_map
[
type
]
class
Variable
(
object
):
def
__init__
(
self
,
block
,
name
=
None
,
shape
=
None
,
dtype
=
None
,
lod_level
=
None
):
...
...
@@ -36,27 +71,50 @@ class Variable(object):
class
Operator
(
object
):
def
__init__
(
self
,
block
,
proto
,
type
=
None
,
inputs
=
None
,
outputs
=
None
,
def
__init__
(
self
,
block
,
desc
,
type
,
inputs
=
None
,
outputs
=
None
,
attrs
=
None
):
self
.
block
=
block
self
.
proto
=
proto
if
type
is
not
None
:
# TODO.
pass
self
.
desc
=
desc
self
.
proto
=
OpProtoHolder
.
instance
().
get_op_proto
(
type
)
self
.
desc
.
set_type
(
type
)
if
inputs
is
not
None
:
# TODO
pass
for
in_proto
in
self
.
proto
.
inputs
:
in_argus
=
inputs
[
in_proto
.
name
]
if
not
isinstance
(
in_argus
,
list
):
in_argus
=
[
in_argus
]
if
not
in_proto
.
duplicable
and
len
(
in_argus
)
>
1
:
raise
ValueError
(
"Input %s expects only one input, but %d are given."
%
(
in_proto
.
name
,
len
(
in_argus
)))
in_argu_names
=
[]
for
argu
in
in_argus
:
in_argu_names
.
append
(
argu
.
name
())
self
.
desc
.
set_input
(
in_proto
.
name
,
in_argu_names
)
if
outputs
is
not
None
:
# TODO
pass
for
out_proto
in
self
.
proto
.
outputs
:
out_argus
=
outputs
[
out_proto
.
name
]
if
not
isinstance
(
out_argus
,
list
):
out_argus
=
[
out_argus
]
if
not
out_proto
.
duplicable
and
len
(
out_argus
)
>
1
:
raise
ValueError
(
"Output %s expects only one output, but %d are given."
%
(
out_proto
.
name
,
len
(
out_argus
)))
out_argu_names
=
[]
for
argu
in
out_argus
:
out_argu_names
.
append
(
argu
.
name
())
self
.
desc
.
set_output
(
out_proto
.
name
,
out_argu_names
)
if
attrs
is
not
None
:
# TODO
pass
for
attr
in
self
.
proto
.
attrs
:
attr_name
=
attr
.
name
if
not
attr_name
in
attrs
:
continue
if
not
isinstance
(
attrs
[
attr_name
],
Block
):
self
.
desc
.
set_attr
(
attr_name
,
attrs
[
attr_name
])
else
:
self
.
desc
.
set_block_attr
(
attr_name
,
attrs
[
attr_name
].
desc
)
# TODO: Getters
...
...
@@ -80,8 +138,8 @@ class Block(object):
return
Variable
(
self
,
*
args
,
**
kwargs
)
def
append_op
(
self
,
*
args
,
**
kwargs
):
op_
proto
=
self
.
proto
.
append_op
()
op
=
Operator
(
self
,
op_
proto
,
*
args
,
**
kwargs
)
op_
desc
=
self
.
proto
.
append_op
()
op
=
Operator
(
self
,
op_
desc
,
*
args
,
**
kwargs
)
self
.
ops
.
append
(
op
)
return
op
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录