Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
fcfce484
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fcfce484
编写于
10月 09, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow coments
上级
14b2c98f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
29 deletion
+65
-29
paddle/operators/CMakeLists.txt
paddle/operators/CMakeLists.txt
+2
-1
paddle/operators/math/pooling.h
paddle/operators/math/pooling.h
+38
-4
paddle/operators/pool_with_index_op.cc
paddle/operators/pool_with_index_op.cc
+10
-10
paddle/operators/pool_with_index_op.cu
paddle/operators/pool_with_index_op.cu
+4
-4
python/paddle/v2/framework/tests/test_pool_max_op.py
python/paddle/v2/framework/tests/test_pool_max_op.py
+11
-10
未找到文件。
paddle/operators/CMakeLists.txt
浏览文件 @
fcfce484
...
...
@@ -75,10 +75,11 @@ function(op_library TARGET)
file
(
APPEND
${
pybind_file
}
"USE_OP(reduce_sum);
\n
"
)
endif
()
# pool_with_index_op contains several operators
if
(
"
${
TARGET
}
"
STREQUAL
"pool_with_index_op"
)
set
(
pybind_flag 1
)
# It's enough to just adding one operator to pybind
file
(
APPEND
${
pybind_file
}
"USE_OP(max
Pool2dWithI
ndex);
\n
"
)
file
(
APPEND
${
pybind_file
}
"USE_OP(max
_pool2d_with_i
ndex);
\n
"
)
endif
()
# pybind USE_NO_KERNEL_OP
...
...
paddle/operators/math/pooling.h
浏览文件 @
fcfce484
...
...
@@ -21,15 +21,26 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
namespace
math
{
//////////////////////
#define FLT_MAX __FLT_MAX__ //
#define FLT_MAX \
__FLT_MAX__ // It might need to be placed in another file, but I'm still
// wondering where to put it
/*
* \brief Extracting simple operations from pooling.
* Both MaxPool and AvgPool need initial, compute and finalize operation.
* MaxPool initializes temp variable to the negative maximum to find the
* maximum value in the pooling field.
* AvgPool initializes temp variable to the zero to accumulate all values
* in pool pooling, and takes the average.
* MaxPoolGrad and AvgPoolGrad are gradient operations respectively.
*/
template
<
class
T
>
class
MaxPool
{
public:
DEVICE
inline
T
initial
()
{
return
static_cast
<
T
>
(
-
FLT_MAX
);
}
DEVICE
inline
void
compute
(
T
&
y
,
const
T
&
x
)
{
y
=
y
>
x
?
y
:
x
;
}
DEVICE
inline
void
finalize
(
T
&
y
,
const
T
&
poo
_size
)
{}
DEVICE
inline
void
finalize
(
T
&
y
,
const
T
&
poo
l_field
)
{}
};
template
<
class
T
>
...
...
@@ -37,8 +48,9 @@ class AvgPool {
public:
DEVICE
inline
T
initial
()
{
return
static_cast
<
T
>
(
0
);
}
DEVICE
inline
void
compute
(
T
&
y
,
const
T
&
x
)
{
y
+=
x
;
}
DEVICE
inline
void
finalize
(
T
&
y
,
const
T
&
poo
_size
)
{
y
/=
poo_size
;
}
DEVICE
inline
void
finalize
(
T
&
y
,
const
T
&
poo
l_field
)
{
y
/=
pool_field
;
}
};
template
<
class
T
>
class
MaxPoolGrad
{
public:
...
...
@@ -57,6 +69,20 @@ class AvgPoolGrad {
}
};
/*
* \brief Getting pooling results, and calculating gradient.
*
* In pool2d, all tensors are in NCHW format. In pool3d, all tensors are in
* NCDHW format.
*
* In max pooling, it is possible that the pooling region has multiple maximum
* elements.
* In this case, we should compute the gradient of the first maximum element.
* This is different from average pooling. So we rewrite the max_pool_grad:
* MaxPool2dGradFunctor, MaxPool3dGradFunctor.
*
*/
template
<
typename
Place
,
typename
PoolProcess
,
typename
T
>
class
Pool2dFunctor
{
public:
...
...
@@ -117,6 +143,14 @@ class MaxPool3dGradFunctor {
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
paddings
);
};
/*
* \brief Getting max pooling results and corresponding max index, and
* calculating gradient.
* In sub-sampling-pooling, it is necessary to know max element index.
* In pool2d, all tensors are in NCHW format. In pool3d, all tensors are in
* NCDHW format.
*
*/
template
<
typename
Place
,
typename
T
>
class
MaxPool2dWithIndexFunctor
{
public:
...
...
paddle/operators/pool_with_index_op.cc
浏览文件 @
fcfce484
...
...
@@ -17,8 +17,8 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
int
OutputSizeMaxPool
(
int
input_size
,
int
filter_size
,
int
padding
,
int
stride
)
{
in
line
in
t
OutputSizeMaxPool
(
int
input_size
,
int
filter_size
,
int
padding
,
int
stride
)
{
int
output_size
=
(
input_size
-
filter_size
+
2
*
padding
)
/
stride
+
1
;
return
output_size
;
}
...
...
@@ -194,24 +194,24 @@ the input and ksize, strides, paddings parameters.
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
max
Pool2dWithI
ndex
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool2dWithIndexOpMaker
,
max
Pool2dWithI
ndex_grad
,
REGISTER_OP
(
max
_pool2d_with_i
ndex
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool2dWithIndexOpMaker
,
max
_pool2d_with_i
ndex_grad
,
ops
::
MaxPoolWithIndexOpGrad
);
REGISTER_OP_CPU_KERNEL
(
max
Pool2dWithI
ndex
,
max
_pool2d_with_i
ndex
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
max
Pool2dWithI
ndex_grad
,
max
_pool2d_with_i
ndex_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
)
REGISTER_OP
(
max
Pool3dWithI
ndex
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool3dWithIndexOpMaker
,
max
Pool3dWithI
ndex_grad
,
REGISTER_OP
(
max
_pool3d_with_i
ndex
,
ops
::
MaxPoolWithIndexOp
,
ops
::
MaxPool3dWithIndexOpMaker
,
max
_pool3d_with_i
ndex_grad
,
ops
::
MaxPoolWithIndexOpGrad
);
REGISTER_OP_CPU_KERNEL
(
max
Pool3dWithI
ndex
,
max
_pool3d_with_i
ndex
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
max
Pool3dWithI
ndex_grad
,
max
_pool3d_with_i
ndex_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
)
paddle/operators/pool_with_index_op.cu
浏览文件 @
fcfce484
...
...
@@ -17,15 +17,15 @@ limitations under the License. */
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
max
Pool2dWithI
ndex
,
max
_pool2d_with_i
ndex
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
max
Pool2dWithI
ndex_grad
,
max
_pool2d_with_i
ndex_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
)
REGISTER_OP_GPU_KERNEL
(
max
Pool3dWithI
ndex
,
max
_pool3d_with_i
ndex
,
ops
::
MaxPoolWithIndexKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
max
Pool3dWithI
ndex_grad
,
max
_pool3d_with_i
ndex_grad
,
ops
::
MaxPoolWithIndexGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
)
python/paddle/v2/framework/tests/test_pool_max_op.py
浏览文件 @
fcfce484
...
...
@@ -100,7 +100,8 @@ class TestMaxPoolWithIndex_Op(OpTest):
def
initTestCase
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"maxPool3dWithIndex"
self
.
index
=
"max_pool3d_with_index"
self
.
op_type
=
"%s"
%
self
.
index
self
.
pool_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
...
...
@@ -111,7 +112,7 @@ class TestMaxPoolWithIndex_Op(OpTest):
class
TestCase1
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"max
Pool3dWithI
ndex"
self
.
op_type
=
"max
_pool3d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
...
...
@@ -122,7 +123,7 @@ class TestCase1(TestMaxPoolWithIndex_Op):
class
TestCase2
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
False
self
.
op_type
=
"max
Pool3dWithI
ndex"
self
.
op_type
=
"max
_pool3d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
...
...
@@ -133,7 +134,7 @@ class TestCase2(TestMaxPoolWithIndex_Op):
class
TestCase3
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
False
self
.
op_type
=
"max
Pool3dWithI
ndex"
self
.
op_type
=
"max
_pool3d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
,
7
]
self
.
ksize
=
[
3
,
3
,
3
]
...
...
@@ -144,7 +145,7 @@ class TestCase3(TestMaxPoolWithIndex_Op):
class
TestCase4
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"max
Pool3dWithI
ndex"
self
.
op_type
=
"max
_pool3d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
...
...
@@ -155,7 +156,7 @@ class TestCase4(TestMaxPoolWithIndex_Op):
class
TestCase5
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"max
Pool3dWithI
ndex"
self
.
op_type
=
"max
_pool3d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool3D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
,
5
]
self
.
ksize
=
[
3
,
3
,
3
]
...
...
@@ -166,7 +167,7 @@ class TestCase5(TestMaxPoolWithIndex_Op):
class
TestCase6
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
False
self
.
op_type
=
"max
Pool2dWithI
ndex"
self
.
op_type
=
"max
_pool2d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
...
...
@@ -177,7 +178,7 @@ class TestCase6(TestMaxPoolWithIndex_Op):
class
TestCase7
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
False
self
.
op_type
=
"max
Pool2dWithI
ndex"
self
.
op_type
=
"max
_pool2d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
7
,
7
]
self
.
ksize
=
[
3
,
3
]
...
...
@@ -188,7 +189,7 @@ class TestCase7(TestMaxPoolWithIndex_Op):
class
TestCase8
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"max
Pool2dWithI
ndex"
self
.
op_type
=
"max
_pool2d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
...
...
@@ -199,7 +200,7 @@ class TestCase8(TestMaxPoolWithIndex_Op):
class
TestCase9
(
TestMaxPoolWithIndex_Op
):
def
initTestCase
(
self
):
self
.
global_pool
=
True
self
.
op_type
=
"max
Pool2dWithI
ndex"
self
.
op_type
=
"max
_pool2d_with_i
ndex"
self
.
pool_forward_naive
=
max_pool2D_forward_naive
self
.
shape
=
[
2
,
3
,
5
,
5
]
self
.
ksize
=
[
3
,
3
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录