Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0f1b30ef
P
Paddle
项目概览
机器未来
/
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看板
提交
0f1b30ef
编写于
11月 05, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix doc and unit test
上级
10bd9f68
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
39 deletion
+55
-39
paddle/operators/conv_transpose_op.cc
paddle/operators/conv_transpose_op.cc
+27
-20
paddle/operators/conv_transpose_op.h
paddle/operators/conv_transpose_op.h
+10
-2
python/paddle/v2/framework/tests/test_conv2d_transpose_op.py
python/paddle/v2/framework/tests/test_conv2d_transpose_op.py
+15
-14
python/paddle/v2/framework/tests/test_conv3d_transpose_op.py
python/paddle/v2/framework/tests/test_conv3d_transpose_op.py
+3
-3
未找到文件。
paddle/operators/conv_transpose_op.cc
浏览文件 @
0f1b30ef
...
...
@@ -65,16 +65,17 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
"Input"
,
"(Tensor) The input tensor of convolution transpose operator. "
"The format of input tensor is NCHW. Where N is batch size, C is the "
"number of input channels, H and W is the height and width of image."
);
"number of input channels, H is the height of the feature, and "
"W is the width of the feature."
);
AddInput
(
"Filter"
,
"(Tensor) The filter tensor of convolution transpose operator."
"(Tensor) The filter tensor of convolution transpose operator.
"
"The format of the filter tensor is CMHW, where C is the number of "
"output image channels, M is the number of input image channels, "
"H
and W is height and width of
filter. "
"H
is the height of the filter, and W is the width of the
filter. "
"We enforce groups number == 1 and padding == 0 in "
"
convolution transpose S
cenario."
);
"
the convolution transpose s
cenario."
);
AddOutput
(
"Output"
,
"(Tensor) The output tensor of convolution transpose operator."
"(Tensor) The output tensor of convolution transpose operator.
"
"The format of output tensor is also NCHW."
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
...
...
@@ -85,13 +86,15 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
"(vector defalut:{0, 0}), paddings of convolution transpose operator."
)
.
SetDefault
({
0
,
0
});
AddComment
(
R"DOC(
Convolution2D Transpose Operator.
The convolution transpose operation calculates the output based on the input, filter
and strides, paddings, groups parameters. The size of each dimension of the
parameters is checked in the infer-shape.
Input(Input, Filter) and output(Output) are in NCHW format. Where N is batch
size, C is the number of channels, H
and W is the height and
width of
feature. Parameters(ksize, strides, paddings) are two elements.
size, C is the number of channels, H
is the height of the feature, and
W is the width of the
feature. Parameters(ksize, strides, paddings) are two elements.
These two elements represent height and width, respectively.
The input(X) size and output(Out) size may be different.
Example:
...
...
@@ -109,25 +112,26 @@ Example:
Conv3DTransposeOpMaker
::
Conv3DTransposeOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Input"
,
"(Tensor) The input tensor of convolution transpose operator.
"
"The format of input tensor is NCDHW. Where N is batch size, C is
"
"the number of channels, D, H and W is the depth, height and width of
"
"
feature."
);
AddInput
(
"Input"
,
"(Tensor) The input tensor of convolution transpose operator."
"The format of input tensor is NCDHW. Where N is batch size, C is
"
"the number of channels, D is the depth of the feature, H is the
"
"height of the feature, and
"
"W is the width of the
feature."
);
AddInput
(
"Filter"
,
"(Tensor) The filter tensor of convolution transpose operator."
"The format of the filter tensor is CMDHW, where C is the number of "
"output image channels, M is the number of input image channels, "
"D, H and W is depth, height and width of filter. "
"output image channels, M is the number of input image channels, D "
"is the depth of the filter, H is the height of the filter, and "
"W is the width of the filter."
"We enforce groups number == 1 and padding == 0 in "
"
convolution transpose S
cenario."
);
"
the convolution3d transpose s
cenario."
);
AddOutput
(
"Output"
,
"(Tensor) The output tensor of convolution transpose operator."
"The format of output tensor is also NCDHW."
"Where N is batch size, C is "
"the number of channels, D
, H and W is the depth, height and
"
"
width of
feature."
);
"the number of channels, D
is the depth of the feature, H is the
"
"
height of the feature, and W is the width of the
feature."
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector defalut:{1, 1, 1}), strides of convolution transpose operator."
)
...
...
@@ -137,13 +141,16 @@ Conv3DTransposeOpMaker::Conv3DTransposeOpMaker(
"(vector defalut:{0, 0, 0}), paddings of convolution transpose operator."
)
.
SetDefault
({
0
,
0
,
0
});
AddComment
(
R"DOC(
Convolution3D Transpose Operator.
The convolution transpose operation calculates the output based on the input, filter
and strides, paddings, groups parameters. The size of each dimension of the
parameters is checked in the infer-shape.
Input(Input, Filter) and output(Output) are in NCDHW format. Where N is batch
size, C is the number of channels, d, H and W is the depth, height and
width of feature. Parameters(ksize, strides, paddings) are three elements.
size, C is the number of channels, D is the depth of the feature,
H is the height of the feature, and W is the width of the feature.
Parameters(ksize, strides, paddings) are three elements.
These three elements represent depth, height and width, respectively.
The input(X) size and output(Out) size may be different.
Example:
...
...
paddle/operators/conv_transpose_op.h
浏览文件 @
0f1b30ef
...
...
@@ -175,6 +175,10 @@ class GemmConv2DTransposeGradKernel : public framework::OpKernel<T> {
DDim
filter_matrix_shape
=
{
m
,
c
*
k_h
*
k_w
};
filter
.
Resize
(
filter_matrix_shape
);
if
((
!
input_grad
)
&&
(
!
filter_grad
))
{
return
;
}
// convolution transpose grad on input:
// im2col + gemm (similar to conv-forward)
// input need to compute gradient
...
...
@@ -265,7 +269,7 @@ class GemmConv3DTransposeKernel : public framework::OpKernel<T> {
const
int64_t
o_h
=
output
->
dims
()[
3
];
const
int64_t
o_w
=
output
->
dims
()[
4
];
paddle
::
operators
::
math
::
Col2VolFunctor
<
Place
,
T
>
col2vol
;
math
::
Col2VolFunctor
<
Place
,
T
>
col2vol
;
// use col_shape in the vol2col and col2vol calculation
DDim
col_shape
=
{
c
,
k_d
,
k_h
,
k_w
,
d
,
h
,
w
};
...
...
@@ -349,7 +353,7 @@ class GemmConv3DTransposeGradKernel : public framework::OpKernel<T> {
const
int64_t
o_w
=
output_grad
->
dims
()[
4
];
// Only vol2col functor required for bp to get to the right shape
paddle
::
operators
::
math
::
Vol2ColFunctor
<
Place
,
T
>
vol2col
;
math
::
Vol2ColFunctor
<
Place
,
T
>
vol2col
;
// use col_shape in the vol2col and col2vol calculation
DDim
col_shape
=
{
c
,
k_d
,
k_h
,
k_w
,
d
,
h
,
w
};
...
...
@@ -363,6 +367,10 @@ class GemmConv3DTransposeGradKernel : public framework::OpKernel<T> {
DDim
filter_matrix_shape
=
{
m
,
c
*
k_d
*
k_h
*
k_w
};
filter
.
Resize
(
filter_matrix_shape
);
if
((
!
input_grad
)
&&
(
!
filter_grad
))
{
return
;
}
// convolution transpose grad on input:
// vol2col + gemm (similar to conv-forward)
// input need to compute gradient
...
...
python/paddle/v2/framework/tests/test_conv2d_transpose_op.py
浏览文件 @
0f1b30ef
...
...
@@ -58,36 +58,37 @@ class TestConv2dTransposeOp(OpTest):
print
'check output here for'
,
self
.
op_type
self
.
check_output
()
def
init_test_case
(
self
):
self
.
pad
=
[
0
,
0
]
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"
def
test_check_grad_no_input
(
self
):
self
.
check_grad
(
[
'Filter'
],
'Output'
,
max_relative_error
=
0.0
5
,
max_relative_error
=
0.0
2
,
no_grad_set
=
set
([
'Input'
]))
def
test_check_grad_no_filter
(
self
):
self
.
check_grad
(
[
'Input'
],
'Output'
,
max_relative_error
=
0.0
5
,
max_relative_error
=
0.0
2
,
no_grad_set
=
set
([
'Filter'
]))
def
test_check_grad
(
self
):
self
.
check_grad
(
set
([
'Input'
,
'Filter'
]),
'Output'
,
max_relative_error
=
0.05
)
set
([
'Input'
,
'Filter'
]),
'Output'
,
max_relative_error
=
0.02
)
def
init_test_case
(
self
):
self
.
pad
=
[
0
,
0
]
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"
# ------------ test_cudnn ------------
class
TestCudnn
(
TestConv2dTransposeOp
):
def
init_op_type
(
self
):
self
.
op_type
=
"conv2d_transpose_cudnn"
...
...
python/paddle/v2/framework/tests/test_conv3d_transpose_op.py
浏览文件 @
0f1b30ef
...
...
@@ -65,20 +65,20 @@ class TestConv3dTransposeOp(OpTest):
def
test_check_grad
(
self
):
self
.
check_grad
(
set
([
'Input'
,
'Filter'
]),
'Output'
,
max_relative_error
=
0.0
5
)
set
([
'Input'
,
'Filter'
]),
'Output'
,
max_relative_error
=
0.0
2
)
def
test_check_grad_no_filter
(
self
):
self
.
check_grad
(
[
'Input'
],
'Output'
,
max_relative_error
=
0.0
5
,
max_relative_error
=
0.0
2
,
no_grad_set
=
set
([
'Filter'
]))
def
test_check_grad_no_input
(
self
):
self
.
check_grad
(
[
'Filter'
],
'Output'
,
max_relative_error
=
0.0
5
,
max_relative_error
=
0.0
2
,
no_grad_set
=
set
([
'Input'
]))
def
init_test_case
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录