Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
67edd04a
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
67edd04a
编写于
10月 10, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix doc
上级
0f1d3af4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
31 deletion
+51
-31
paddle/operators/pool_op.cc
paddle/operators/pool_op.cc
+47
-28
paddle/operators/pool_with_index_op.cc
paddle/operators/pool_with_index_op.cc
+4
-3
未找到文件。
paddle/operators/pool_op.cc
浏览文件 @
67edd04a
...
@@ -40,8 +40,6 @@ class PoolOp : public framework::OperatorWithKernel {
...
@@ -40,8 +40,6 @@ class PoolOp : public framework::OperatorWithKernel {
std
::
vector
<
int
>
strides
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
strides
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
paddings
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"paddings"
);
PADDLE_ENFORCE
(
pooling_type
==
"max"
||
pooling_type
==
"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"
);
...
@@ -52,13 +50,11 @@ class PoolOp : public framework::OperatorWithKernel {
...
@@ -52,13 +50,11 @@ class PoolOp : public framework::OperatorWithKernel {
}
}
PADDLE_ENFORCE
(
in_x_dims
.
size
()
-
ksize
.
size
()
==
2U
,
PADDLE_ENFORCE
(
in_x_dims
.
size
()
-
ksize
.
size
()
==
2U
,
"Input size and Pooling size should be consistent."
);
"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
(),
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
"
s
trides size and pooling size should be the same."
);
"
S
trides size and pooling size should be the same."
);
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
"
p
addings size and pooling size should be the same."
);
"
P
addings size and pooling size should be the same."
);
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
)
{
...
@@ -75,10 +71,9 @@ class PoolOpGrad : public framework::OperatorWithKernel {
...
@@ -75,10 +71,9 @@ class PoolOpGrad : public framework::OperatorWithKernel {
protected:
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) must not be null."
);
"X(Input) of Pooling should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
"Input
@Grad of Pooling
should not be null."
);
"Input
(X@GRAD)
should not be null."
);
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"X"
));
}
}
};
};
...
@@ -94,17 +89,22 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -94,17 +89,22 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
"number of channels, H and W is the height and width of feature."
);
"number of channels, H and W is the height and width of feature."
);
AddOutput
(
"Out"
,
AddOutput
(
"Out"
,
"The output tensor of pooling operator."
"The output tensor of pooling operator."
"The format of output tensor is also NCHW."
);
"The format of output tensor is also NCHW."
"Where N is batch size, C is "
"the number of channels, H and W is the height and "
"width of feature."
);
AddAttr
<
std
::
string
>
(
"poolingType"
,
AddAttr
<
std
::
string
>
(
"poolingType"
,
"PoolingType of pooling operator."
"PoolingType of pooling operator."
"Str constant equal to 'max' or 'avg'."
)
"Str constant equal to 'max' or 'avg'."
)
.
InEnum
({
"max"
,
"avg"
});
.
InEnum
({
"max"
,
"avg"
});
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"ksize"
,
"
Pooling size(depth,
height, width) of pooling operator."
"
The pooling size(
height, width) of pooling operator."
"If globalPooling = true, ksize is ignored and need not be "
"If globalPooling = true, ksize is ignored and need not be "
"specified."
);
// TODO(Add checker)
"specified."
);
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
bool
>
(
AddAttr
<
bool
>
(
"globalPooling"
,
"globalPooling"
,
"Whether to use the globalPooling."
"Whether to use the globalPooling."
...
@@ -114,15 +114,22 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -114,15 +114,22 @@ class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker {
.
SetDefault
(
false
);
.
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}."
)
.
SetDefault
({
1
,
1
});
// TODO(Add checker)
.
SetDefault
({
1
,
1
});
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"Paddings(height, width) of pooling operator."
"Paddings(height, width) of pooling operator."
"Default {0,0}."
)
"Default {0,0}."
)
.
SetDefault
({
0
,
0
});
// TODO(Add checker)
.
SetDefault
({
0
,
0
});
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddComment
(
R"DOC(
AddComment
(
R"DOC(
The pooling2d operation calculates the output based on
The pooling2d operation calculates the output based on
the input, poolingType and ksize, strides, paddings parameters.
the input, poolingType and ksize, strides, paddings parameters.
Input(X) and output(Out) are in NCHW format. Where N is batch size, C is the
number of channels, H and W is the height and width of feature.
Parameters(ksize, strides, paddings) are two elements.
These two elements represent height and width, respectively.
)DOC"
);
)DOC"
);
}
}
};
};
...
@@ -131,25 +138,30 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -131,25 +138,30 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
public:
public:
Pool3dOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
Pool3dOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
AddInput
(
"The input tensor of pooling operator. "
"X"
,
"The format of input tensor is NCDHW. Where N is batch size, C is
"
"The input tensor of pooling operator.
"
"the
"
"The format of input tensor is NCDHW. Where N is batch size, C is
"
"
number of channels, D, H and W is the depth, height and width of "
"the
number of channels, D, H and W is the depth, height and width of "
"feature."
);
"feature."
);
AddOutput
(
"Out"
,
AddOutput
(
"Out"
,
"The output tensor of pooling operator."
"The output tensor of pooling operator."
"The format of output tensor is also NCDHW."
);
"The format of output tensor is also NCDHW."
"Where N is batch size, C is "
"the number of channels, D, H and W is the depth, height and "
"width of feature."
);
AddAttr
<
std
::
string
>
(
"poolingType"
,
AddAttr
<
std
::
string
>
(
"poolingType"
,
"PoolingType of pooling operator."
"PoolingType of pooling operator."
"
s
tr constant equal to 'max' or 'avg'."
)
"
S
tr constant equal to 'max' or 'avg'."
)
.
InEnum
({
"max"
,
"avg"
});
.
InEnum
({
"max"
,
"avg"
});
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"ksize"
,
"ksize"
,
"
P
ooling size(depth, height, width) of pooling operator."
"
The p
ooling size(depth, height, width) of pooling operator."
"If globalPooling = true, ksize is ignored and need not be "
"If globalPooling = true, ksize is ignored and need not be "
"specified."
);
// TODO(Add checker)
"specified."
);
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
bool
>
(
AddAttr
<
bool
>
(
"globalPooling"
,
"globalPooling"
,
"Whether to use the globalPooling."
"Whether to use the globalPooling."
...
@@ -161,15 +173,22 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -161,15 +173,22 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
"strides"
,
"strides"
,
"Strides(depth, height, width) of pooling operator."
"Strides(depth, height, width) of pooling operator."
"Default {1,1,1}."
)
"Default {1,1,1}."
)
.
SetDefault
({
1
,
1
,
1
});
// TODO(Add checker)
.
SetDefault
({
1
,
1
,
1
});
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"paddings"
,
"Paddings(depth, height, width) of pooling operator."
"Paddings(depth, height, width) of pooling operator."
"Default {0,0,0}."
)
"Default {0,0,0}."
)
.
SetDefault
({
0
,
0
,
0
});
// TODO(Add checker)
.
SetDefault
({
0
,
0
,
0
});
// TODO(Chengduo): Add checker. (Currently,
// TypedAttrChecker don't support vector type.)
AddComment
(
R"DOC(
AddComment
(
R"DOC(
The pooling3d operation calculates the output based on
The pooling3d operation calculates the output based on
the input, poolingType and ksize, strides, paddings parameters.
the input, poolingType and ksize, strides, paddings parameters.
Input(X) and output(Out) are in NCDHW format. Where N is batch
size, C is the number of channels, D, H and W is the depth, height and
width of feature. Parameters(ksize, strides, paddings) are three elements.
These three elements represent depth, height and width, respectively.
)DOC"
);
)DOC"
);
}
}
};
};
...
...
paddle/operators/pool_with_index_op.cc
浏览文件 @
67edd04a
...
@@ -28,7 +28,7 @@ class MaxPoolWithIndexOp : public framework::OperatorWithKernel {
...
@@ -28,7 +28,7 @@ class MaxPoolWithIndexOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
protected:
void
InferShape
(
framework
::
InferShapeContext
Base
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"X(Input) of Pooling should not be null."
);
"X(Input) of Pooling should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
...
@@ -52,7 +52,7 @@ class MaxPoolWithIndexOp : public framework::OperatorWithKernel {
...
@@ -52,7 +52,7 @@ class MaxPoolWithIndexOp : public framework::OperatorWithKernel {
}
}
PADDLE_ENFORCE
(
in_x_dims
.
size
()
-
ksize
.
size
()
==
2U
,
PADDLE_ENFORCE
(
in_x_dims
.
size
()
-
ksize
.
size
()
==
2U
,
"In
t
put size and pooling size should be consistent."
);
"Input size and pooling size should be consistent."
);
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
"Strides size and pooling size should be the same."
);
"Strides size and pooling size should be the same."
);
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
paddings
.
size
(),
...
@@ -73,7 +73,8 @@ class MaxPoolWithIndexOpGrad : public framework::OperatorWithKernel {
...
@@ -73,7 +73,8 @@ class MaxPoolWithIndexOpGrad : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
protected:
void
InferShape
(
framework
::
InferShapeContextBase
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Mask"
),
"Input(Mask) must not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) must not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) must not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
framework
::
GradVarName
(
"X"
)),
"Input(X@GRAD) should not be null."
);
"Input(X@GRAD) should not be null."
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录