Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4b06d8db
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
4b06d8db
编写于
9月 26, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix globalPooling type (int => bool)
上级
30a586df
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
30 addition
and
25 deletion
+30
-25
paddle/operators/pool_op.cc
paddle/operators/pool_op.cc
+26
-21
paddle/operators/pool_op.h
paddle/operators/pool_op.h
+4
-4
未找到文件。
paddle/operators/pool_op.cc
浏览文件 @
4b06d8db
...
@@ -35,7 +35,7 @@ class PoolOp : public framework::OperatorWithKernel {
...
@@ -35,7 +35,7 @@ class PoolOp : public framework::OperatorWithKernel {
auto
in_x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
auto
in_x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
auto
out
=
ctx
.
Output
<
Tensor
>
(
"Out"
);
auto
out
=
ctx
.
Output
<
Tensor
>
(
"Out"
);
int
global_pooling
=
Attr
<
int
>
(
"globalPooling"
);
bool
global_pooling
=
Attr
<
bool
>
(
"globalPooling"
);
std
::
string
pooling_type
=
Attr
<
std
::
string
>
(
"poolingType"
);
std
::
string
pooling_type
=
Attr
<
std
::
string
>
(
"poolingType"
);
std
::
vector
<
int
>
ksize
=
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
ksize
=
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
strides
=
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
...
@@ -45,6 +45,15 @@ class PoolOp : public framework::OperatorWithKernel {
...
@@ -45,6 +45,15 @@ class PoolOp : public framework::OperatorWithKernel {
"pooling_type should be 'max' or 'avg'"
);
"pooling_type should be 'max' or 'avg'"
);
PADDLE_ENFORCE
(
in_x
->
dims
().
size
()
==
4
||
in_x
->
dims
().
size
()
==
5
,
PADDLE_ENFORCE
(
in_x
->
dims
().
size
()
==
4
||
in_x
->
dims
().
size
()
==
5
,
"Pooling intput should be 4-D or 5-D"
);
"Pooling intput should be 4-D or 5-D"
);
if
(
global_pooling
)
{
ksize
.
resize
(
static_cast
<
size_t
>
(
in_x
->
dims
().
size
())
-
2
);
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
}
PADDLE_ENFORCE
(
in_x
->
dims
().
size
()
==
static_cast
<
size_t
>
(
ksize
.
size
()
+
2
),
"Input size and Pooling size should be consistent."
);
PADDLE_ENFORCE
(
ksize
.
size
()
==
2
||
ksize
.
size
()
==
3
,
PADDLE_ENFORCE
(
ksize
.
size
()
==
2
||
ksize
.
size
()
==
3
,
"Pooling size should be 2 elements. or 3 elements."
);
"Pooling size should be 2 elements. or 3 elements."
);
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
...
@@ -52,12 +61,6 @@ class PoolOp : public framework::OperatorWithKernel {
...
@@ -52,12 +61,6 @@ class PoolOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
"paddings size and pooling size should be the same."
);
"paddings size and pooling size should be the same."
);
if
(
global_pooling
==
1
)
{
ksize
.
resize
(
static_cast
<
size_t
>
(
in_x
->
dims
().
size
())
-
2
);
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
}
std
::
vector
<
int64_t
>
output_shape
({
in_x
->
dims
()[
0
],
in_x
->
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
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
output_shape
.
push_back
(
OutputSizePool
(
in_x
->
dims
()[
i
+
2
],
ksize
[
i
],
output_shape
.
push_back
(
OutputSizePool
(
in_x
->
dims
()[
i
+
2
],
ksize
[
i
],
...
@@ -103,15 +106,16 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -103,15 +106,16 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
"poolingType of pooling operator."
"poolingType of pooling operator."
"str constant equal to 'max' or 'avg'"
);
"str constant equal to 'max' or 'avg'"
);
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"pooling size(height, width) of pooling operator."
)
"ksize"
,
.
AddCustomChecker
(
GreaterThanChecker_pool
({
0
,
0
}));
"Pooling size(depth, height, width) of pooling operator."
AddAttr
<
int
>
(
"If globalPooling = true, ksize is ignored and need not be specified."
);
AddAttr
<
bool
>
(
"globalPooling"
,
"globalPooling"
,
"whether to use the globalPooling."
"whether to use the globalPooling."
"int constant equal to
0 or 1
"
"int constant equal to
false or true
"
"default
0
"
"default
false
"
"If globalPooling =
1
, ksize is ignored and need not be specified."
)
"If globalPooling =
true
, ksize is ignored and need not be specified."
)
.
SetDefault
(
0
);
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides(height, width) of pooling operator."
"strides(height, width) of pooling operator."
"default {1,1}"
)
"default {1,1}"
)
...
@@ -177,15 +181,16 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -177,15 +181,16 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
"poolingType of pooling operator."
"poolingType of pooling operator."
"str constant equal to 'max' or 'avg'"
);
"str constant equal to 'max' or 'avg'"
);
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"pooling size(depth, height, width) of pooling operator."
)
"ksize"
,
.
AddCustomChecker
(
GreaterThanChecker_pool
({
0
,
0
,
0
}));
"pooling size(depth, height, width) of pooling operator."
AddAttr
<
int
>
(
"If globalPooling = true, ksize is ignored and need not be specified."
);
AddAttr
<
bool
>
(
"globalPooling"
,
"globalPooling"
,
"whether to use the globalPooling."
"whether to use the globalPooling."
"int constant equal to
0 or 1
"
"int constant equal to
false or true
"
"default
0
"
"default
false
"
"If globalPooling =
1
, ksize is ignored and need not be specified."
)
"If globalPooling =
true
, ksize is ignored and need not be specified."
)
.
SetDefault
(
0
);
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides"
,
"strides(depth, height, width) of pooling operator."
"strides(depth, height, width) of pooling operator."
...
...
paddle/operators/pool_op.h
浏览文件 @
4b06d8db
...
@@ -31,12 +31,12 @@ class PoolKernel : public framework::OpKernel {
...
@@ -31,12 +31,12 @@ class PoolKernel : public framework::OpKernel {
const
Tensor
*
in_x
=
context
.
Input
<
Tensor
>
(
"X"
);
const
Tensor
*
in_x
=
context
.
Input
<
Tensor
>
(
"X"
);
Tensor
*
out
=
context
.
Output
<
Tensor
>
(
"Out"
);
Tensor
*
out
=
context
.
Output
<
Tensor
>
(
"Out"
);
int
global_pooling
=
context
.
Attr
<
int
>
(
"globalPooling"
);
bool
global_pooling
=
context
.
Attr
<
bool
>
(
"globalPooling"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"poolingType"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"poolingType"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
if
(
global_pooling
==
1
)
{
if
(
global_pooling
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
}
}
...
@@ -92,13 +92,13 @@ class PoolGradKernel : public framework::OpKernel {
...
@@ -92,13 +92,13 @@ class PoolGradKernel : public framework::OpKernel {
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
Tensor
*
in_x_grad
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
Tensor
*
in_x_grad
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
int
global_pooling
=
context
.
Attr
<
int
>
(
"globalPooling"
);
bool
global_pooling
=
context
.
Attr
<
bool
>
(
"globalPooling"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"poolingType"
);
std
::
string
pooling_type
=
context
.
Attr
<
std
::
string
>
(
"poolingType"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
ksize
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
strides
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
paddings
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
if
(
global_pooling
==
1
)
{
if
(
global_pooling
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录