Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6fc9a9fd
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
6fc9a9fd
编写于
11月 28, 2017
作者:
S
sweetsky0901
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify for del T2 and doc update
上级
ee0a794c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
52 addition
and
50 deletion
+52
-50
paddle/operators/math/unpooling.cc
paddle/operators/math/unpooling.cc
+10
-10
paddle/operators/math/unpooling.cu
paddle/operators/math/unpooling.cu
+18
-21
paddle/operators/math/unpooling.h
paddle/operators/math/unpooling.h
+2
-2
paddle/operators/unpool_op.cc
paddle/operators/unpool_op.cc
+12
-7
paddle/operators/unpool_op.cu.cc
paddle/operators/unpool_op.cu.cc
+4
-4
paddle/operators/unpool_op.h
paddle/operators/unpool_op.h
+4
-4
python/paddle/v2/fluid/tests/test_unpool_op.py
python/paddle/v2/fluid/tests/test_unpool_op.py
+2
-2
未找到文件。
paddle/operators/math/unpooling.cc
浏览文件 @
6fc9a9fd
...
...
@@ -19,8 +19,8 @@ namespace operators {
namespace
math
{
// All tensors are in NCHW format
template
<
typename
T
,
typename
T2
>
class
Unpool2dMaxFunctor
<
platform
::
CPUPlace
,
T
,
T2
>
{
template
<
typename
T
>
class
Unpool2dMaxFunctor
<
platform
::
CPUPlace
,
T
>
{
public:
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
...
...
@@ -35,7 +35,7 @@ class Unpool2dMaxFunctor<platform::CPUPlace, T, T2> {
int
input_feasize
=
input_height
*
input_width
;
int
output_feasize
=
output_height
*
output_width
;
const
T
*
input_data
=
input
.
data
<
T
>
();
const
T2
*
indices_data
=
indices
.
data
<
T2
>
();
const
int
*
indices_data
=
indices
.
data
<
int
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
for
(
int
b
=
0
;
b
<
batch_size
;
++
b
)
{
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
...
...
@@ -54,8 +54,8 @@ class Unpool2dMaxFunctor<platform::CPUPlace, T, T2> {
template
<
class
T
,
typename
T2
>
class
Unpool2dMaxGradFunctor
<
platform
::
CPUPlace
,
T
,
T2
>
{
template
<
class
T
>
class
Unpool2dMaxGradFunctor
<
platform
::
CPUPlace
,
T
>
{
public:
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
...
...
@@ -71,7 +71,7 @@ public:
const
int
output_width
=
output
.
dims
()[
3
];
int
input_feasize
=
input_height
*
input_width
;
int
output_feasize
=
output_height
*
output_width
;
const
T2
*
indices_data
=
indices
.
data
<
T2
>
();
const
int
*
indices_data
=
indices
.
data
<
int
>
();
const
T
*
output_grad_data
=
output_grad
.
data
<
T
>
();
T
*
input_grad_data
=
input_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
...
...
@@ -90,10 +90,10 @@ public:
}
};
template
class
Unpool2dMaxGradFunctor
<
platform
::
CPUPlace
,
float
,
int
>;
template
class
Unpool2dMaxGradFunctor
<
platform
::
CPUPlace
,
double
,
int
>;
template
class
Unpool2dMaxFunctor
<
platform
::
CPUPlace
,
float
,
int
>;
template
class
Unpool2dMaxFunctor
<
platform
::
CPUPlace
,
double
,
int
>;
template
class
Unpool2dMaxGradFunctor
<
platform
::
CPUPlace
,
float
>;
template
class
Unpool2dMaxGradFunctor
<
platform
::
CPUPlace
,
double
>;
template
class
Unpool2dMaxFunctor
<
platform
::
CPUPlace
,
float
>;
template
class
Unpool2dMaxFunctor
<
platform
::
CPUPlace
,
double
>;
}
// namespace math
}
// namespace operators
...
...
paddle/operators/math/unpooling.cu
浏览文件 @
6fc9a9fd
...
...
@@ -19,10 +19,10 @@ namespace paddle {
namespace
operators
{
namespace
math
{
template
<
typename
T
,
typename
T2
>
template
<
typename
T
>
__global__
void
KernelUnpool2dMax
(
const
int
nthreads
,
const
T
*
input_data
,
const
T2
*
indices_data
,
const
int
*
indices_data
,
const
int
input_height
,
const
int
input_width
,
const
int
channels
,
...
...
@@ -45,10 +45,10 @@ __global__ void KernelUnpool2dMax(const int nthreads,
output_data
[
out_offset
+
out_index
]
=
input_data
[
i
];
}
}
template
<
typename
T
,
typename
T2
>
template
<
typename
T
>
__global__
void
KernelUnpool2dMaxGrad
(
const
int
nthreads
,
const
T
*
input_data
,
const
T2
*
indices_data
,
const
int
*
indices_data
,
const
int
input_height
,
const
int
input_width
,
const
int
channels
,
...
...
@@ -76,8 +76,8 @@ __global__ void KernelUnpool2dMaxGrad(const int nthreads,
/*
* All tensors are in NCHW format.
*/
template
<
typename
T
,
typename
T2
>
class
Unpool2dMaxFunctor
<
platform
::
GPUPlace
,
T
,
T2
>
{
template
<
typename
T
>
class
Unpool2dMaxFunctor
<
platform
::
GPUPlace
,
T
>
{
public:
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
...
...
@@ -90,15 +90,14 @@ class Unpool2dMaxFunctor<platform::GPUPlace, T, T2> {
const
int
output_height
=
output
->
dims
()[
2
];
const
int
output_width
=
output
->
dims
()[
3
];
const
T
*
input_data
=
input
.
data
<
T
>
();
const
T2
*
indices_data
=
indices
.
data
<
T2
>
();
const
int
*
indices_data
=
indices
.
data
<
int
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
int
nthreads
=
batch_size
*
output_channels
*
input_height
*
input_width
;
int
threads
=
1024
;
int
grid
=
(
input
.
numel
()
+
threads
-
1
)
/
threads
;
KernelUnpool2dMax
<
T
,
T2
><<<
grid
,
threads
,
0
,
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
nthreads
,
input_data
,
indices_data
,
.
stream
()
>>>
(
input
.
numel
()
,
input_data
,
indices_data
,
input_height
,
input_width
,
output_channels
,
output_data
,
output_height
,
output_width
);
}
...
...
@@ -106,8 +105,8 @@ class Unpool2dMaxFunctor<platform::GPUPlace, T, T2> {
/*
* All tensors are in NCHW format.
*/
template
<
typename
T
,
typename
T2
>
class
Unpool2dMaxGradFunctor
<
platform
::
GPUPlace
,
T
,
T2
>
{
template
<
typename
T
>
class
Unpool2dMaxGradFunctor
<
platform
::
GPUPlace
,
T
>
{
public:
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
...
...
@@ -122,18 +121,16 @@ class Unpool2dMaxGradFunctor<platform::GPUPlace, T, T2> {
const
int
output_height
=
output
.
dims
()[
2
];
const
int
output_width
=
output
.
dims
()[
3
];
const
T
*
input_data
=
input
.
data
<
T
>
();
const
T2
*
indices_data
=
indices
.
data
<
T2
>
();
const
int
*
indices_data
=
indices
.
data
<
int
>
();
const
T
*
output_data
=
output
.
data
<
T
>
();
const
T
*
output_grad_data
=
output_grad
.
data
<
T
>
();
T
*
input_grad_data
=
input_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
int
nthreads
=
batch_size
*
output_channels
*
input_height
*
input_width
;
int
threads
=
1024
;
int
grid
=
(
input
.
numel
()
+
threads
-
1
)
/
threads
;
KernelUnpool2dMaxGrad
<
T
,
T2
><<<
grid
,
threads
,
0
,
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
nthreads
,
input_data
,
indices_data
,
.
stream
()
>>>
(
input
.
numel
(),
input_data
,
indices_data
,
input_height
,
input_width
,
output_channels
,
output_data
,
output_grad_data
,
output_height
,
output_width
,
...
...
@@ -141,11 +138,11 @@ class Unpool2dMaxGradFunctor<platform::GPUPlace, T, T2> {
}
};
template
class
Unpool2dMaxGradFunctor
<
platform
::
GPUPlace
,
float
,
int
>;
template
class
Unpool2dMaxGradFunctor
<
platform
::
GPUPlace
,
double
,
int
>;
template
class
Unpool2dMaxGradFunctor
<
platform
::
GPUPlace
,
float
>;
template
class
Unpool2dMaxGradFunctor
<
platform
::
GPUPlace
,
double
>;
template
class
Unpool2dMaxFunctor
<
platform
::
GPUPlace
,
float
,
int
>;
template
class
Unpool2dMaxFunctor
<
platform
::
GPUPlace
,
double
,
int
>;
template
class
Unpool2dMaxFunctor
<
platform
::
GPUPlace
,
float
>;
template
class
Unpool2dMaxFunctor
<
platform
::
GPUPlace
,
double
>;
}
// namespace math
}
// namespace operators
...
...
paddle/operators/math/unpooling.h
浏览文件 @
6fc9a9fd
...
...
@@ -19,7 +19,7 @@ namespace paddle {
namespace
operators
{
namespace
math
{
template
<
typename
Place
,
typename
T
,
typename
T2
>
template
<
typename
Place
,
typename
T
>
class
Unpool2dMaxFunctor
{
public:
...
...
@@ -29,7 +29,7 @@ class Unpool2dMaxFunctor {
framework
::
Tensor
*
output
);
};
template
<
typename
Place
,
class
T
,
typename
T2
>
template
<
typename
Place
,
class
T
>
class
Unpool2dMaxGradFunctor
{
public:
void
operator
()(
const
platform
::
DeviceContext
&
context
,
...
...
paddle/operators/unpool_op.cc
浏览文件 @
6fc9a9fd
...
...
@@ -50,10 +50,15 @@ class Unpool2dOpMaker : public framework::OpProtoAndCheckerMaker {
"(string), unpooling type, can be
\"
max
\"
for max-unpooling "
)
.
InEnum
({
"max"
});
AddComment
(
R"DOC(
"Paper: http://www.matthewzeiler.com/wp-content/uploads/2017
"Input shape: $(N, C_{in}, H_{in}, W_{in})$
Output shape: $(N, C_{out}, H_{out}, W_{out})$
Where
$$
H_{out} = (H_{in}−1) * strides[0] − 2 * paddings[0] + ksize[0] \\
W_{out} = (W_{in}−1) * strides[1] − 2 * paddings[1] + ksize[1]
$$
Paper: http://www.matthewzeiler.com/wp-content/uploads/2017
/07/iccv2011.pdf
PyTorch: http://pytorch.org/docs/master/nn.html?highlight=unpool#
torch.nn.MaxUnpool2d"
)DOC"
);
}
};
...
...
@@ -125,9 +130,9 @@ namespace ops = paddle::operators;
REGISTER_OP
(
unpool
,
ops
::
UnpoolOp
,
ops
::
Unpool2dOpMaker
,
unpool_grad
,
ops
::
UnpoolOpGrad
);
REGISTER_OP_CPU_KERNEL
(
unpool
,
ops
::
UnpoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
,
int
>
,
ops
::
UnpoolKernel
<
paddle
::
platform
::
CPUPlace
,
double
,
int
>
);
ops
::
UnpoolKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
UnpoolKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
unpool_grad
,
ops
::
UnpoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
,
int
>
,
ops
::
UnpoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
,
int
>
);
ops
::
UnpoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
UnpoolGradKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
paddle/operators/unpool_op.cu.cc
浏览文件 @
6fc9a9fd
...
...
@@ -16,10 +16,10 @@ limitations under the License. */
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
unpool
,
ops
::
UnpoolKernel
<
paddle
::
platform
::
GPUPlace
,
float
,
int
>
,
ops
::
UnpoolKernel
<
paddle
::
platform
::
GPUPlace
,
double
,
int
>
);
ops
::
UnpoolKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
,
ops
::
UnpoolKernel
<
paddle
::
platform
::
GPUPlace
,
double
>
);
REGISTER_OP_GPU_KERNEL
(
unpool_grad
,
ops
::
UnpoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
,
int
>
,
float
>
,
ops
::
UnpoolGradKernel
<
paddle
::
platform
::
GPUPlace
,
double
,
int
>
);
double
>
);
paddle/operators/unpool_op.h
浏览文件 @
6fc9a9fd
...
...
@@ -21,7 +21,7 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
template
<
typename
Place
,
typename
T
,
typename
T2
>
template
<
typename
Place
,
typename
T
>
class
UnpoolKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
...
...
@@ -37,12 +37,12 @@ class UnpoolKernel : public framework::OpKernel<T> {
math
::
SetConstant
<
Place
,
T
>
set_zero
;
set_zero
(
context
.
device_context
(),
out
,
static_cast
<
T
>
(
0
));
}
math
::
Unpool2dMaxFunctor
<
Place
,
T
,
T2
>
unpool2d_max_forward
;
math
::
Unpool2dMaxFunctor
<
Place
,
T
>
unpool2d_max_forward
;
unpool2d_max_forward
(
context
.
device_context
(),
*
in_x
,
*
in_y
,
out
);
}
};
template
<
typename
Place
,
typename
T
,
typename
T2
>
template
<
typename
Place
,
typename
T
>
class
UnpoolGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
...
...
@@ -64,7 +64,7 @@ class UnpoolGradKernel : public framework::OpKernel<T> {
in_x_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
zero
(
device_ctx
,
in_x_grad
,
static_cast
<
T
>
(
0
));
}
math
::
Unpool2dMaxGradFunctor
<
Place
,
T
,
T2
>
unpool2d_max_backward
;
math
::
Unpool2dMaxGradFunctor
<
Place
,
T
>
unpool2d_max_backward
;
unpool2d_max_backward
(
context
.
device_context
(),
*
in_x
,
*
in_y
,
*
out
,
*
out_grad
,
in_x_grad
);
}
...
...
python/paddle/v2/fluid/tests/test_unpool_op.py
浏览文件 @
6fc9a9fd
...
...
@@ -50,7 +50,7 @@ class TestUnpoolOp(OpTest):
indices
[
nidx
,
cidx
,
i
,
j
]
=
\
(
r_start
+
arg
/
self
.
ksize
[
1
])
*
wsize
+
\
c_start
+
arg
%
self
.
ksize
[
1
]
output
=
self
.
U
npool2d_forward_naive
(
input
,
indices
,
self
.
ksize
,
\
output
=
self
.
u
npool2d_forward_naive
(
input
,
indices
,
self
.
ksize
,
\
self
.
strides
,
self
.
paddings
).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
input
.
astype
(
'float32'
),
'Indices'
:
indices
.
astype
(
'int32'
)}
...
...
@@ -69,7 +69,7 @@ class TestUnpoolOp(OpTest):
self
.
check_grad
([
'X'
],
'Out'
)
def
init_test_case
(
self
):
self
.
U
npool2d_forward_naive
=
unpool2dmax_forward_naive
self
.
u
npool2d_forward_naive
=
unpool2dmax_forward_naive
self
.
unpooling_type
=
"max"
self
.
shape
=
[
6
,
4
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录