Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
d93bbf1b
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d93bbf1b
编写于
12月 08, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add conv_trans unit test
上级
aa770198
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
132 addition
and
23 deletion
+132
-23
python/paddle/v2/fluid/tests/test_conv2d_transpose_op.py
python/paddle/v2/fluid/tests/test_conv2d_transpose_op.py
+63
-10
python/paddle/v2/fluid/tests/test_conv3d_transpose_op.py
python/paddle/v2/fluid/tests/test_conv3d_transpose_op.py
+69
-13
未找到文件。
python/paddle/v2/fluid/tests/test_conv2d_transpose_op.py
浏览文件 @
d93bbf1b
...
...
@@ -3,14 +3,17 @@ import numpy as np
from
op_test
import
OpTest
def
conv2dtranspose_forward_naive
(
input_
,
filter_
,
conv2dtranspose_param
):
def
conv2dtranspose_forward_naive
(
input_
,
filter_
,
attrs
):
in_n
,
in_c
,
in_h
,
in_w
=
input_
.
shape
f_c
,
out_c
,
f_h
,
f_w
=
filter_
.
shape
assert
in_c
==
f_c
stride
,
pad
=
conv2dtranspose_param
[
'stride'
],
conv2dtranspose_param
[
'pad'
]
out_h
=
(
in_h
-
1
)
*
stride
[
0
]
+
f_h
out_w
=
(
in_w
-
1
)
*
stride
[
1
]
+
f_w
stride
,
pad
,
dilations
=
attrs
[
'strides'
],
attrs
[
'paddings'
],
attrs
[
'dilations'
]
d_bolck_h
=
dilations
[
0
]
*
(
f_h
-
1
)
+
1
d_bolck_w
=
dilations
[
1
]
*
(
f_w
-
1
)
+
1
out_h
=
(
in_h
-
1
)
*
stride
[
0
]
+
d_bolck_h
out_w
=
(
in_w
-
1
)
*
stride
[
1
]
+
d_bolck_w
out
=
np
.
zeros
((
in_n
,
out_c
,
out_h
,
out_w
))
...
...
@@ -23,9 +26,9 @@ def conv2dtranspose_forward_naive(input_, filter_, conv2dtranspose_param):
for
k
in
range
(
out_c
):
tmp_out
=
np
.
sum
(
input_masked
*
filter_
[:,
k
,
:,
:],
axis
=
0
)
i1
,
i2
=
i
*
stride
[
0
],
i
*
stride
[
0
]
+
f
_h
j1
,
j2
=
j
*
stride
[
0
],
j
*
stride
[
0
]
+
f_w
out
[
n
,
k
,
i1
:
i2
,
j1
:
j2
]
+=
tmp_out
i1
,
i2
=
i
*
stride
[
0
],
i
*
stride
[
0
]
+
d_bolck
_h
j1
,
j2
=
j
*
stride
[
0
],
j
*
stride
[
0
]
+
d_bolck_h
out
[
n
,
k
,
i1
:
i2
:
dilations
[
0
],
j1
:
j2
:
dilations
[
1
]
]
+=
tmp_out
out
=
out
[:,
:,
pad
[
0
]:
out_h
-
pad
[
0
],
pad
[
1
]:
out_w
-
pad
[
1
]]
return
out
...
...
@@ -37,11 +40,8 @@ class TestConv2dTransposeOp(OpTest):
self
.
init_op_type
()
self
.
init_test_case
()
conv2dtranspose_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
=
conv2dtranspose_forward_naive
(
input_
,
filter_
,
conv2dtranspose_param
).
astype
(
'float32'
)
self
.
inputs
=
{
'Input'
:
input_
,
'Filter'
:
filter_
}
self
.
attrs
=
{
...
...
@@ -49,6 +49,10 @@ class TestConv2dTransposeOp(OpTest):
'paddings'
:
self
.
pad
,
'dilations'
:
self
.
dilations
}
output
=
conv2dtranspose_forward_naive
(
input_
,
filter_
,
self
.
attrs
).
astype
(
'float32'
)
self
.
outputs
=
{
'Output'
:
output
}
def
test_check_output
(
self
):
...
...
@@ -104,11 +108,60 @@ class TestWithStride(TestConv2dTransposeOp):
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
class
TestWithDilation
(
TestConv2dTransposeOp
):
def
init_test_case
(
self
):
self
.
pad
=
[
1
,
1
]
self
.
stride
=
[
1
,
1
]
self
.
dilations
=
[
2
,
2
]
self
.
input_size
=
[
2
,
3
,
5
,
5
]
# NCHW
f_c
=
self
.
input_size
[
1
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
# ------------ test_cudnn ------------
class
TestCudnn
(
TestConv2dTransposeOp
):
def
init_op_type
(
self
):
self
.
op_type
=
"conv2d_transpose_cudnn"
class
TestCudnnWithPad
(
TestWithPad
):
def
init_test_case
(
self
):
self
.
pad
=
[
1
,
1
]
self
.
stride
=
[
1
,
1
]
self
.
dilations
=
[
1
,
1
]
self
.
input_size
=
[
2
,
3
,
5
,
5
]
# NCHW
f_c
=
self
.
input_size
[
1
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
def
init_op_type
(
self
):
self
.
op_type
=
"conv2d_transpose_cudnn"
class
TestCudnnWithStride
(
TestWithStride
):
def
init_test_case
(
self
):
self
.
pad
=
[
1
,
1
]
self
.
stride
=
[
2
,
2
]
self
.
dilations
=
[
1
,
1
]
self
.
input_size
=
[
2
,
3
,
5
,
5
]
# NCHW
f_c
=
self
.
input_size
[
1
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
def
init_op_type
(
self
):
self
.
op_type
=
"conv2d_transpose_cudnn"
# #cudnn v5 does not support dilation conv.
# class TestCudnnWithDilation(TestWithDilation):
# def init_test_case(self):
# self.pad = [1, 1]
# self.stride = [2, 2]
# self.dilations = [2, 2]
# self.input_size = [2, 3, 5, 5] # NCHW
# f_c = self.input_size[1]
# self.filter_size = [f_c, 6, 3, 3]
#
# def init_op_type(self):
# self.op_type = "conv2d_transpose_cudnn"
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/v2/fluid/tests/test_conv3d_transpose_op.py
浏览文件 @
d93bbf1b
...
...
@@ -3,15 +3,20 @@ import numpy as np
from
op_test
import
OpTest
def
conv3dtranspose_forward_naive
(
input_
,
filter_
,
conv3dtranspose_param
):
def
conv3dtranspose_forward_naive
(
input_
,
filter_
,
attrs
):
in_n
,
in_c
,
in_d
,
in_h
,
in_w
=
input_
.
shape
f_c
,
out_c
,
f_d
,
f_h
,
f_w
=
filter_
.
shape
assert
in_c
==
f_c
stride
,
pad
=
conv3dtranspose_param
[
'stride'
],
conv3dtranspose_param
[
'pad'
]
out_d
=
(
in_d
-
1
)
*
stride
[
0
]
+
f_d
out_h
=
(
in_h
-
1
)
*
stride
[
1
]
+
f_h
out_w
=
(
in_w
-
1
)
*
stride
[
2
]
+
f_w
stride
,
pad
,
dilations
=
attrs
[
'strides'
],
attrs
[
'paddings'
],
attrs
[
'dilations'
]
d_bolck_d
=
dilations
[
0
]
*
(
f_d
-
1
)
+
1
d_bolck_h
=
dilations
[
1
]
*
(
f_h
-
1
)
+
1
d_bolck_w
=
dilations
[
2
]
*
(
f_w
-
1
)
+
1
out_d
=
(
in_d
-
1
)
*
stride
[
0
]
+
d_bolck_d
out_h
=
(
in_h
-
1
)
*
stride
[
1
]
+
d_bolck_h
out_w
=
(
in_w
-
1
)
*
stride
[
2
]
+
d_bolck_w
out
=
np
.
zeros
((
in_n
,
out_c
,
out_d
,
out_h
,
out_w
))
for
n
in
range
(
in_n
):
...
...
@@ -25,10 +30,11 @@ def conv3dtranspose_forward_naive(input_, filter_, conv3dtranspose_param):
for
k
in
range
(
out_c
):
tmp_out
=
np
.
sum
(
input_masked
*
filter_
[:,
k
,
:,
:,
:],
axis
=
0
)
d1
,
d2
=
d
*
stride
[
0
],
d
*
stride
[
0
]
+
f_d
i1
,
i2
=
i
*
stride
[
1
],
i
*
stride
[
1
]
+
f_h
j1
,
j2
=
j
*
stride
[
2
],
j
*
stride
[
2
]
+
f_w
out
[
n
,
k
,
d1
:
d2
,
i1
:
i2
,
j1
:
j2
]
+=
tmp_out
d1
,
d2
=
d
*
stride
[
0
],
d
*
stride
[
0
]
+
d_bolck_d
i1
,
i2
=
i
*
stride
[
1
],
i
*
stride
[
1
]
+
d_bolck_h
j1
,
j2
=
j
*
stride
[
2
],
j
*
stride
[
2
]
+
d_bolck_w
out
[
n
,
k
,
d1
:
d2
:
dilations
[
0
],
i1
:
i2
:
dilations
[
1
],
j1
:
j2
:
dilations
[
2
]]
+=
tmp_out
out
=
out
[:,
:,
pad
[
0
]:
out_d
-
pad
[
0
],
pad
[
1
]:
out_h
-
pad
[
1
],
pad
[
2
]:
out_w
-
pad
[
2
]]
...
...
@@ -41,18 +47,19 @@ class TestConv3dTransposeOp(OpTest):
self
.
init_op_type
()
self
.
init_test_case
()
conv3dtranspose_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
=
conv3dtranspose_forward_naive
(
input_
,
filter_
,
conv3dtranspose_param
).
astype
(
"float32"
)
self
.
inputs
=
{
'Input'
:
input_
,
'Filter'
:
filter_
}
self
.
attrs
=
{
'strides'
:
self
.
stride
,
'paddings'
:
self
.
pad
,
#
'dilations': self.dilations
'dilations'
:
self
.
dilations
}
output
=
conv3dtranspose_forward_naive
(
input_
,
filter_
,
self
.
attrs
).
astype
(
"float32"
)
self
.
outputs
=
{
'Output'
:
output
}
def
test_check_output
(
self
):
...
...
@@ -108,11 +115,60 @@ class TestWithStride(TestConv3dTransposeOp):
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
,
3
]
class
TestWithDilation
(
TestConv3dTransposeOp
):
def
init_test_case
(
self
):
self
.
pad
=
[
1
,
1
,
1
]
self
.
stride
=
[
1
,
1
,
1
]
self
.
dilations
=
[
2
,
2
,
2
]
self
.
input_size
=
[
2
,
3
,
5
,
5
,
5
]
# NCDHW
f_c
=
self
.
input_size
[
1
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
,
3
]
# ------------ test_cudnn ------------
class
TestCudnn
(
TestConv3dTransposeOp
):
def
init_op_type
(
self
):
self
.
op_type
=
"conv3d_transpose_cudnn"
class
TestCudnnWithPad
(
TestWithPad
):
def
init_test_case
(
self
):
self
.
pad
=
[
1
,
1
,
1
]
self
.
stride
=
[
1
,
1
,
1
]
self
.
dilations
=
[
1
,
1
,
1
]
self
.
input_size
=
[
2
,
3
,
5
,
5
,
5
]
# NCDHW
f_c
=
self
.
input_size
[
1
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
,
3
]
def
init_op_type
(
self
):
self
.
op_type
=
"conv3d_transpose_cudnn"
class
TestCudnnWithStride
(
TestWithStride
):
def
init_test_case
(
self
):
self
.
pad
=
[
1
,
1
,
1
]
self
.
stride
=
[
2
,
2
,
2
]
self
.
dilations
=
[
1
,
1
,
1
]
self
.
input_size
=
[
2
,
3
,
5
,
5
,
5
]
# NCDHW
f_c
=
self
.
input_size
[
1
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
,
3
]
def
init_op_type
(
self
):
self
.
op_type
=
"conv3d_transpose_cudnn"
# #cudnn v5 does not support dilation conv.
# class TestCudnnWithDilation(TestWithDilation):
# def init_test_case(self):
# self.pad = [1, 1, 1]
# self.stride = [2, 2, 2]
# self.dilations = [2, 2, 2]
# self.input_size = [2, 3, 5, 5, 5] # NCDHW
# f_c = self.input_size[1]
# self.filter_size = [f_c, 6, 3, 3, 3]
#
# def init_op_type(self):
# self.op_type = "conv3d_transpose_cudnn"
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录