Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5fe68931
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5fe68931
编写于
10月 12, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code struce
上级
8ad67da9
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
43 addition
and
30 deletion
+43
-30
python/paddle/v2/framework/tests/test_conv2d_op.py
python/paddle/v2/framework/tests/test_conv2d_op.py
+43
-30
未找到文件。
python/paddle/v2/framework/tests/test_conv2d_op.py
浏览文件 @
5fe68931
...
...
@@ -21,13 +21,15 @@ def conv2d_forward_naive(input, filter, group, conv_param):
for
i
in
range
(
out_h
):
for
j
in
range
(
out_w
):
for
g
in
range
(
group
):
input_pad_masked
=
input_pad
[:,
g
*
f_c
:(
g
+
1
)
*
f_c
,
i
*
stride
[
0
]:
i
*
stride
[
0
]
+
f_h
,
j
*
stride
[
1
]:
j
*
stride
[
1
]
+
f_w
]
input_pad_masked
=
\
input_pad
[:,
g
*
f_c
:(
g
+
1
)
*
f_c
,
i
*
stride
[
0
]:
i
*
stride
[
0
]
+
f_h
,
j
*
stride
[
1
]:
j
*
stride
[
1
]
+
f_w
]
f_sub
=
filter
[
g
*
sub_out_c
:(
g
+
1
)
*
sub_out_c
,
:,
:,
:]
for
k
in
range
(
sub_out_c
):
out
[:,
g
*
sub_out_c
+
k
,
i
,
j
]
=
np
.
sum
(
input_pad_masked
*
f_sub
[
k
,
:,
:,
:],
out
[:,
g
*
sub_out_c
+
k
,
i
,
j
]
=
\
np
.
sum
(
input_pad_masked
*
f_sub
[
k
,
:,
:,
:],
axis
=
(
1
,
2
,
3
))
return
out
...
...
@@ -35,27 +37,21 @@ def conv2d_forward_naive(input, filter, group, conv_param):
class
TestConv2dOp
(
OpTest
):
def
setUp
(
self
):
self
.
init_groups
()
self
.
init_optype
()
pad
=
[
0
,
0
]
stride
=
[
1
,
1
]
input_size
=
[
2
,
3
,
5
,
5
]
# NCHW
assert
np
.
mod
(
input_size
[
1
],
self
.
groups
)
==
0
f_c
=
input_size
[
1
]
/
self
.
groups
filter_size
=
[
6
,
f_c
,
3
,
3
]
conv2d_param
=
{
'stride'
:
stride
,
'pad'
:
pad
}
input
=
np
.
random
.
random
(
input_size
).
astype
(
"float32"
)
filter
=
np
.
random
.
random
(
filter_size
).
astype
(
"float32"
)
self
.
init_op_type
()
self
.
init_group
()
self
.
init_test_case
()
conv2d_param
=
{
'stride'
:
self
.
stride
,
'pad'
:
self
.
pad
}
input
=
np
.
random
.
random
(
self
.
input_size
).
astype
(
"float32"
)
filter
=
np
.
random
.
random
(
self
.
filter_size
).
astype
(
"float32"
)
output
=
conv2d_forward_naive
(
input
,
filter
,
self
.
groups
,
conv2d_param
)
self
.
inputs
=
{
'Input'
:
input
,
'Filter'
:
filter
}
self
.
attrs
=
{
'strides'
:
stride
,
'paddings'
:
pad
,
'strides'
:
s
elf
.
s
tride
,
'paddings'
:
self
.
pad
,
'groups'
:
self
.
groups
,
'dilations'
:
[
1
,
1
]
'dilations'
:
self
.
dilations
}
self
.
outputs
=
{
'Output'
:
output
}
...
...
@@ -80,30 +76,47 @@ class TestConv2dOp(OpTest):
max_relative_error
=
0.05
,
no_grad_set
=
set
([
'Input'
]))
def
init_groups
(
self
):
def
init_test_case
(
self
):
self
.
groups
=
1
self
.
op_type
=
"conv2d"
self
.
pad
=
[
0
,
0
]
self
.
stride
=
[
1
,
1
]
self
.
dilations
=
[
1
,
1
]
self
.
input_size
=
[
2
,
3
,
5
,
5
]
# NCHW
assert
np
.
mod
(
self
.
input_size
[
1
],
self
.
groups
)
==
0
f_c
=
self
.
input_size
[
1
]
/
self
.
groups
self
.
filter_size
=
[
6
,
f_c
,
3
,
3
]
def
init_group
(
self
):
self
.
groups
=
1
def
init_optype
(
self
):
def
init_op
_
type
(
self
):
self
.
op_type
=
"conv2d"
class
TestWithGroup
(
TestConv2dOp
):
def
init_group
s
(
self
):
def
init_group
(
self
):
self
.
groups
=
3
def
init_op_type
(
self
):
self
.
op_type
=
"conv2d"
class
TestCudnn2d
(
TestConv2dOp
):
def
init_optype
(
self
):
self
.
op_type
=
"conv_cudnn"
class
TestCudnn
(
TestConv2dOp
):
def
init_group
(
self
):
self
.
groups
=
1
class
TestCudnn2dWithGroup
(
TestConv2dOp
):
def
init_optype
(
self
):
def
init_op_type
(
self
):
self
.
op_type
=
"conv_cudnn"
def
init_groups
(
self
):
class
TestCudnnWithGroup
(
TestConv2dOp
):
def
init_group
(
self
):
self
.
groups
=
3
def
init_op_type
(
self
):
self
.
op_type
=
"conv_cudnn"
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录