Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
d5291340
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
12 个月 前同步成功
通知
692
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d5291340
编写于
7月 19, 2017
作者:
Y
Yu Yang
提交者:
GitHub
7月 19, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2947 from reyoung/feature/add_op_test
Feature/add op test
上级
e8304bd9
3402b6ad
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
1 deletion
+72
-1
python/paddle/v2/framework/create_op_creation_methods.py
python/paddle/v2/framework/create_op_creation_methods.py
+4
-0
python/paddle/v2/framework/tests/CMakeLists.txt
python/paddle/v2/framework/tests/CMakeLists.txt
+1
-1
python/paddle/v2/framework/tests/op_test_util.py
python/paddle/v2/framework/tests/op_test_util.py
+50
-0
python/paddle/v2/framework/tests/test_add_two_op.py
python/paddle/v2/framework/tests/test_add_two_op.py
+17
-0
未找到文件。
python/paddle/v2/framework/create_op_creation_methods.py
浏览文件 @
d5291340
...
...
@@ -217,6 +217,10 @@ def create_op_creation_method(op_proto):
return
core
.
Operator
.
create
(
opdesc
.
SerializeToString
())
__impl__
.
__doc__
=
get_docstring_from_op_proto
(
op_proto
)
__impl__
.
all_input_args
=
[
var
.
name
for
var
in
op_proto
.
inputs
]
__impl__
.
all_output_args
=
[
var
.
name
for
var
in
op_proto
.
outputs
]
__impl__
.
all_attr_args
=
[
attr
.
name
for
attr
in
op_proto
.
attrs
]
return
__impl__
...
...
python/paddle/v2/framework/tests/CMakeLists.txt
浏览文件 @
d5291340
add_python_test
(
test_framework test_protobuf.py test_scope.py
test_default_scope_funcs.py test_op_creation_methods.py
test_tensor.py test_fc_op.py
)
test_tensor.py test_fc_op.py
test_add_two_op.py
)
python/paddle/v2/framework/tests/op_test_util.py
0 → 100644
浏览文件 @
d5291340
import
paddle.v2.framework.core
as
core
import
unittest
import
numpy
import
paddle.v2.framework.create_op_creation_methods
as
creation
class
OpTestMeta
(
type
):
def
__new__
(
cls
,
name
,
bases
,
attrs
):
obj
=
super
(
OpTestMeta
,
cls
).
__new__
(
cls
,
name
,
bases
,
attrs
)
def
test_all
(
self
):
func
=
getattr
(
creation
.
op_creations
,
self
.
type
,
None
)
self
.
assertIsNotNone
(
func
)
scope
=
core
.
Scope
(
None
)
kwargs
=
dict
()
for
in_name
in
func
.
all_input_args
:
if
hasattr
(
self
,
in_name
):
kwargs
[
in_name
]
=
in_name
var
=
scope
.
create_var
(
in_name
).
get_tensor
()
arr
=
getattr
(
self
,
in_name
)
var
.
set_dims
(
arr
.
shape
)
var
.
set
(
arr
)
else
:
kwargs
[
in_name
]
=
"@EMPTY@"
for
out_name
in
func
.
all_output_args
:
if
hasattr
(
self
,
out_name
):
kwargs
[
out_name
]
=
out_name
scope
.
create_var
(
out_name
).
get_tensor
()
for
attr_name
in
func
.
all_attr_args
:
if
hasattr
(
self
,
attr_name
):
kwargs
[
attr_name
]
=
getattr
(
self
,
attr_name
)
op
=
func
(
**
kwargs
)
op
.
infer_shape
(
scope
)
ctx
=
core
.
DeviceContext
.
cpu_context
()
op
.
run
(
scope
,
ctx
)
for
out_name
in
func
.
all_output_args
:
actual
=
numpy
.
array
(
scope
.
get_var
(
out_name
).
get_tensor
())
expect
=
getattr
(
self
,
out_name
)
numpy
.
testing
.
assert_almost_equal
(
actual
,
expect
)
obj
.
test_all
=
test_all
return
obj
python/paddle/v2/framework/tests/test_add_two_op.py
0 → 100644
浏览文件 @
d5291340
import
unittest
from
op_test_util
import
OpTestMeta
import
numpy
class
TestAddOp
(
unittest
.
TestCase
):
__metaclass__
=
OpTestMeta
def
setUp
(
self
):
self
.
type
=
"add_two"
self
.
X
=
numpy
.
random
.
random
((
342
,
345
)).
astype
(
"float32"
)
self
.
Y
=
numpy
.
random
.
random
((
342
,
345
)).
astype
(
"float32"
)
self
.
Out
=
self
.
X
+
self
.
Y
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录