提交 f0e95a60 编写于 作者: L liym27 提交者: Aurelius84

Polish error messages of pool_2d/3d and add Raises in English document. test=develop (#21017)

上级 fa522dff
......@@ -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_size);
"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, stride);
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 (int i = 0; i < data_dims.size(); ++i) {
if ((!ctx->IsRuntime()) && (data_dims[i] < 0)) {
output_shape.push_back(data_dims[i]);
} else {
......
......@@ -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 (int 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 (int 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);
......
......@@ -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,7 +3532,7 @@ def pool2d(input,
"and be a valid value. Received pool_size: %s." % str(pool_size))
if not isinstance(use_cudnn, bool):
raise ValueError("Attr(use_cudnn) should be True or False. Received "
raise TypeError("Attr(use_cudnn) should be True or False. Received "
"Attr(use_cudnn): %s." % str(use_cudnn))
if data_format not in ["NCHW", "NHWC"]:
......@@ -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,7 +3752,7 @@ def pool3d(input,
str(pool_size))
if not isinstance(use_cudnn, bool):
raise ValueError("Attr(use_cudnn) should be True or False. Received "
raise TypeError("Attr(use_cudnn) should be True or False. Received "
"Attr(use_cudnn): %s. " % str(use_cudnn))
if data_format not in ["NCDHW", "NDHWC"]:
......
......@@ -1179,7 +1179,7 @@ class TestPool2dAPI_Error(OpTest):
dtype="float32")
ksize = [3, 3]
# cudnn value error
# cudnn type 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(ValueError, run_1)
self.assertRaises(TypeError, run_1)
# data_format value error
def run_2():
......
......@@ -1086,7 +1086,7 @@ class TestPool3dAPI_Error(OpTest):
dtype="float32")
ksize = [3, 3, 3]
# cudnn value error
# cudnn type 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(ValueError, run_1)
self.assertRaises(TypeError, 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.
先完成此消息的编辑!
想要评论请 注册