Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
5173b8d8
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5173b8d8
编写于
10月 30, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code format and doc
上级
09ed5283
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
62 addition
and
27 deletion
+62
-27
paddle/operators/CMakeLists.txt
paddle/operators/CMakeLists.txt
+1
-1
paddle/operators/conv_transpose_op.cc
paddle/operators/conv_transpose_op.cc
+54
-19
paddle/operators/conv_transpose_op.cu
paddle/operators/conv_transpose_op.cu
+4
-4
python/paddle/v2/framework/tests/test_conv2dtranspose_op.py
python/paddle/v2/framework/tests/test_conv2dtranspose_op.py
+2
-2
python/paddle/v2/framework/tests/test_conv3dtranspose_op.py
python/paddle/v2/framework/tests/test_conv3dtranspose_op.py
+1
-1
未找到文件。
paddle/operators/CMakeLists.txt
浏览文件 @
5173b8d8
...
@@ -73,7 +73,7 @@ function(op_library TARGET)
...
@@ -73,7 +73,7 @@ function(op_library TARGET)
if
(
"
${
TARGET
}
"
STREQUAL
"conv_transpose_op"
)
if
(
"
${
TARGET
}
"
STREQUAL
"conv_transpose_op"
)
set
(
pybind_flag 1
)
set
(
pybind_flag 1
)
# It's enough to just adding one operator to pybind
# It's enough to just adding one operator to pybind
file
(
APPEND
${
pybind_file
}
"USE_OP(conv2dtranspose);
\n
"
)
file
(
APPEND
${
pybind_file
}
"USE_OP(conv2d
_
transpose);
\n
"
)
endif
()
endif
()
# pool_cudnn_op contains several operators
# pool_cudnn_op contains several operators
...
...
paddle/operators/conv_transpose_op.cc
浏览文件 @
5173b8d8
...
@@ -46,9 +46,9 @@ void ConvTransposeOp::InferShape(framework::InferShapeContext* ctx) const {
...
@@ -46,9 +46,9 @@ void ConvTransposeOp::InferShape(framework::InferShapeContext* ctx) const {
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
strides
.
size
(),
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
strides
.
size
(),
"ConvTransposeOp paddings dimension and Conv strides "
"ConvTransposeOp paddings dimension and Conv strides "
"dimension should be the same."
);
"dimension should be the same."
);
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
in_dims
[
1
],
filter_dims
[
0
],
in_dims
[
1
],
filter_dims
[
0
],
"In ConvTransposeOp, The input channel should be the same "
"ConvTransposeOp input and kernel input dimension should be equal
."
);
"as the number of filters
."
);
std
::
vector
<
int64_t
>
output_shape
({
in_dims
[
0
],
filter_dims
[
1
]});
std
::
vector
<
int64_t
>
output_shape
({
in_dims
[
0
],
filter_dims
[
1
]});
for
(
size_t
i
=
0
;
i
<
paddings
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
paddings
.
size
();
++
i
)
{
...
@@ -76,16 +76,33 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
...
@@ -76,16 +76,33 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
AddOutput
(
"Output"
,
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."
);
"The format of output tensor is also NCHW."
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
AddAttr
<
std
::
vector
<
int
>>
(
"strides of convolution transpose operator."
)
"strides"
,
"(vector defalut:{1, 1}), strides of convolution transpose operator."
)
.
SetDefault
({
1
,
1
});
.
SetDefault
({
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
AddAttr
<
std
::
vector
<
int
>>
(
"paddings of convolution transpose operator."
)
"paddings"
,
"(vector defalut:{0, 0}), paddings of convolution transpose operator."
)
.
SetDefault
({
0
,
0
});
.
SetDefault
({
0
,
0
});
AddComment
(
R"DOC(
AddComment
(
R"DOC(
The convolution transpose operation calculates the output based on the input, filter
The convolution transpose operation calculates the output based on the input, filter
and strides, paddings, groups parameters. The size of each dimension of the
and strides, paddings, groups parameters. The size of each dimension of the
parameters is checked in the infer-shape.
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.
These two elements represent height and width, respectively.
The input(X) size and output(Out) size may be different.
Example:
Input:
Input shape: (N, C_in, H_in, W_in)
Filter shape: (C_in, C_out, H_f, W_f)
Output:
Output shape: (N, C_out, H_out, W_out)
where
H_out = (H_in - 1) * strides[0] - 2 * paddings[0] + filter_size[0];
W_out = (W_in - 1) * strides[1] - 2 * paddings[1] + filter_size[1];
)DOC"
);
)DOC"
);
}
}
...
@@ -111,16 +128,34 @@ Conv3DTransposeOpMaker::Conv3DTransposeOpMaker(
...
@@ -111,16 +128,34 @@ Conv3DTransposeOpMaker::Conv3DTransposeOpMaker(
"Where N is batch size, C is "
"Where N is batch size, C is "
"the number of channels, D, H and W is the depth, height and "
"the number of channels, D, H and W is the depth, height and "
"width of feature."
);
"width of feature."
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
AddAttr
<
std
::
vector
<
int
>>
(
"strides of convolution transpose operator."
)
"strides"
,
"(vector defalut:{1, 1, 1}), strides of convolution transpose operator."
)
.
SetDefault
({
1
,
1
,
1
});
.
SetDefault
({
1
,
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
AddAttr
<
std
::
vector
<
int
>>
(
"paddings of convolution transpose operator."
)
"paddings"
,
"(vector defalut:{0, 0, 0}), paddings of convolution transpose operator."
)
.
SetDefault
({
0
,
0
,
0
});
.
SetDefault
({
0
,
0
,
0
});
AddComment
(
R"DOC(
AddComment
(
R"DOC(
The convolution transpose operation calculates the output based on the input, filter
The convolution transpose operation calculates the output based on the input, filter
and strides, paddings, groups parameters. The size of each dimension of the
and strides, paddings, groups parameters. The size of each dimension of the
parameters is checked in the infer-shape.
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.
These three elements represent depth, height and width, respectively.
The input(X) size and output(Out) size may be different.
Example:
Input:
Input shape: (N, C_in, D_in, H_in, W_in)
Filter shape: (C_in, C_out, D_f, H_f, W_f)
Output:
Output shape: (N, C_out, D_out, H_out, W_out)
where
D_out = (D_in - 1) * strides[0] - 2 * paddings[0] + filter_size[0];
H_out = (H_in - 1) * strides[1] - 2 * paddings[1] + filter_size[1];
W_out = (W_in - 1) * strides[2] - 2 * paddings[2] + filter_size[2];
)DOC"
);
)DOC"
);
}
}
...
@@ -140,22 +175,22 @@ void ConvTransposeOpGrad::InferShape(framework::InferShapeContext* ctx) const {
...
@@ -140,22 +175,22 @@ void ConvTransposeOpGrad::InferShape(framework::InferShapeContext* ctx) const {
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
conv2dtranspose
,
ops
::
ConvTransposeOp
,
ops
::
Conv2DTransposeOpMaker
,
REGISTER_OP
(
conv2d
_
transpose
,
ops
::
ConvTransposeOp
,
ops
::
Conv2DTransposeOpMaker
,
conv2dtranspose_grad
,
ops
::
ConvTransposeOpGrad
);
conv2d
_
transpose_grad
,
ops
::
ConvTransposeOpGrad
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
conv2dtranspose
,
conv2d
_
transpose
,
ops
::
GemmConv2DTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConv2DTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
conv2dtranspose_grad
,
conv2d
_
transpose_grad
,
ops
::
GemmConv2DTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConv2DTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP
(
conv3dtranspose
,
ops
::
ConvTransposeOp
,
ops
::
Conv3DTransposeOpMaker
,
REGISTER_OP
(
conv3d
_
transpose
,
ops
::
ConvTransposeOp
,
ops
::
Conv3DTransposeOpMaker
,
conv3dtranspose_grad
,
ops
::
ConvTransposeOpGrad
);
conv3d
_
transpose_grad
,
ops
::
ConvTransposeOpGrad
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
conv3dtranspose
,
conv3d
_
transpose
,
ops
::
GemmConv3DTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConv3DTransposeKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
conv3dtranspose_grad
,
conv3d
_
transpose_grad
,
ops
::
GemmConv3DTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
GemmConv3DTransposeGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/conv_transpose_op.cu
浏览文件 @
5173b8d8
...
@@ -17,15 +17,15 @@
...
@@ -17,15 +17,15 @@
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
REGISTER_OP_GPU_KERNEL
(
conv2dtranspose
,
conv2d
_
transpose
,
ops
::
GemmConv2DTransposeKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
GemmConv2DTransposeKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
REGISTER_OP_GPU_KERNEL
(
conv2dtranspose_grad
,
conv2d
_
transpose_grad
,
ops
::
GemmConv2DTransposeGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
GemmConv2DTransposeGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
REGISTER_OP_GPU_KERNEL
(
conv3dtranspose
,
conv3d
_
transpose
,
ops
::
GemmConv3DTransposeKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
GemmConv3DTransposeKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
REGISTER_OP_GPU_KERNEL
(
conv3dtranspose_grad
,
conv3d
_
transpose_grad
,
ops
::
GemmConv3DTransposeGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
GemmConv3DTransposeGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
python/paddle/v2/framework/tests/test_conv2dtranspose_op.py
浏览文件 @
5173b8d8
...
@@ -26,7 +26,7 @@ def conv2dtranspose_forward_naive(input_, filter_, conv2dtranspose_param):
...
@@ -26,7 +26,7 @@ def conv2dtranspose_forward_naive(input_, filter_, conv2dtranspose_param):
for
k
in
range
(
out_c
):
for
k
in
range
(
out_c
):
tmp_out
=
np
.
sum
(
input_masked
*
filter_
[:,
k
,
:,
:],
axis
=
0
)
tmp_out
=
np
.
sum
(
input_masked
*
filter_
[:,
k
,
:,
:],
axis
=
0
)
i1
,
i2
=
i
*
stride
[
0
],
i
*
stride
[
0
]
+
f_h
i1
,
i2
=
i
*
stride
[
0
],
i
*
stride
[
0
]
+
f_h
j1
,
j2
=
j
*
stride
[
0
],
j
*
stride
[
0
]
+
f_w
j1
,
j2
=
j
*
stride
[
1
],
j
*
stride
[
1
]
+
f_w
out
[
n
,
k
,
i1
:
i2
,
j1
:
j2
]
+=
tmp_out
out
[
n
,
k
,
i1
:
i2
,
j1
:
j2
]
+=
tmp_out
return
out
return
out
...
@@ -86,7 +86,7 @@ class TestConv2dTransposeOp(OpTest):
...
@@ -86,7 +86,7 @@ class TestConv2dTransposeOp(OpTest):
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
def
init_op_type
(
self
):
def
init_op_type
(
self
):
self
.
op_type
=
"conv2dtranspose"
self
.
op_type
=
"conv2d
_
transpose"
"""
"""
...
...
python/paddle/v2/framework/tests/test_conv3dtranspose_op.py
浏览文件 @
5173b8d8
...
@@ -90,7 +90,7 @@ class TestConv3dTransposeOp(OpTest):
...
@@ -90,7 +90,7 @@ class TestConv3dTransposeOp(OpTest):
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
,
3
]
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
,
3
]
def
init_op_type
(
self
):
def
init_op_type
(
self
):
self
.
op_type
=
"conv3dtranspose"
self
.
op_type
=
"conv3d
_
transpose"
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录