Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
4b06d8db
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
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 {
auto
in_x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
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
::
vector
<
int
>
ksize
=
Attr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
...
...
@@ -45,6 +45,15 @@ class PoolOp : public framework::OperatorWithKernel {
"pooling_type should be 'max' or 'avg'"
);
PADDLE_ENFORCE
(
in_x
->
dims
().
size
()
==
4
||
in_x
->
dims
().
size
()
==
5
,
"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
,
"Pooling size should be 2 elements. or 3 elements."
);
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
...
...
@@ -52,12 +61,6 @@ class PoolOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
"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
]});
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
output_shape
.
push_back
(
OutputSizePool
(
in_x
->
dims
()[
i
+
2
],
ksize
[
i
],
...
...
@@ -103,15 +106,16 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
"poolingType of pooling operator."
"str constant equal to 'max' or 'avg'"
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"pooling size(height, width) of pooling operator."
)
.
AddCustomChecker
(
GreaterThanChecker_pool
({
0
,
0
}));
AddAttr
<
int
>
(
"ksize"
,
"Pooling size(depth, height, width) of pooling operator."
"If globalPooling = true, ksize is ignored and need not be specified."
);
AddAttr
<
bool
>
(
"globalPooling"
,
"whether to use the globalPooling."
"int constant equal to
0 or 1
"
"default
0
"
"If globalPooling =
1
, ksize is ignored and need not be specified."
)
.
SetDefault
(
0
);
"int constant equal to
false or true
"
"default
false
"
"If globalPooling =
true
, ksize is ignored and need not be specified."
)
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides(height, width) of pooling operator."
"default {1,1}"
)
...
...
@@ -177,15 +181,16 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
"poolingType of pooling operator."
"str constant equal to 'max' or 'avg'"
);
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"pooling size(depth, height, width) of pooling operator."
)
.
AddCustomChecker
(
GreaterThanChecker_pool
({
0
,
0
,
0
}));
AddAttr
<
int
>
(
"ksize"
,
"pooling size(depth, height, width) of pooling operator."
"If globalPooling = true, ksize is ignored and need not be specified."
);
AddAttr
<
bool
>
(
"globalPooling"
,
"whether to use the globalPooling."
"int constant equal to
0 or 1
"
"default
0
"
"If globalPooling =
1
, ksize is ignored and need not be specified."
)
.
SetDefault
(
0
);
"int constant equal to
false or true
"
"default
false
"
"If globalPooling =
true
, ksize is ignored and need not be specified."
)
.
SetDefault
(
false
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides(depth, height, width) of pooling operator."
...
...
paddle/operators/pool_op.h
浏览文件 @
4b06d8db
...
...
@@ -31,12 +31,12 @@ class PoolKernel : public framework::OpKernel {
const
Tensor
*
in_x
=
context
.
Input
<
Tensor
>
(
"X"
);
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
::
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
)
{
if
(
global_pooling
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
ksize
[
i
]
=
static_cast
<
int
>
(
in_x
->
dims
()[
i
+
2
]);
}
...
...
@@ -92,13 +92,13 @@ class PoolGradKernel : public framework::OpKernel {
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
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
::
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
)
{
if
(
global_pooling
)
{
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录