Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
f0e95a60
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看板
提交
f0e95a60
编写于
11月 06, 2019
作者:
L
liym27
提交者:
Aurelius84
11月 06, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish error messages of pool_2d/3d and add Raises in English document. test=develop (#21017)
上级
fa522dff
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
23 deletion
+62
-23
paddle/fluid/operators/pool_op.cc
paddle/fluid/operators/pool_op.cc
+27
-10
paddle/fluid/operators/pool_op.h
paddle/fluid/operators/pool_op.h
+2
-2
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+29
-7
python/paddle/fluid/tests/unittests/test_pool2d_op.py
python/paddle/fluid/tests/unittests/test_pool2d_op.py
+2
-2
python/paddle/fluid/tests/unittests/test_pool3d_op.py
python/paddle/fluid/tests/unittests/test_pool3d_op.py
+2
-2
未找到文件。
paddle/fluid/operators/pool_op.cc
浏览文件 @
f0e95a60
...
...
@@ -38,10 +38,10 @@ int PoolOutputSize(int input_size, int filter_size, int padding_1,
}
PADDLE_ENFORCE_GT
(
output_size
,
0
,
"
Due to the settings of padding(%d,%d), filter_size(%d) and
"
"
stride(%d), the output size is less than 0, please check
"
"
again. Input_size:%d
"
,
padding_1
,
padding_2
,
filter_size
,
stride
,
input_siz
e
);
"
ShapeError: the output size must be greater than 0. But received:
"
"
output_size = %d due to the settings of input_size(%d), padding(%d,%d),
"
"
k_size(%d) and stride(%d). Please check again!
"
,
output_size
,
input_size
,
padding_1
,
padding_2
,
filter_size
,
strid
e
);
return
output_size
;
}
...
...
@@ -63,13 +63,30 @@ void PoolOp::InferShape(framework::InferShapeContext* ctx) const {
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"padding_algorithm"
);
auto
in_x_dims
=
ctx
->
GetInputDim
(
"X"
);
PADDLE_ENFORCE_EQ
(
in_x_dims
.
size
()
==
4
||
in_x_dims
.
size
()
==
5
,
true
,
"Pooling intput should be 4-D or 5-D tensor."
);
PADDLE_ENFORCE_EQ
(
in_x_dims
.
size
()
==
4
||
in_x_dims
.
size
()
==
5
,
true
,
"ShapeError: the input of Op(pool) should be 4-D or 5-D Tensor. But "
"received: %u-D Tensor and it's shape is [%s]."
,
in_x_dims
.
size
(),
in_x_dims
);
PADDLE_ENFORCE_EQ
(
in_x_dims
.
size
()
-
ksize
.
size
(),
2U
,
"ShapeError: the dimension of input minus the size of "
"Attr(ksize) must be euqal to 2 in Op(pool). "
"But received: the dimension of input minus the size "
"of Attr(ksize) is %d, the "
"input's dimension is %d, the shape of input "
"is [%s], the Attr(ksize)'s size is %d, the Attr(ksize) is [%s]."
,
in_x_dims
.
size
()
-
ksize
.
size
(),
in_x_dims
.
size
(),
in_x_dims
,
ksize
.
size
(),
framework
::
make_ddim
(
ksize
));
PADDLE_ENFORCE_EQ
(
in_x_dims
.
size
()
-
ksize
.
size
(),
2U
,
"Input size and pooling size should be consistent."
);
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
strides
.
size
(),
"Strides size and pooling size should be the same."
);
"ShapeError: the size of Attr(ksize) and Attr(strides) in "
"Op(pool) must be equal. "
"But received: Attr(ksize)'s size is %d, Attr(strides)'s "
"size is %d, Attr(ksize) is [%s], Attr(strides)is [%s]."
,
ksize
.
size
(),
strides
.
size
(),
framework
::
make_ddim
(
ksize
),
framework
::
make_ddim
(
strides
));
const
bool
channel_last
=
(
data_format
==
"NHWC"
||
data_format
==
"NDHWC"
);
...
...
@@ -91,7 +108,7 @@ void PoolOp::InferShape(framework::InferShapeContext* ctx) const {
if
(
adaptive
)
{
output_shape
.
insert
(
output_shape
.
end
(),
ksize
.
begin
(),
ksize
.
end
());
}
else
{
for
(
size_
t
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
for
(
in
t
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
if
((
!
ctx
->
IsRuntime
())
&&
(
data_dims
[
i
]
<
0
))
{
output_shape
.
push_back
(
data_dims
[
i
]);
}
else
{
...
...
paddle/fluid/operators/pool_op.h
浏览文件 @
f0e95a60
...
...
@@ -66,7 +66,7 @@ inline void UpdatePadding(std::vector<int>* paddings, const bool global_pooling,
// set padding size == data_dims.size() * 2
auto
data_shape
=
framework
::
vectorize
<
int
>
(
data_dims
);
if
(
paddings
->
size
()
==
data_dims
.
size
())
{
for
(
size_
t
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
for
(
in
t
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
int
copy_pad
=
*
(
paddings
->
begin
()
+
2
*
i
);
paddings
->
insert
(
paddings
->
begin
()
+
2
*
i
+
1
,
copy_pad
);
}
...
...
@@ -78,7 +78,7 @@ inline void UpdatePadding(std::vector<int>* paddings, const bool global_pooling,
// when padding_desc is "VALID" or "SAME"
if
(
padding_algorithm
==
"SAME"
)
{
for
(
size_
t
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
for
(
in
t
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
int
out_size
=
(
data_dims
[
i
]
+
strides
[
i
]
-
1
)
/
strides
[
0
];
int
pad_sum
=
std
::
max
((
out_size
-
1
)
*
strides
[
i
]
+
ksize
[
i
]
-
data_shape
[
i
],
0
);
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
f0e95a60
...
...
@@ -3458,9 +3458,18 @@ def pool2d(input,
Variable: The output tensor of pooling result. The data type is same as input tensor.
Raises:
ValueError: If `pool_type` is not "max" nor "avg"
ValueError: If `global_pooling` is False and `pool_size` is -1
ValueError: If `use_cudnn` is not a bool value.
ValueError: If `pool_type` is not "max" nor "avg".
ValueError: If `global_pooling` is False and `pool_size` is -1.
TypeError: If `use_cudnn` is not a bool value.
ValueError: If `data_format` is not "NCHW" or "NHWC".
ValueError: If `pool_padding` is a string, but not "SAME" or "VALID".
ValueError: If `pool_padding` is "VALID", but `ceil_mode` is True.
ValueError: If `pool_padding` is a list or tuple, but the elements in the batch or channel dimensions are non-zero.
ShapeError: If the input is not a 4-D or 5-D Tensor.
ShapeError: If the dimension of input minus the size of `pool_stride` is not 2.
ShapeError: If the size of `pool_size` and `pool_stride` is not equal.
ShapeError: If the output's shape calculated is not greater than 0.
Examples:
...
...
@@ -3523,8 +3532,8 @@ def pool2d(input,
"and be a valid value. Received pool_size: %s." % str(pool_size))
if not isinstance(use_cudnn, bool):
raise
Valu
eError("Attr(use_cudnn) should be True or False. Received "
"Attr(use_cudnn): %s." % str(use_cudnn))
raise
Typ
eError("Attr(use_cudnn) should be True or False. Received "
"Attr(use_cudnn): %s." % str(use_cudnn))
if data_format not in ["NCHW", "NHWC"]:
raise ValueError(
...
...
@@ -3663,6 +3672,19 @@ def pool3d(input,
Returns:
Variable: The output tensor of pooling result. The data type is same as input tensor.
Raises:
ValueError: If `pool_type` is not "max" nor "avg".
ValueError: If `global_pooling` is False and `pool_size` is -1.
TypeError: If `use_cudnn` is not a bool value.
ValueError: If `data_format` is not "NCDHW" or "NDHWC".
ValueError: If `pool_padding` is a string, but not "SAME" or "VALID".
ValueError: If `pool_padding` is "VALID", but `ceil_mode` is True.
ValueError: If `pool_padding` is a list or tuple, but the elements in the batch or channel dimensions are non-zero.
ShapeError: If the input is not a 4-D or 5-D Tensor.
ShapeError: If the dimension of input minus the size of `pool_stride` is not 2.
ShapeError: If the size of `pool_size` and `pool_stride` is not equal.
ShapeError: If the output's shape calculated is not greater than 0.
Examples:
.. code-block:: python
...
...
@@ -3730,8 +3752,8 @@ def pool3d(input,
str(pool_size))
if not isinstance(use_cudnn, bool):
raise
Valu
eError("Attr(use_cudnn) should be True or False. Received "
"Attr(use_cudnn): %s. " % str(use_cudnn))
raise
Typ
eError("Attr(use_cudnn) should be True or False. Received "
"Attr(use_cudnn): %s. " % str(use_cudnn))
if data_format not in ["NCDHW", "NDHWC"]:
raise ValueError(
...
...
python/paddle/fluid/tests/unittests/test_pool2d_op.py
浏览文件 @
f0e95a60
...
...
@@ -1179,7 +1179,7 @@ class TestPool2dAPI_Error(OpTest):
dtype
=
"float32"
)
ksize
=
[
3
,
3
]
# cudnn
valu
e error
# cudnn
typ
e error
def
run_1
():
out_1
=
fluid
.
layers
.
pool2d
(
input
=
input_NHWC
,
...
...
@@ -1189,7 +1189,7 @@ class TestPool2dAPI_Error(OpTest):
use_cudnn
=
[
0
],
data_format
=
"NHWC"
)
self
.
assertRaises
(
Valu
eError
,
run_1
)
self
.
assertRaises
(
Typ
eError
,
run_1
)
# data_format value error
def
run_2
():
...
...
python/paddle/fluid/tests/unittests/test_pool3d_op.py
浏览文件 @
f0e95a60
...
...
@@ -1086,7 +1086,7 @@ class TestPool3dAPI_Error(OpTest):
dtype
=
"float32"
)
ksize
=
[
3
,
3
,
3
]
# cudnn
valu
e error
# cudnn
typ
e error
def
run_1
():
out_1
=
fluid
.
layers
.
pool3d
(
input
=
input_NDHWC
,
...
...
@@ -1096,7 +1096,7 @@ class TestPool3dAPI_Error(OpTest):
use_cudnn
=
[
0
],
data_format
=
"NDHWC"
)
self
.
assertRaises
(
Valu
eError
,
run_1
)
self
.
assertRaises
(
Typ
eError
,
run_1
)
# data_format value error
def
run_2
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录