x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
shape [N, C, L]. where `N` is batch size, `C` is the number of channels,
shape [N, C, L]. where `N` is batch size, `C` is the number of channels,
`L` is the length of the feature. The data type if float32 or float64.
`L` is the length of the feature. The data type is float32 or float64.
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
it must contain one integers.
it must contain an integer.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain one integers.
it must contain an integer.
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
1. A string in ['valid', 'same'].
it could be the following forms: `[pad_left, pad_right]`. If padding is non-zero,
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
then the input is implicitly zero-padded on both sides for padding number of points.
3. A list[int] or tuple(int) whose length is 1, which means the feature map is zero padded by the size of `padding[0]` on every sides.
4. A list[int] or tuple(int) whose length is 2. It has the form [pad_before, pad_after].
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
count_include_pad (bool): Whether to exclude padding points in average pooling
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is `true`.
mode, default is `True`.
ceil_mode (bool): ${ceil_mode_comment}Whether to use the ceil function to calculate output height and width.
ceil_mode (bool): ${ceil_mode_comment}Whether to use the ceil function to calculate output height and width.
If it is set to False, the floor function will be used. Default False
If it is set to False, the floor function will be used. The default value is False.
name(str, optional): For detailed information, please refer
name(str, optional): For detailed information, please refer
to :ref:`api_guide_Name`. Usually name is no need to set and
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.
None by default.
Returns:
Returns:
Tensor: The output tensor of pooling result. The data type is same as input tensor.
Tensor: The output tensor of pooling result. The data type is same as input tensor.
Raises:
Raises:
ValueError: If `padding` is a string, but not "SAME" or "VALID".
ValueError: If `padding` is a string, but not "SAME" or "VALID".
ValueError: If `padding` is "VALID", but `ceil_mode` is True.
ValueError: If `padding` is "VALID", but `ceil_mode` is True.
ValueError: If `padding` is a list or tuple but its length greater than 1.
ValueError: If `padding` is a list or tuple but its length is greater than 1.
ShapeError: If the input is not a 3-D.
ShapeError: If the input is not a 3-D tensor.
ShapeError: If the output's shape calculated is not greater than 0.
ShapeError: If the output's shape calculated is not greater than 0.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
import paddle
import paddle.nn.functional as F
import paddle.nn.functional as F
paddle.disable_static()
paddle.disable_static()
data = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32]).astype(np.float32))
data = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32]).astype(np.float32))
x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
shape [N, C, L], where `N` is batch size, `C` is the number of channels,
shape [N, C, H, W]. The format of input tensor is `"NCHW"` or
`L` is the length of the feature. The data type if float32 or float64.
`"NHWC"`, where `N` is batch size, `C` is the number of channels,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
`H` is the height of the feature, and `W` is the width of the
it must contain one integers.
feature. The data type if float32 or float64.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If it is a tuple or list,
it must contain one integers.
it must contain two integers, (kernel_size_Height, kernel_size_Width).
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
Otherwise, the pool kernel size will be a square of an int.
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
stride (int|list|tuple): The stride size. If it is a tuple or list,
it could be the following forms: `[pad_left, pad_right]`.
it must contain two integers, (stride_Height, stride_Width).
return_indices (bool): Whether return the max indices along with the outputs. default is `False`.
Otherwise, the stride size will be a square of an int.
ceil_mode (bool): Whether to use the ceil function to calculate output height and width. False is the default.
If it is set to False, the floor function will be used. Default False.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is `true`.
divisor_override (float): if specified, it will be used as divisor, otherwise kernel_size will be used. Default None.
data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NHWC"`.
The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
return_indices (bool): If true, the index of max pooling point will be returned along
Otherwise, the pool kernel size will be the cube of an int.
with outputs. It cannot be set in average pooling type. Default False.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain three integers, [stride_Depth, stride_Height, stride_Width).
Otherwise, the pool stride size will be a cube of an int.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
3. A list[int] or tuple(int) whose length is 3, [pad_depth, pad_height, pad_weight] whose value means the padding size of each dimension.
4. A list[int] or tuple(int) whose length is 6. [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
ceil_mode (bool): ${ceil_mode_comment}
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is True.
divisor_override (int|float) if specified, it will be used as divisor, otherwise kernel_size will be used. Default None.
data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`.
The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
& \text{input}(N_i, C_j, \text{stride[0]} \times h + m,
\text{stride[1]} \times w + n)
$$
Args:
Args:
x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
shape [N, C, H, W]. The format of input tensor is `"NCHW"` or
shape [N, C, L], where `N` is batch size, `C` is the number of channels,
`"NHWC"`, where `N` is batch size, `C` is the number of channels,
`L` is the length of the feature. The data type if float32 or float64.
`H` is the height of the feature, and `W` is the width of the
feature. The data type if float32 or float64.
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
it must contain two integers, (pool_size_Height, pool_size_Width).
it must contain an integer.
Otherwise, the pool kernel size will be a square of an int.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain two integers, (pool_stride_Height, pool_stride_Width).
it must contain an integer.
Otherwise, the pool stride size will be a square of an int.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
1. A string in ['valid', 'same'].
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
2. An integer, which means the feature map is zero padded by size of `padding` on every sides.
it could be in three forms: `[pad_height, pad_width]` or
3. A list[int] or tuple(int) whose length is 1, which means the feature map is zero padded by the size of `padding[0]` on every sides.
`[pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`, and when `data_format` is `"NCHW"`,
4. A list[int] or tuple(int) whose length is 2. It has the form [pad_before, pad_after].
`pool_padding` can be in the form `[[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
when `data_format` is `"NHWC"`, `pool_padding` can be in the form
input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
$$
Args:
Args:
x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
...
@@ -796,30 +627,26 @@ def avg_pool2d(x,
...
@@ -796,30 +627,26 @@ def avg_pool2d(x,
`H` is the height of the feature, and `W` is the width of the
`H` is the height of the feature, and `W` is the width of the
feature. The data type if float32 or float64.
feature. The data type if float32 or float64.
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
it must contain two integers, (pool_size_Height, pool_size_Width).
it must contain two integers, (kernel_size_Height, kernel_size_Width).
Otherwise, the pool kernel size will be a square of an int.
Otherwise, the pool kernel size will be a square of an int.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain two integers, (pool_stride_Height, pool_stride_Width).
it must contain two integers, (stride_Height, stride_Width).
Otherwise, the pool stride size will be a square of an int.
Otherwise, the pool stride size will be a square of an int.
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
1. A string in ['valid', 'same'].
it could be in three forms: `[pad_height, pad_width]` or
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
`[pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`, and when `data_format` is `"NCHW"`,
3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
`pool_padding` can be in the form `[[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
when `data_format` is `"NHWC"`, `pool_padding` can be in the form
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
& \text{input}(N_i, C_j, \text{stride[0]} \times d + k,
\text{stride[1]} \times h + m, \text{stride[2]} \times w + n)
$$
Args:
Args:
x (Tensor): The input tensor of pooling operator, which is a 5-D tensor with
x (Tensor): The input tensor of pooling operator, which is a 5-D tensor with
shape [N, C, D, H, W]. The format of
shape [N, C, D, H, W]. The format of input tensor is `"NCDHW"` or `"NDHWC"`, where N represents batch size, C represents the number of channels, D, H and W represent the depth, height and width of the feature respectively.
input tensor is `"NCDHW"` or `"NDHWC"`, where `N` is batch size, `C` is
kernel_size (int|list|tuple): The pool kernel size. If the kernel size
the number of channels, `D` is the depth of the feature,
`H` is the height of the feature, and `W` is the width
of the feature.
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size
is a tuple or list, it must contain three integers,
is a tuple or list, it must contain three integers,
4. A list[int] or tuple(int) whose length is 6. [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
when `data_format` is `"NDHWC"`, `pool_padding` can be in the form
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
This operation applies a 2D adaptive max pooling on input tensor.
See more details in :ref:`api_nn_pooling_AdaptiveMaxPool2d` .
Args:
x (Tensor): The input tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type can be float16, float32, float64, int32 or int64.
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain two elements, (H, W). H and W can be either a int, or None which means the size will be the same as that of the input.
return_indices (bool): If true, the index of max pooling point will be returned along with outputs. Default False.
name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default.
Returns:
Tensor: The output tensor of adaptive max pool2d result. The data type is same as input tensor.
Examples:
.. code-block:: python
# max adaptive pool2d
# suppose input data in the shape of [N, C, H, W], `output_size` is [m, n]
# output shape is [N, C, m, n], adaptive pool divide H and W dimensions
# of input data into m*n grids averagely and performs poolings in each
# grid to get output.
# adaptive max pool performs calculations as follow:
This operation applies a 3D adaptive max pooling on input tensor.
See more details in :ref:`api_nn_pooling_AdaptiveMaxPool3d` .
Args:
x (Tensor): The input tensor of adaptive max pool3d operator, which is a 5-D tensor. The data type can be float32, float64.
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain three elements, (D, H, W). D, H and W can be either a int, or None which means the size will be the same as that of the input.
return_indices (bool): If true, the index of max pooling point will be returned along with outputs. Default False.
name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default.
Returns:
Tensor: The output tensor of adaptive max pool3d result. The data type is same as input tensor.
Examples:
.. code-block:: python
# adaptive max pool3d
# suppose input data in the shape of [N, C, D, H, W], `output_size` is [l, m, n]
# output shape is [N, C, l, m, n], adaptive pool divide D, H and W dimensions
# of input data into m*n grids averagely and performs poolings in each
# grid to get output.
# adaptive max pool performs calculations as follow:
This operation applies a 1D average pooling over an input signal composed
This operation applies a 1D average pooling over an input signal composed
...
@@ -223,17 +51,20 @@ class AvgPool1d(layers.Layer):
...
@@ -223,17 +51,20 @@ class AvgPool1d(layers.Layer):
Args:
Args:
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
it must contain one integers.
it must contain an integer.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain one integers.
it must contain an integer.
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
1. A string in ['valid', 'same'].
it could be the following forms: `[pad_left, pad_right]`. If padding is non-zero,
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
then the input is implicitly zero-padded on both sides for padding number of points.
3. A list[int] or tuple(int) whose length is 1, which means the feature map is zero padded by the size of `padding[0]` on every sides.
4. A list[int] or tuple(int) whose length is 2. It has the form [pad_before, pad_after].
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
count_include_pad (bool): Whether to exclude padding points in average pooling
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is `true`.
mode, default is `True`.
ceil_mode (bool): ${ceil_mode_comment}Whether to use the ceil function to calculate output height and width.
ceil_mode (bool): ${ceil_mode_comment}Whether to use the ceil function to calculate output height and width.
If it is set to False, the floor function will be used. Default False
If it is set to False, the floor function will be used. The default value is False.
name(str, optional): For detailed information, please refer
name(str, optional): For detailed information, please refer
to :ref:`api_guide_Name`. Usually name is no need to set and
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.
None by default.
...
@@ -245,10 +76,14 @@ class AvgPool1d(layers.Layer):
...
@@ -245,10 +76,14 @@ class AvgPool1d(layers.Layer):
ValueError: If `padding` is a string, but not "SAME" or "VALID".
ValueError: If `padding` is a string, but not "SAME" or "VALID".
ValueError: If `padding` is "VALID", but `ceil_mode` is True.
ValueError: If `padding` is "VALID", but `ceil_mode` is True.
ValueError: If `padding` is a list or tuple but its length greater than 1.
ValueError: If `padding` is a list or tuple but its length greater than 1.
ShapeError: If the input is not a 3-D.
ShapeError: If the input is not a 3-D tensor.
ShapeError: If the output's shape calculated is not greater than 0.
ShapeError: If the output's shape calculated is not greater than 0.
Shape:
- inpuut: 3-D tensor.
- output: 3-D tensor
Examples:
Examples:
.. code-block:: python
.. code-block:: python
...
@@ -284,63 +119,74 @@ class AvgPool1d(layers.Layer):
...
@@ -284,63 +119,74 @@ class AvgPool1d(layers.Layer):
returnout
returnout
classMaxPool1d(layers.Layer):
classAvgPool2d(layers.Layer):
"""
"""
Applies a 1D max pooling over an input signal composed of several input planes based
This operation applies 2D average pooling over input features based on the input,
on the input, output_size, return_indices parameters.
and kernel_size, stride, padding parameters. Input(X) and Output(Out) are
Input(X) and output(Out) are in NCL format, where N is batch
in NCHW format, where N is batch size, C is the number of channels,
size, C is the number of channels, L is the length of the feature.
H is the height of the feature, and W is the width of the feature.
The output value of the layer with input size (N, C, L),
output (N, C, L_{out}) and kernel_size k can be precisely described as
input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
$$
Args:
Args:
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
it must contain one integers.
it must contain two integers, (pool_size_Height, pool_size_Width).
Otherwise, the pool kernel size will be a square of an int.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain one integers.
it must contain two integers, (pool_stride_Height, pool_stride_Width).
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
Otherwise, the pool stride size will be a square of an int.
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
it could be the following forms: `[pad_left, pad_right]`.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
return_indices (bool): Whether return the max indices along with the outputs. default is `False`.
1. A string in ['valid', 'same'].
ceil_mode (bool): Whether to use the ceil function to calculate output height and width. False is the default.
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
If it is set to False, the floor function will be used. Default False
3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is `true`.
divisor_override (float): if specified, it will be used as divisor, otherwise kernel_size will be used. Default None.
data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NDHW"`.
The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
Otherwise, the pool kernel size will be the cube of an int.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain three integers, [stride_Depth, stride_Height, stride_Width).
Otherwise, the pool stride size will be a cube of an int.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
3. A list[int] or tuple(int) whose length is 3, [pad_depth, pad_height, pad_weight] whose value means the padding size of each dimension.
4. A list[int] or tuple(int) whose length is 6. [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
ceil_mode (bool): ${ceil_mode_comment}
count_include_pad (bool): Whether to exclude padding points in average pooling
mode, default is True.
divisor_override (int|float) if specified, it will be used as divisor, otherwise kernel_size will be used. Default None.
data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`.
The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
it must contain one int.
it must contain an integer.
return_indices (bool): If true, the index of max pooling point will be returned along
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
with outputs. It cannot be set in average pooling type. Default False.
it must contain an integer.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same'].
2. An integer, which means the feature map is zero padded by size of `padding` on every sides.
3. A list[int] or tuple(int) whose length is 1, which means the feature map is zero padded by the size of `padding[0]` on every sides.
4. A list[int] or tuple(int) whose length is 2. It has the form [pad_before, pad_after].
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
The default value is 0.
return_indices (bool): Whether return the max indices along with the outputs. default is `False`.
ceil_mode (bool): Whether to use the ceil function to calculate output height and width. False is the default.
If it is set to False, the floor function will be used. Default False.
name(str, optional): For detailed information, please refer
name(str, optional): For detailed information, please refer
to :ref:`api_guide_Name`. Usually name is no need to set and
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.
None by default.
...
@@ -462,53 +350,60 @@ class AdaptiveMaxPool1d(layers.Layer):
...
@@ -462,53 +350,60 @@ class AdaptiveMaxPool1d(layers.Layer):
None.
None.
Raises:
Raises:
ValueError: 'pool_size' should be a integer or list or tuple with length as 1.
ValueError: If `padding` is a string, but not "SAME" or "VALID".
ValueError: If `padding` is "VALID", but `ceil_mode` is True.
ValueError: If `padding` is a list or tuple but its length greater than 1.
ShapeError: If the input is not a 3-D.
ShapeError: If the output's shape calculated is not greater than 0.
Shape:
- x: 3-D tensor.
- out: 3-D tensor.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
# max adaptive pool1d
import paddle
# suppose input data in shape of [N, C, L], `output_size` is m or [m],
# output shape is [N, C, m], adaptive pool divide L dimension
# of input data into m grids averagely and performs poolings in each
# grid to get output.
# adaptive max pool performs calculations as follow:
input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
& \text{input}(N_i, C_j, \text{stride[0]} \times h + m,
\text{stride[1]} \times w + n)
$$
$$
Args:
Args:
...
@@ -532,31 +428,33 @@ class AvgPool2d(layers.Layer):
...
@@ -532,31 +428,33 @@ class AvgPool2d(layers.Layer):
Otherwise, the pool kernel size will be a square of an int.
Otherwise, the pool kernel size will be a square of an int.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain two integers, (pool_stride_Height, pool_stride_Width).
it must contain two integers, (pool_stride_Height, pool_stride_Width).
Otherwise, the pool stride size will be a square of an int. Default: kernel_size.
Otherwise, the pool stride size will be a square of an int.
padding (string|int|list|tuple): The pool padding. If `pool_padding` is a string, either 'VALID' or
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
'SAME' which is the padding algorithm. If pool padding size is a tuple or list,
1. A string in ['valid', 'same'].
it could be in three forms: `[pad_height, pad_width]` or
2. An int, which means the feature map is zero padded by size of `padding` on every sides.
`[pad_height_top, pad_height_bottom, pad_width_left, pad_width_right]`, and when `data_format` is `"NCHW"`,
3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
`pool_padding` can be in the form `[[0,0], [0,0], [pad_height_top, pad_height_bottom], [pad_width_left, pad_width_right]]`.
4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
when `data_format` is `"NHWC"`, `pool_padding` can be in the form
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
3. A list[int] or tuple(int) whose length is 3, [pad_depth, pad_height, pad_weight] whose value means the padding size of each dimension.
and when `data_format` is `"NCDHW"`, `pool_padding` can be in the form
4. A list[int] or tuple(int) whose length is 6. [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
when `data_format` is `"NDHWC"`, `pool_padding` can be in the form
This operation applies 2D adaptive max pooling on input tensor. The h and w dimensions
of the output tensor are determined by the parameter output_size. The difference between adaptive pooling and pooling is adaptive one focus on the output size.
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain two element, (H, W). H and W can be either a int, or None which means the size will be the same as that of the input.
return_indices (bool): If true, the index of max pooling point will be returned along with outputs. It cannot be set in average pooling type. Default False.
name(str, optional): For detailed information, please refer
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.
Shape:
x (Tensor): The input tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type can be float32, float64.
output (Tensor): The output tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type is same as input x.
Returns:
A callable object of AdaptiveMaxPool2d.
Examples:
.. code-block:: python
# adaptive max pool2d
# suppose input data in shape of [N, C, H, W], `output_size` is [m, n],
# output shape is [N, C, m, n], adaptive pool divide H and W dimensions
# of input data into m * n grids averagely and performs poolings in each
# grid to get output.
# adaptive max pool performs calculations as follow:
This operation applies 3D adaptive max pooling on input tensor. The h and w dimensions
of the output tensor are determined by the parameter output_size. The difference between adaptive pooling and pooling is adaptive one focus on the output size.