Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b3ab3ce0
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看板
提交
b3ab3ce0
编写于
10月 20, 2017
作者:
Z
zchen0211
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deconv -> conv transpose
上级
64c5ecbe
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
24 addition
and
21 deletion
+24
-21
paddle/operators/conv2dtranspose_op.cc
paddle/operators/conv2dtranspose_op.cc
+4
-5
paddle/operators/conv2dtranspose_op.cu
paddle/operators/conv2dtranspose_op.cu
+1
-1
paddle/operators/conv2dtranspose_op.h
paddle/operators/conv2dtranspose_op.h
+11
-8
python/paddle/v2/framework/tests/test_conv2dtranspose_op.py
python/paddle/v2/framework/tests/test_conv2dtranspose_op.py
+8
-7
未找到文件。
paddle/operators/
deconv2d
_op.cc
→
paddle/operators/
conv2dtranspose
_op.cc
浏览文件 @
b3ab3ce0
...
...
@@ -12,8 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/operators/deconv2d_op.h"
#include "paddle/operators/conv2d_op.h"
#include "paddle/operators/conv2dtranspose_op.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -54,18 +53,18 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Input"
,
"The input tensor of convolution transpose operator. "
"
(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."
);
AddInput
(
"Filter"
,
"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. "
"We enforce groups number == 1 and padding == 0 in "
"convolution transpose Scenario."
);
AddOutput
(
"Output"
,
"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"
,
"strides of convolution transpose operator."
)
...
...
paddle/operators/
deconv2d
_op.cu
→
paddle/operators/
conv2dtranspose
_op.cu
浏览文件 @
b3ab3ce0
...
...
@@ -12,7 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/operators/
deconv2d
_op.h"
#include "paddle/operators/
conv2dtranspose
_op.h"
namespace
ops
=
paddle
::
operators
;
...
...
paddle/operators/
deconv2d
_op.h
→
paddle/operators/
conv2dtranspose
_op.h
浏览文件 @
b3ab3ce0
...
...
@@ -14,7 +14,6 @@ limitations under the License. */
#pragma once
#include "glog/logging.h"
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
#include "paddle/operators/math/im2col.h"
...
...
@@ -62,7 +61,8 @@ class GemmConv2DTransposeKernel : public framework::OpKernel<T> {
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
// no paddings and groups allowed in deconv
// TODO(Zhuoyuan): Paddings can be added in future.
// groups will alway be disabled in conv2dtranspose.
const
int
batch_size
=
input
->
dims
()[
0
];
const
int
m
=
input
->
dims
()[
1
];
...
...
@@ -91,7 +91,8 @@ class GemmConv2DTransposeKernel : public framework::OpKernel<T> {
// col_matrix shares the same piece of data with col,
// but will be reshaped into a two-dimensional matrix shape
// to call the matrix multiplication interface.
Tensor
col_matrix
=
col
;
Tensor
col_matrix
;
col_matrix
.
ShareDataWith
(
col
);
col_matrix
.
Resize
(
col_matrix_shape
);
DDim
output_shape
=
{
c
,
o_h
,
o_w
};
...
...
@@ -100,7 +101,7 @@ class GemmConv2DTransposeKernel : public framework::OpKernel<T> {
DDim
filter_matrix_shape
=
{
m
,
c
*
k_h
*
k_w
};
filter
.
Resize
(
filter_matrix_shape
);
//
deconvolution
: gemm + col2im (similar to conv-backward on input)
//
convolution transpose
: gemm + col2im (similar to conv-backward on input)
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
output
);
...
...
@@ -142,7 +143,7 @@ class GemmConv2DTransposeGradKernel : public framework::OpKernel<T> {
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Filter"
));
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
// Actually, no paddings and groups allowed in
deconv
.
// Actually, no paddings and groups allowed in
conv transpose
.
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
const
int
batch_size
=
input
->
dims
()[
0
];
...
...
@@ -180,11 +181,12 @@ class GemmConv2DTransposeGradKernel : public framework::OpKernel<T> {
DDim
filter_matrix_shape
=
{
m
,
c
*
k_h
*
k_w
};
filter
.
Resize
(
filter_matrix_shape
);
//
deconvolution
grad on input:
//
convolution transpose
grad on input:
// im2col + gemm (similar to conv-forward)
// input need to compute gradient
if
(
input_grad
)
{
Tensor
col_matrix
=
col
;
Tensor
col_matrix
;
col_matrix
.
ShareDataWith
(
col
);
DDim
col_matrix_shape
=
{
c
*
k_h
*
k_w
,
h
*
w
};
col_matrix
.
Resize
(
col_matrix_shape
);
...
...
@@ -216,7 +218,8 @@ class GemmConv2DTransposeGradKernel : public framework::OpKernel<T> {
// filter gradient required
if
(
filter_grad
)
{
Tensor
col_matrix_f
=
col
;
Tensor
col_matrix_f
;
col_matrix_f
.
ShareDataWith
(
col
);
DDim
col_matrix_shape_f
=
{
c
*
h
*
w
,
k_h
*
k_w
};
col_matrix_f
.
Resize
(
col_matrix_shape_f
);
...
...
python/paddle/v2/framework/tests/test_
deconv
_op.py
→
python/paddle/v2/framework/tests/test_
conv2dtranspose
_op.py
浏览文件 @
b3ab3ce0
...
...
@@ -3,14 +3,14 @@ import numpy as np
from
op_test
import
OpTest
def
deconv2d_forward_naive
(
input_
,
filter_
,
deconv
_param
):
def
conv2dtranspose_forward_naive
(
input_
,
filter_
,
conv2dtranspose
_param
):
# [2, 3, 5, 5]
in_n
,
in_c
,
in_h
,
in_w
=
input_
.
shape
# [3, 6, 3, 3]
f_c
,
out_c
,
f_h
,
f_w
=
filter_
.
shape
assert
in_c
==
f_c
stride
,
pad
=
deconv_param
[
'stride'
],
deconv
_param
[
'pad'
]
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
...
...
@@ -32,18 +32,19 @@ def deconv2d_forward_naive(input_, filter_, deconv_param):
return
out
class
Test
Deconv2d
Op
(
OpTest
):
class
Test
Conv2dTranspose
Op
(
OpTest
):
def
setUp
(
self
):
# init as
deconv
# init as
conv transpose
self
.
init_op_type
()
# [2, 3, 5, 5] -> kernel [3, 6, 3, 3] -> output [2, 6, 7, 7]
self
.
init_test_case
()
deconv2d
_param
=
{
'stride'
:
self
.
stride
,
'pad'
:
self
.
pad
}
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
=
deconv2d_forward_naive
(
input_
,
filter_
,
deconv2d_param
)
output
=
conv2dtranspose_forward_naive
(
input_
,
filter_
,
conv2dtranspose_param
)
# print 'deconv output py', output, output.shape
self
.
inputs
=
{
'Input'
:
input_
,
'Filter'
:
filter_
}
...
...
@@ -85,7 +86,7 @@ class TestDeconv2dOp(OpTest):
self
.
filter_size
=
[
f_c
,
6
,
3
,
3
]
def
init_op_type
(
self
):
self
.
op_type
=
"
deconv2d
"
self
.
op_type
=
"
conv2dtranspose
"
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录