Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
afaac789
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
afaac789
编写于
10月 10, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine code
上级
906f5e8a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
37 deletion
+36
-37
python/paddle/v2/framework/graph.py
python/paddle/v2/framework/graph.py
+34
-34
python/paddle/v2/framework/tests/test_operator_desc.py
python/paddle/v2/framework/tests/test_operator_desc.py
+2
-3
未找到文件。
python/paddle/v2/framework/graph.py
浏览文件 @
afaac789
...
...
@@ -7,40 +7,6 @@ import copy
__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
:
self
.
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
,
...
...
@@ -141,6 +107,40 @@ class Variable(object):
raise
ValueError
(
"Not supported numpy dtype "
+
str
(
dtype
))
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
:
self
.
op_proto_map
[
proto
.
type
]
=
proto
def
get_op_proto
(
self
,
type
):
assert
type
in
self
.
op_proto_map
,
"Operator
\"
%s
\"
has not been registered."
%
type
return
self
.
op_proto_map
[
type
]
class
Operator
(
object
):
def
__init__
(
self
,
block
,
desc
,
type
,
inputs
=
None
,
outputs
=
None
,
attrs
=
None
):
...
...
python/paddle/v2/framework/tests/test_operator_desc.py
浏览文件 @
afaac789
...
...
@@ -10,9 +10,8 @@ class TestOperator(unittest.TestCase):
block
.
append_op
(
type
=
"no_such_op"
)
self
.
assertFail
()
except
AssertionError
as
err
:
self
.
assertEqual
(
err
.
message
,
"Operator with type
\"
no_such_op
\"
has not been registered."
)
self
.
assertEqual
(
err
.
message
,
"Operator
\"
no_such_op
\"
has not been registered."
)
def
test_op_desc_creation
(
self
):
block
=
g_program
.
current_block
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录