Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
84a2512b
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看板
提交
84a2512b
编写于
9月 22, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix parameter name and function define
上级
50b8ec05
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
129 addition
and
118 deletion
+129
-118
paddle/operators/math/pooling.cc
paddle/operators/math/pooling.cc
+12
-12
paddle/operators/math/pooling.cu
paddle/operators/math/pooling.cu
+12
-12
paddle/operators/math/pooling.h
paddle/operators/math/pooling.h
+12
-12
paddle/operators/pool_op.cc
paddle/operators/pool_op.cc
+51
-36
paddle/operators/pool_op.h
paddle/operators/pool_op.h
+34
-38
python/paddle/v2/framework/tests/test_pool2d_op.py
python/paddle/v2/framework/tests/test_pool2d_op.py
+4
-4
python/paddle/v2/framework/tests/test_pool3d_op.py
python/paddle/v2/framework/tests/test_pool3d_op.py
+4
-4
未找到文件。
paddle/operators/math/pooling.cc
浏览文件 @
84a2512b
...
...
@@ -21,10 +21,10 @@ namespace math {
template
<
typename
PoolProcess
,
typename
T
>
class
Pool2dForwardFunctor
<
platform
::
CPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_height
=
input
.
dims
()[
2
];
const
int
input_width
=
input
.
dims
()[
3
];
...
...
@@ -75,12 +75,12 @@ class Pool2dForwardFunctor<platform::CPUPlace, PoolProcess, T> {
template
<
typename
PoolProcess
,
class
T
>
class
Pool2dBackwardFunctor
<
platform
::
CPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
const
framework
::
Tensor
&
output
,
const
framework
::
Tensor
&
output_grad
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_height
=
input
.
dims
()[
2
];
const
int
input_width
=
input
.
dims
()[
3
];
...
...
@@ -154,10 +154,10 @@ template class Pool2dBackwardFunctor<
template
<
typename
PoolProcess
,
class
T
>
class
Pool3dForwardFunctor
<
platform
::
CPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_depth
=
input
.
dims
()[
2
];
const
int
input_height
=
input
.
dims
()[
3
];
...
...
@@ -224,12 +224,12 @@ class Pool3dForwardFunctor<platform::CPUPlace, PoolProcess, T> {
template
<
typename
PoolProcess
,
class
T
>
class
Pool3dBackwardFunctor
<
platform
::
CPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
const
framework
::
Tensor
&
output
,
const
framework
::
Tensor
&
output_grad
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_depth
=
input
.
dims
()[
2
];
const
int
input_height
=
input
.
dims
()[
3
];
...
...
paddle/operators/math/pooling.cu
浏览文件 @
84a2512b
...
...
@@ -105,10 +105,10 @@ __global__ void KernelPool2dBackward(
template
<
typename
PoolProcess
,
typename
T
>
class
Pool2dForwardFunctor
<
platform
::
GPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_channels
=
input
.
dims
()[
1
];
const
int
input_height
=
input
.
dims
()[
2
];
...
...
@@ -148,12 +148,12 @@ class Pool2dForwardFunctor<platform::GPUPlace, PoolProcess, T> {
template
<
typename
PoolProcess
,
typename
T
>
class
Pool2dBackwardFunctor
<
platform
::
GPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
const
framework
::
Tensor
&
output
,
const
framework
::
Tensor
&
output_grad
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_channels
=
input
.
dims
()[
1
];
const
int
input_height
=
input
.
dims
()[
2
];
...
...
@@ -319,10 +319,10 @@ __global__ void KernelPool3DBackward(
template
<
typename
PoolProcess
,
class
T
>
class
Pool3dForwardFunctor
<
platform
::
GPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_channels
=
input
.
dims
()[
1
];
const
int
input_depth
=
input
.
dims
()[
2
];
...
...
@@ -369,12 +369,12 @@ class Pool3dForwardFunctor<platform::GPUPlace, PoolProcess, T> {
template
<
typename
PoolProcess
,
class
T
>
class
Pool3dBackwardFunctor
<
platform
::
GPUPlace
,
PoolProcess
,
T
>
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
const
framework
::
Tensor
&
output
,
const
framework
::
Tensor
&
output_grad
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
)
{
PoolProcess
pool_process
)
{
const
int
batch_size
=
input
.
dims
()[
0
];
const
int
input_channels
=
input
.
dims
()[
1
];
const
int
input_depth
=
input
.
dims
()[
2
];
...
...
paddle/operators/math/pooling.h
浏览文件 @
84a2512b
...
...
@@ -59,41 +59,41 @@ class avePool {
template
<
typename
Place
,
typename
PoolProcess
,
typename
T
>
class
Pool2dForwardFunctor
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
);
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
);
};
template
<
typename
Place
,
typename
PoolProcess
,
typename
T
>
class
Pool2dBackwardFunctor
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
const
framework
::
Tensor
&
output
,
const
framework
::
Tensor
&
output_grad
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
);
PoolProcess
pool_process
);
};
template
<
typename
Place
,
typename
PoolProcess
,
typename
T
>
class
Pool3dForwardFunctor
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
output
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
);
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
);
};
template
<
typename
Place
,
typename
PoolProcess
,
typename
T
>
class
Pool3dBackwardFunctor
{
public:
void
operator
()(
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
void
operator
()(
const
platform
::
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
framework
::
Tensor
&
input_grad
,
const
framework
::
Tensor
&
output
,
const
framework
::
Tensor
&
output_grad
,
std
::
vector
<
int
>&
ksize
,
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
,
PoolProcess
pool_process
,
const
platform
::
DeviceContext
&
context
);
PoolProcess
pool_process
);
};
}
// namespace math
...
...
paddle/operators/pool_op.cc
浏览文件 @
84a2512b
...
...
@@ -28,18 +28,18 @@ class PoolOp : public framework::OperatorWithKernel {
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"
Input
"
),
"
Input
(Input) of Pooling should not be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Out
put
"
),
"Out
put
(Output) of Pooling should not be null."
);
// PADDLE_ENFORCE_NOT_NULL(Attr<std::string>("pooling
_t
ype"),
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"
X
"
),
"
X
(Input) of Pooling should not be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Out"
),
"Out(Output) of Pooling should not be null."
);
// PADDLE_ENFORCE_NOT_NULL(Attr<std::string>("pooling
T
ype"),
// "pooling_type should not be null.");
// PADDLE_ENFORCE_NOT_NULL(Attr<std::vector<int>>("ksize"), "ksize should
// not be null.");
auto
in
put
=
ctx
.
Input
<
Tensor
>
(
"Input
"
);
auto
out
put
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Outp
ut"
);
int
global_pooling
=
Attr
<
int
>
(
"global
_p
ooling"
);
std
::
string
pooling_type
=
Attr
<
std
::
string
>
(
"pooling
_t
ype"
);
auto
in
_X
=
ctx
.
Input
<
Tensor
>
(
"X
"
);
auto
out
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"O
ut"
);
int
global_pooling
=
Attr
<
int
>
(
"global
P
ooling"
);
std
::
string
pooling_type
=
Attr
<
std
::
string
>
(
"pooling
T
ype"
);
std
::
vector
<
int
>
ksize
=
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
...
...
@@ -50,25 +50,25 @@ class PoolOp : public framework::OperatorWithKernel {
"Pooling ksize should be 2-D or 3-D"
);
if
(
global_pooling
==
1
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
in
put
->
dims
()[
i
+
2
];
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
in
_X
->
dims
()[
i
+
2
];
}
if
(
ksize
.
size
()
==
2
)
{
PADDLE_ENFORCE_EQ
(
in
put
->
dims
().
size
(),
4
,
PADDLE_ENFORCE_EQ
(
in
_X
->
dims
().
size
(),
4
,
"Pool2DOp intput should be 4-D."
);
PADDLE_ENFORCE_EQ
(
strides
.
size
(),
2
,
"Pool2DOp strides should be 2-D."
);
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
2
,
"Pool2DOp paddings should be 2-D."
);
}
else
{
PADDLE_ENFORCE_EQ
(
in
put
->
dims
().
size
(),
5
,
PADDLE_ENFORCE_EQ
(
in
_X
->
dims
().
size
(),
5
,
"Pool3DOp intput should be 5-D."
);
PADDLE_ENFORCE_EQ
(
strides
.
size
(),
3
,
"Pool3DOp strides should be 3-D."
);
PADDLE_ENFORCE_EQ
(
paddings
.
size
(),
3
,
"Pool3DOp paddings should be 3-D."
);
}
std
::
vector
<
int64_t
>
output_shape
({
in
put
->
dims
()[
0
],
input
->
dims
()[
1
]});
std
::
vector
<
int64_t
>
output_shape
({
in
_X
->
dims
()[
0
],
in_X
->
dims
()[
1
]});
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
output_shape
.
push_back
(
outputSize_pool
(
in
put
->
dims
()[
i
+
2
],
ksize
[
i
],
output_shape
.
push_back
(
outputSize_pool
(
in
_X
->
dims
()[
i
+
2
],
ksize
[
i
],
paddings
[
i
],
strides
[
i
]));
}
out
put
->
Resize
(
framework
::
make_ddim
(
output_shape
));
out
->
Resize
(
framework
::
make_ddim
(
output_shape
));
}
};
...
...
@@ -78,9 +78,8 @@ class PoolOpGrad : public framework::OperatorWithKernel {
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
in
=
ctx
.
Input
<
Tensor
>
(
"Input"
);
auto
d_in
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"Input"
));
auto
in
=
ctx
.
Input
<
Tensor
>
(
"X"
);
auto
d_in
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
if
(
d_in
)
d_in
->
Resize
(
in
->
dims
());
}
};
...
...
@@ -90,27 +89,36 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
Pool3dOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"
Input
"
,
"
X
"
,
"The input tensor of pooling 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 "
"image."
);
AddOutput
(
"Out
put
"
,
AddOutput
(
"Out"
,
"The output tensor of pooling operator."
"The format of output tensor is also NCDHW."
);
AddAttr
<
std
::
string
>
(
"pooling_type"
,
"pooling_type of pooling operator.['max' or 'ave']"
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"strides of pooling operator."
);
AddAttr
<
int
>
(
"global_pooling"
,
"whether to use the global_pooling."
)
AddAttr
<
std
::
string
>
(
"poolingType"
,
"poolingType of pooling operator.['max' or 'ave']"
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"pooling size(depth, height, width) of pooling operator."
);
AddAttr
<
int
>
(
"globalPooling"
,
"default 0"
"whether to use the globalPooling."
)
.
SetDefault
(
0
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides of pooling operator."
)
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"default {1,1,1}"
"strides(depth, height, width) of pooling operator."
)
.
SetDefault
({
1
,
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"paddings of pooling operator."
)
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"default {0,0,0}"
"paddings(depth, height, width) of pooling operator."
)
.
SetDefault
({
0
,
0
,
0
});
AddComment
(
R"DOC(
The pooling3d operation calculates the output based on
the input, pooling
_t
ype and ksize, strides, paddings parameters.
the input, pooling
T
ype and ksize, strides, paddings parameters.
)DOC"
);
}
};
...
...
@@ -120,26 +128,33 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
Pool2dOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"
Input
"
,
"
X
"
,
"The input tensor of pooling operator. "
"The format of input tensor is NCHW. Where N is batch size, C is the "
"number of channels, H and W is the height and width of image."
);
AddOutput
(
"Out
put
"
,
AddOutput
(
"Out"
,
"The output tensor of pooling operator."
"The format of output tensor is also NCHW."
);
AddAttr
<
std
::
string
>
(
"pooling_type"
,
"pooling_type of pooling operator.['max' or 'ave']"
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"strides of pooling operator."
);
AddAttr
<
int
>
(
"global_pooling"
,
"whether to use the global_pooling."
)
AddAttr
<
std
::
string
>
(
"poolingType"
,
"poolingType of pooling operator.['max' or 'ave']"
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"pooling size(height, width) of pooling operator."
);
AddAttr
<
int
>
(
"globalPooling"
,
"default 0"
"whether to use the globalPooling.[0 or 1]"
)
.
SetDefault
(
0
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides of pooling operator."
)
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"default {1, 1}"
"strides(height, width) of pooling operator."
)
.
SetDefault
({
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"paddings of pooling operator."
)
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"default {0, 0}"
"paddings(height, width) of pooling operator."
)
.
SetDefault
({
0
,
0
});
AddComment
(
R"DOC(
The pooling2d operation calculates the output based on
the input, pooling
_t
ype and ksize, strides, paddings parameters.
the input, pooling
T
ype and ksize, strides, paddings parameters.
)DOC"
);
}
};
...
...
paddle/operators/pool_op.h
浏览文件 @
84a2512b
...
...
@@ -28,17 +28,17 @@ template <typename Place, typename T>
class
PoolKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
Tensor
*
in
put
=
context
.
Input
<
Tensor
>
(
"Input
"
);
Tensor
*
out
put
=
context
.
Output
<
Tensor
>
(
"Outp
ut"
);
const
Tensor
*
in
_X
=
context
.
Input
<
Tensor
>
(
"X
"
);
Tensor
*
out
=
context
.
Output
<
Tensor
>
(
"O
ut"
);
int
global_pooling
=
context
.
Attr
<
int
>
(
"global
_p
ooling"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"pooling
_t
ype"
);
int
global_pooling
=
context
.
Attr
<
int
>
(
"global
P
ooling"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"pooling
T
ype"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
if
(
global_pooling
==
1
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
ksize
[
i
]
=
in
put
->
dims
()[
i
+
2
];
ksize
[
i
]
=
in
_X
->
dims
()[
i
+
2
];
}
}
...
...
@@ -49,16 +49,16 @@ class PoolKernel : public framework::OpKernel {
Place
,
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
,
T
>
pool2d_forward
;
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
pool_process
;
pool2d_forward
(
*
input
,
*
output
,
ksize
,
strides
,
padding
s
,
p
ool_process
,
context
.
device_context
()
);
pool2d_forward
(
context
.
device_context
(),
*
in_X
,
*
out
,
ksize
,
stride
s
,
p
addings
,
pool_process
);
}
else
if
(
pooling_type
==
"ave"
)
{
paddle
::
operators
::
math
::
Pool2dForwardFunctor
<
Place
,
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
,
T
>
pool2d_forward
;
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
pool_process
;
pool2d_forward
(
*
input
,
*
output
,
ksize
,
strides
,
padding
s
,
p
ool_process
,
(
context
.
device_context
())
);
pool2d_forward
(
context
.
device_context
(),
*
in_X
,
*
out
,
ksize
,
stride
s
,
p
addings
,
pool_process
);
}
}
break
;
case
3
:
{
...
...
@@ -67,15 +67,15 @@ class PoolKernel : public framework::OpKernel {
Place
,
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
,
T
>
pool3d_forward
;
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
pool_process
;
pool3d_forward
(
*
input
,
*
output
,
ksize
,
strides
,
padding
s
,
p
ool_process
,
context
.
device_context
()
);
pool3d_forward
(
context
.
device_context
(),
*
in_X
,
*
out
,
ksize
,
stride
s
,
p
addings
,
pool_process
);
}
else
if
(
pooling_type
==
"ave"
)
{
paddle
::
operators
::
math
::
Pool3dForwardFunctor
<
Place
,
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
,
T
>
pool3d_forward
;
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
pool_process
;
pool3d_forward
(
*
input
,
*
output
,
ksize
,
strides
,
padding
s
,
p
ool_process
,
context
.
device_context
()
);
pool3d_forward
(
context
.
device_context
(),
*
in_X
,
*
out
,
ksize
,
stride
s
,
p
addings
,
pool_process
);
}
}
break
;
}
...
...
@@ -86,26 +86,26 @@ template <typename Place, typename T>
class
PoolGradKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
Tensor
*
in
put
=
context
.
Input
<
Tensor
>
(
"Input
"
);
const
Tensor
*
out
put
=
context
.
Input
<
Tensor
>
(
"Outp
ut"
);
const
Tensor
*
out
put
_grad
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out
put
"
));
Tensor
*
in
put
_grad
=
context
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"
Input
"
));
int
global_pooling
=
context
.
Attr
<
int
>
(
"global
_p
ooling"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"pooling
_t
ype"
);
const
Tensor
*
in
_X
=
context
.
Input
<
Tensor
>
(
"X
"
);
const
Tensor
*
out
=
context
.
Input
<
Tensor
>
(
"O
ut"
);
const
Tensor
*
out_grad
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
Tensor
*
in
_X
_grad
=
context
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"
X
"
));
int
global_pooling
=
context
.
Attr
<
int
>
(
"global
P
ooling"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"pooling
T
ype"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
if
(
global_pooling
==
1
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
in
put
->
dims
()[
i
+
2
];
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
in
_X
->
dims
()[
i
+
2
];
}
if
(
in
put
_grad
)
{
in
put
_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
temp
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
in
put
_grad
);
if
(
in
_X
_grad
)
{
in
_X
_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
temp
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
in
_X
_grad
);
temp
.
device
(
context
.
GetEigenDevice
<
Place
>
())
=
temp
.
constant
(
static_cast
<
T
>
(
0
));
...
...
@@ -116,17 +116,15 @@ class PoolGradKernel : public framework::OpKernel {
Place
,
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
,
T
>
pool2d_backward
;
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
pool_process
;
pool2d_backward
(
*
input
,
*
input_grad
,
*
output
,
*
output_grad
,
ksize
,
strides
,
paddings
,
pool_process
,
context
.
device_context
());
pool2d_backward
(
context
.
device_context
(),
*
in_X
,
*
in_X_grad
,
*
out
,
*
out_grad
,
ksize
,
strides
,
paddings
,
pool_process
);
}
else
if
(
pooling_type
==
"ave"
)
{
paddle
::
operators
::
math
::
Pool2dBackwardFunctor
<
Place
,
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
,
T
>
pool2d_backward
;
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
pool_process
;
pool2d_backward
(
*
input
,
*
input_grad
,
*
output
,
*
output_grad
,
ksize
,
strides
,
paddings
,
pool_process
,
context
.
device_context
());
pool2d_backward
(
context
.
device_context
(),
*
in_X
,
*
in_X_grad
,
*
out
,
*
out_grad
,
ksize
,
strides
,
paddings
,
pool_process
);
}
}
break
;
case
3
:
{
...
...
@@ -135,17 +133,15 @@ class PoolGradKernel : public framework::OpKernel {
Place
,
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
,
T
>
pool3d_backward
;
paddle
::
operators
::
math
::
pool
::
maxPool
<
T
>
pool_process
;
pool3d_backward
(
*
input
,
*
input_grad
,
*
output
,
*
output_grad
,
ksize
,
strides
,
paddings
,
pool_process
,
context
.
device_context
());
pool3d_backward
(
context
.
device_context
(),
*
in_X
,
*
in_X_grad
,
*
out
,
*
out_grad
,
ksize
,
strides
,
paddings
,
pool_process
);
}
else
if
(
pooling_type
==
"ave"
)
{
paddle
::
operators
::
math
::
Pool3dBackwardFunctor
<
Place
,
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
,
T
>
pool3d_backward
;
paddle
::
operators
::
math
::
pool
::
avePool
<
T
>
pool_process
;
pool3d_backward
(
*
input
,
*
input_grad
,
*
output
,
*
output_grad
,
ksize
,
strides
,
paddings
,
pool_process
,
context
.
device_context
());
pool3d_backward
(
context
.
device_context
(),
*
in_X
,
*
in_X_grad
,
*
out
,
*
out_grad
,
ksize
,
strides
,
paddings
,
pool_process
);
}
}
break
;
}
...
...
python/paddle/v2/framework/tests/test_pool2d_op.py
浏览文件 @
84a2512b
...
...
@@ -47,23 +47,23 @@ class TestPool2d_Op(OpTest):
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
output
=
self
.
pool2D_forward_naive
(
input
,
self
.
ksize
,
self
.
strides
,
self
.
paddings
)
self
.
inputs
=
{
'
Input
'
:
input
}
self
.
inputs
=
{
'
X
'
:
input
}
self
.
attrs
=
{
'strides'
:
self
.
strides
,
'paddings'
:
self
.
paddings
,
'ksize'
:
self
.
ksize
,
'pooling
_t
ype'
:
self
.
pool_type
,
'pooling
T
ype'
:
self
.
pool_type
,
}
self
.
outputs
=
{
'Out
put
'
:
output
}
self
.
outputs
=
{
'Out'
:
output
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
if
self
.
pool_type
!=
"max"
:
self
.
check_grad
(
set
([
'
Input'
]),
'Outp
ut'
,
max_relative_error
=
0.07
)
self
.
check_grad
(
set
([
'
X'
]),
'O
ut'
,
max_relative_error
=
0.07
)
def
initTestCase
(
self
):
self
.
pool_type
=
"ave"
...
...
python/paddle/v2/framework/tests/test_pool3d_op.py
浏览文件 @
84a2512b
...
...
@@ -57,23 +57,23 @@ class TestPool3d_Op(OpTest):
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
output
=
self
.
pool3D_forward_naive
(
input
,
self
.
ksize
,
self
.
strides
,
self
.
paddings
)
self
.
inputs
=
{
'
Input
'
:
input
}
self
.
inputs
=
{
'
X
'
:
input
}
self
.
attrs
=
{
'strides'
:
self
.
strides
,
'paddings'
:
self
.
paddings
,
'ksize'
:
self
.
ksize
,
'pooling
_t
ype'
:
self
.
pool_type
,
'pooling
T
ype'
:
self
.
pool_type
,
}
self
.
outputs
=
{
'Out
put
'
:
output
}
self
.
outputs
=
{
'Out'
:
output
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
if
self
.
pool_type
!=
"max"
:
self
.
check_grad
(
set
([
'
Input'
]),
'Outp
ut'
,
max_relative_error
=
0.07
)
self
.
check_grad
(
set
([
'
X'
]),
'O
ut'
,
max_relative_error
=
0.07
)
def
initTestCase
(
self
):
self
.
pool_type
=
"ave"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录