Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
66b84366
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看板
提交
66b84366
编写于
11月 23, 2017
作者:
S
sweetsky0901
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify for code review by wangyi
上级
e553d572
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
45 deletion
+28
-45
paddle/operators/unpool_op.cc
paddle/operators/unpool_op.cc
+12
-14
paddle/operators/unpool_op.h
paddle/operators/unpool_op.h
+16
-31
未找到文件。
paddle/operators/unpool_op.cc
浏览文件 @
66b84366
...
...
@@ -16,11 +16,9 @@
namespace
paddle
{
namespace
operators
{
using
framework
::
Tensor
;
class
Unpool2dOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
Unpool2dOpMaker
(
framework
::
OpProto
*
proto
,
\
Unpool2dOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
...
...
@@ -38,26 +36,26 @@ class Unpool2dOpMaker : public framework::OpProtoAndCheckerMaker {
"the number of channels, H and W is the height and "
"width of feature."
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"(vector
), the unpooling window size(height, width) "
"(vector), the unpooling window size(height, width) "
"of unpooling operator."
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector, default:{1, 1}), "
"strides(height, width) of unpooling operator."
)
"strides
(height, width) of unpooling operator."
)
.
SetDefault
({
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"(vector defalut:{0,0}), "
"paddings(height, width) of unpooling operator."
)
"paddings
(height, width) of unpooling operator."
)
.
SetDefault
({
0
,
0
});
AddAttr
<
std
::
string
>
(
"unpoolingtype"
,
"(string), unpooling type, can be
\"
max
\"
for max-unpooling "
)
.
InEnum
({
"max"
});
AddComment
(
R"DOC(
"input: the input Tensor to invert
"
"indices: the indices given out by MaxPool2d"
"ksize – Size of the max pooling window."
"stride – Stride of the max pooling window."
"It is set to kernel_size by default.
"
"
padding – Padding that was added to the input"
"input: the input Tensor to invert
indices: the indices given out by MaxPool2d
ksize – Size of the max pooling window.
stride – Stride of the max pooling window.
"It is set to kernel_size by default.
padding – Padding that was added to the input"
)DOC"
);
}
};
...
...
@@ -80,14 +78,14 @@ class UnpoolOp : public framework::OperatorWithKernel {
auto
in_x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
in_y_dims
=
ctx
->
GetInputDim
(
"Y"
);
std
::
string
unpoolingtype
=
\
std
::
string
unpoolingtype
=
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"unpoolingtype"
);
std
::
vector
<
int
>
ksize
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"paddings"
);
PADDLE_ENFORCE
(
in_x_dims
.
size
()
==
4
,
"Unpooling intput
should be 4-D
."
);
"Unpooling intput
must be of 4-dimensional
."
);
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
PADDLE_ENFORCE
(
in_x_dims
[
i
]
==
in_y_dims
[
i
],
"X size must be eq Y size!"
);
...
...
paddle/operators/unpool_op.h
浏览文件 @
66b84366
...
...
@@ -21,15 +21,13 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
template
<
typename
Place
,
typename
T
>
class
UnpoolKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
Tensor
*
in_x
=
context
.
Input
<
Tensor
>
(
"X"
);
const
Tensor
*
in_y
=
context
.
Input
<
Tensor
>
(
"Y"
);
auto
*
out
=
context
.
Output
<
Tensor
>
(
"Out"
);
const
framework
::
Tensor
*
in_x
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
const
framework
::
Tensor
*
in_y
=
context
.
Input
<
framework
::
Tensor
>
(
"Y"
);
auto
*
out
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
std
::
string
unpoolingtype
=
context
.
Attr
<
std
::
string
>
(
"unpoolingtype"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
...
...
@@ -39,15 +37,8 @@ class UnpoolKernel : public framework::OpKernel<T> {
math
::
SetConstant
<
Place
,
T
>
set_zero
;
set_zero
(
context
.
device_context
(),
out
,
static_cast
<
T
>
(
0
));
}
switch
(
ksize
.
size
())
{
case
2
:
{
if
(
unpoolingtype
==
"max"
)
{
math
::
Unpool2dMaxFunctor
<
Place
,
T
>
unpool2d_max_forward
;
unpool2d_max_forward
(
context
.
device_context
(),
*
in_x
,
*
in_y
,
out
);
}
}
break
;
default:
{
PADDLE_THROW
(
"Pool op only supports 2D input."
);
}
}
math
::
Unpool2dMaxFunctor
<
Place
,
T
>
unpool2d_max_forward
;
unpool2d_max_forward
(
context
.
device_context
(),
*
in_x
,
*
in_y
,
out
);
}
};
...
...
@@ -55,12 +46,13 @@ template <typename Place, typename T>
class
UnpoolGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
Tensor
*
in_x
=
context
.
Input
<
Tensor
>
(
"X"
);
const
Tensor
*
in_y
=
context
.
Input
<
Tensor
>
(
"Y"
);
const
Tensor
*
out
=
context
.
Input
<
Tensor
>
(
"Out"
);
const
Tensor
*
out_grad
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
Tensor
*
in_x_grad
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
const
framework
::
Tensor
*
in_x
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
const
framework
::
Tensor
*
in_y
=
context
.
Input
<
framework
::
Tensor
>
(
"Y"
);
const
framework
::
Tensor
*
out
=
context
.
Input
<
framework
::
Tensor
>
(
"Out"
);
const
framework
::
Tensor
*
out_grad
=
context
.
Input
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
framework
::
Tensor
*
in_x_grad
=
context
.
Output
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"X"
));
std
::
string
unpoolingtype
=
context
.
Attr
<
std
::
string
>
(
"unpoolingtype"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
...
...
@@ -70,18 +62,11 @@ class UnpoolGradKernel : public framework::OpKernel<T> {
math
::
SetConstant
<
Place
,
T
>
zero
;
if
(
in_x_grad
)
{
in_x_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
zero
(
device_ctx
,
in_x_grad
,
static_cast
<
T
>
(
0.0
));
}
switch
(
ksize
.
size
())
{
case
2
:
{
if
(
unpoolingtype
==
"max"
)
{
math
::
Unpool2dMaxGradFunctor
<
Place
,
T
>
unpool2d_max_backward
;
unpool2d_max_backward
(
context
.
device_context
(),
*
in_x
,
*
in_y
,
in_x_grad
,
*
out
,
*
out_grad
);
}
}
break
;
default:
{
PADDLE_THROW
(
"Unpool op only supports 2D input."
);
}
zero
(
device_ctx
,
in_x_grad
,
static_cast
<
T
>
(
0
));
}
math
::
Unpool2dMaxGradFunctor
<
Place
,
T
>
unpool2d_max_backward
;
unpool2d_max_backward
(
context
.
device_context
(),
*
in_x
,
*
in_y
,
in_x_grad
,
*
out
,
*
out_grad
);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录