未验证 提交 40e6c57b 编写于 作者: W Wei Shengyu 提交者: GitHub

fix doc of Pooling layers (#31977)

* fix doc of MaxPool1D

* fix doc

* fix doc format error

* dbg

* fix doc

* dbg doc format test=document_fix

* fix format test=document_fix

* test doc

* remove - from doc

* fix indent

* remove space before bracket

* dbg format

* fix indent test=document_fix

* remove new line

* fix descrip of Shape test=document_fix

* add description for default value test=document_fix

* fix bug test=document_fix
上级 83b953f5
...@@ -33,7 +33,7 @@ __all__ = [ ...@@ -33,7 +33,7 @@ __all__ = [
class AvgPool1D(layers.Layer): class AvgPool1D(layers.Layer):
""" r"""
This operation applies a 1D average pooling over an input signal composed This operation applies a 1D average pooling over an input signal composed
of several input planes, based on the input, output_size, return_mask parameters. of several input planes, based on the input, output_size, return_mask parameters.
Input(X) and output(Out) are in NCL format, where N is batch Input(X) and output(Out) are in NCL format, where N is batch
...@@ -41,36 +41,33 @@ class AvgPool1D(layers.Layer): ...@@ -41,36 +41,33 @@ class AvgPool1D(layers.Layer):
The output tensor shape will be [N, C, output_size]. The output tensor shape will be [N, C, output_size].
The output value of the layer with input size (N, C, L), 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 output (N, C, :math:`L_{out}`) and kernel_size ksize can be precisely described as
For average pool1d: For average pool1d:
.. math:: .. math::
Output(N_i, C_i, l) &= mean(Input[N_i, C_i, stride \times l:stride \times l+k]) Output(N_i, C_i, l) = \frac{Input[N_i, C_i, stride \times l:stride \times l+k]}{ksize}
Parameters:
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 an integer.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain an integer. it must contain an integer.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms. stride(int|list|tuple, optional): The pool stride size. If pool stride size is a tuple or list,
it must contain an integer. Default None, then stride will be equal to the kernel_size.
padding(str|int|list|tuple, optional): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same']. 1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides. 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 1, which means the feature map is zero padded by the size of `padding[0]` 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]. 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). 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. The default value is 0.
exclusive (bool): Whether to exclude padding points in average pooling exclusive(bool, optional): Whether to exclude padding points in average pooling mode, default is `True`.
mode, default is `True`. ceil_mode(bool, optional): ${ceil_mode_comment}Whether to use the ceil function to calculate output height
ceil_mode (bool): ${ceil_mode_comment}Whether to use the ceil function to calculate output height and width. and width. If it is set to False, the floor function will be used. The default value is False.
If it is set to False, the floor function will be used. The default value is False. name(str, optional): For eed to detailed information, please refer to :ref:`api_guide_Name`.
name(str, optional): For detailed information, please refer Usually name is no nset and None by default.
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.
Returns: Returns:
None. A callable object of AvgPool1D.
Raises: Raises:
ValueError: If `padding` is a string, but not "SAME" or "VALID". ValueError: If `padding` is a string, but not "SAME" or "VALID".
...@@ -79,23 +76,24 @@ class AvgPool1D(layers.Layer): ...@@ -79,23 +76,24 @@ class AvgPool1D(layers.Layer):
ShapeError: If the input is not a 3-D tensor. 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: Shape:
- inpuut: 3-D tensor. - x(Tensor): The input tensor of avg pool1d operator, which is a 3-D tensor.
- output: 3-D tensor The data type can be float32, float64.
- output(Tensor): The output tensor of avg pool1d operator, which is a 3-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
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))
AvgPool1D = nn.AvgPool1D(kernel_size=2, stride=2, padding=0) AvgPool1D = nn.AvgPool1D(kernel_size=2, stride=2, padding=0)
pool_out = AvgPool1D(data) pool_out = AvgPool1D(data)
# pool_out shape: [1, 3, 16] # pool_out shape: [1, 3, 16]
""" """
...@@ -132,49 +130,53 @@ class AvgPool2D(layers.Layer): ...@@ -132,49 +130,53 @@ class AvgPool2D(layers.Layer):
H is the height of the feature, and W is the width of the feature. H is the height of the feature, and W is the width of the feature.
Example: Example:
Input: Input:
X shape: $(N, C, H_{in}, W_{in})$ X shape: :math:`(N, C, :math:`H_{in}`, :math:`W_{in}`)`
Attr: Attr:
kernel_size: ksize kernel_size: ksize
Output: Output:
Out shape: $(N, C, H_{out}, W_{out})$ Out shape: :math:`(N, C, :math:`H_{out}`, :math:`W_{out}`)`
$$
out(N_i, C_j, h, w) = \frac{1}{ksize[0] * ksize[1]} \sum_{m=0}^{ksize[0]-1} \sum_{n=0}^{ksize[1]-1} .. math::
input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
$$ Output(N_i, C_j, h, w) = \frac{\sum_{m=0}^{ksize[0]-1} \sum_{n=0}^{ksize[1]-1}
Input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)}{ksize[0] * ksize[1]}
Args:
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, Parameters:
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, (pool_size_Height, pool_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, optional): 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. Otherwise, the pool stride size will be a square of an int.
Default None, then stride will be equal to the kernel_size.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms. padding(str|int|list|tuple, optional): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same']. 1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides. 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. 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. 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). 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. The default value is 0.
ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape ceil_mode(bool, optional): When True, will use `ceil` instead of `floor` to compute the output shape.
exclusive (bool): Whether to exclude padding points in average pooling exclusive(bool, optional): Whether to exclude padding points in average pooling
mode, default is `true`. mode, default is `true`.
divisor_override (float): if specified, it will be used as divisor, otherwise kernel_size will be used. Default None. divisor_override(float, optional): If specified, it will be used as divisor, otherwise kernel_size will be
data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NDHW"`. used. Default None.
The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of: data_format(str, optional): The data format of the input and output data. An optional string from: `"NCHW"`,
`[batch_size, input_channels, input_height, input_width]`. `"NDHW"`. The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
name(str, optional): For detailed information, please refer `[batch_size, input_channels, input_height, input_width]`.
to :ref:`api_guide_Name`. Usually name is no need to set and name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
None by default. Usually name is no need to set and None by default.
Shape: Shape:
- x: 4-D tensor. - x(Tensor): The input tensor of avg pool2d operator, which is a 4-D tensor.
- out: 2-D tensor The data type can be float32, float64.
- output(Tensor): The output tensor of avg pool2d operator, which is a 4-D tensor.
The data type is same as input x.
Returns: None. Returns:
A callable object of AvgPool2D.
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.
...@@ -182,16 +184,16 @@ class AvgPool2D(layers.Layer): ...@@ -182,16 +184,16 @@ class AvgPool2D(layers.Layer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
# max pool2d # max pool2d
input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32)) input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32))
AvgPool2D = nn.AvgPool2D(kernel_size=2, AvgPool2D = nn.AvgPool2D(kernel_size=2,
stride=2, padding=0) stride=2, padding=0)
output = AvgPool2D(input) output = AvgPool2D(input)
# output.shape [1, 3, 16, 16] # output.shape [1, 3, 16, 16]
""" """
...@@ -238,61 +240,64 @@ class AvgPool3D(layers.Layer): ...@@ -238,61 +240,64 @@ class AvgPool3D(layers.Layer):
in NCDHW format, where N is batch size, C is the number of channels, in NCDHW format, where N is batch size, C is the number of channels,
H is the height of the feature, D is the depth of the feature, and W is the width of the feature. H is the height of the feature, D is the depth of the feature, and W is the width of the feature.
Args: Parameters:
kernel_size (int|list|tuple): The pool kernel size. If pool kernel size 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,
(kernel_size_Depth, kernel_size_Height, kernel_size_Width). (kernel_size_Depth, kernel_size_Height, kernel_size_Width).
Otherwise, the pool kernel size will be the cube of an int. 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, stride(int|list|tuple, optional): The pool stride size. If pool stride size is a tuple or list,
it must contain three integers, [stride_Depth, stride_Height, stride_Width). it must contain three integers, [stride_Depth, stride_Height, stride_Width).
Otherwise, the pool stride size will be a cube of an int. 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. Default None, then stride will be equal to the kernel_size.
padding(str|int|list|tuple, optional): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same']. 1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides. 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. 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. 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). 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. The default value is 0.
ceil_mode (bool): ${ceil_mode_comment} ceil_mode(bool, optional): ${ceil_mode_comment}
exclusive (bool): Whether to exclude padding points in average pooling exclusive(bool, optional): Whether to exclude padding points in average pooling mode, default is True.
mode, default is True. divisor_override(int|float, optional): if specified, it will be used as divisor, otherwise kernel_size will
divisor_override (int|float) if specified, it will be used as divisor, otherwise kernel_size will be used. Default None. be used. Default None.
data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`. data_format(str, optional): The data format of the input and output data. An optional string from: `"NCDHW"`,
The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of: `"NDHWC"`. The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
`[batch_size, input_channels, input_depth, input_height, input_width]`. `[batch_size, input_channels, input_depth, input_height, input_width]`.
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: None. Returns:
A callable object of AvgPool3D.
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.
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: Shape:
- x: 5-D tensor. - x(Tensor): The input tensor of avg pool3d operator, which is a 5-D tensor.
- out: 5-D tensor. The data type can be float32, float64.
- output(Tensor): The output tensor of avg pool3d operator, which is a 5-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
# avg pool3d # avg pool3d
input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 2, 3, 32, 32]).astype(np.float32)) input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 2, 3, 32, 32]).astype(np.float32))
AvgPool3D = nn.AvgPool3D(kernel_size=2, AvgPool3D = nn.AvgPool3D(kernel_size=2,
stride=2, padding=0) stride=2, padding=0)
output = AvgPool3D(input) output = AvgPool3D(input)
# output.shape [1, 2, 3, 16, 16] # output.shape [1, 2, 3, 16, 16]
""" """
def __init__(self, def __init__(self,
kernel_size, kernel_size,
stride, stride=None,
padding=0, padding=0,
ceil_mode=False, ceil_mode=False,
exclusive=True, exclusive=True,
...@@ -328,10 +333,11 @@ class AvgPool3D(layers.Layer): ...@@ -328,10 +333,11 @@ class AvgPool3D(layers.Layer):
class MaxPool1D(layers.Layer): class MaxPool1D(layers.Layer):
""" """
Applies a 1D max pooling over an input signal composed of several input planes based This operation applies 1D max pooling over input signal
on the input, output_size, return_mask parameters. composed of several input planes based on the input,
Input(X) and output(Out) are in NCL format, where N is batch and kernel_size, stride, padding parameters. Input(X) and Output(Out) are
size, C is the number of channels, L is the length of the feature. in NCL format, where N is batch size, C is the number of channels,
L is the length of the feature.
The output value of the layer with input size (N, C, L), 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 output (N, C, L_{out}) and kernel_size k can be precisely described as
...@@ -339,28 +345,27 @@ class MaxPool1D(layers.Layer): ...@@ -339,28 +345,27 @@ class MaxPool1D(layers.Layer):
.. math:: .. math::
Output(N_i, C_i, l) &= max(Input[N_i, C_i, stride \times l:stride \times l+k])} Output(N_i, C_i, l) = max(Input[N_i, C_i, stride \times l:stride \times l+k])
Args: Parameters:
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 an integer.
stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
it must contain an integer. it must contain an integer.
padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms. stride(int|list|tuple, optional): The pool stride size. If pool stride size is a tuple or list,
it must contain an integer. Default None, then stride will be equal to the kernel_size.
padding(str|int|list|tuple, optional): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same']. 1. A string in ['valid', 'same'].
2. An integer, which means the feature map is zero padded by size of `padding` on every sides. 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. 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]. 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). 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. The default value is 0.
return_mask (bool): Whether return the max indices along with the outputs. default is `False`. return_mask(bool, optional): 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. ceil_mode(bool, optional): 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. 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`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Returns: Returns:
None. A callable object of MaxPool1D.
Raises: Raises:
ValueError: If `padding` is a string, but not "SAME" or "VALID". ValueError: If `padding` is a string, but not "SAME" or "VALID".
...@@ -371,25 +376,27 @@ class MaxPool1D(layers.Layer): ...@@ -371,25 +376,27 @@ class MaxPool1D(layers.Layer):
Shape: Shape:
- x: 3-D tensor. - x(Tensor): The input tensor of max pool1d operator, which is a 3-D tensor.
- out: 3-D tensor. The data type can be float32, float64.
- output(Tensor): The output tensor of max pool1d operator, which is a 3-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
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))
MaxPool1D = nn.MaxPool1D(kernel_size=2, stride=2, padding=0) MaxPool1D = nn.MaxPool1D(kernel_size=2, stride=2, padding=0)
pool_out = MaxPool1D(data) pool_out = MaxPool1D(data)
# pool_out shape: [1, 3, 16] # pool_out shape: [1, 3, 16]
MaxPool1D = nn.MaxPool1D(kernel_size=2, stride=2, padding=0, return_mask=True) MaxPool1D = nn.MaxPool1D(kernel_size=2, stride=2, padding=0, return_mask=True)
pool_out, indices = MaxPool1D(data) pool_out, indices = MaxPool1D(data)
# pool_out shape: [1, 3, 16], indices shape: [1, 3, 16] # pool_out shape: [1, 3, 16], indices shape: [1, 3, 16]
""" """
...@@ -426,70 +433,73 @@ class MaxPool2D(layers.Layer): ...@@ -426,70 +433,73 @@ class MaxPool2D(layers.Layer):
H is the height of the feature, and W is the width of the feature. H is the height of the feature, and W is the width of the feature.
Example: Example:
Input: - Input:
X shape: $(N, C, H_{in}, W_{in})$ X shape: :math:`(N, C, H_{in}, W_{in})`
Attr: - Attr:
kernel_size: ksize kernel_size: ksize
Output: - Output:
Out shape: $(N, C, H_{out}, W_{out})$ Out shape: :math:`(N, C, H_{out}, W_{out})`
$$
out(N_i, C_j, h, w) ={} & \max_{m=0, \ldots, ksize[0] -1} \max_{n=0, \ldots, ksize[1]-1} \\ .. math::
& \text{input}(N_i, C_j, \text{stride[0]} \times h + m,
\text{stride[1]} \times w + n) Output(N_i, C_j, h, w) = \max_{m=0, \ldots, ksize[0] -1} \max_{n=0, \ldots, ksize[1]-1}
$$ Input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)
Args: Parameters:
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, (pool_size_Height, pool_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, optional): 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. 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. Default None, then stride will be equal to the kernel_size.
padding(str|int|list|tuple, optional): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same']. 1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides. 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. 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. 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). 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. The default value is 0.
ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape ceil_mode(bool, optional): when True, will use `ceil` instead of `floor` to compute the output shape
return_mask (bool): Whether to return the max indices along with the outputs. return_mask(bool, optional): Whether to return the max indices along with the outputs.
data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NDHW"`. data_format(str, optional): 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: The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
`[batch_size, input_channels, input_height, input_width]`. `[batch_size, input_channels, input_height, input_width]`.
name(str, optional): For detailed information, please refer name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Returns: None Returns:
A callable object of MaxPool2D.
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.
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: Shape:
- x: 4-D tensor. - x(Tensor): The input tensor of max pool2d operator, which is a 4-D tensor.
- out: 4-D tensor. The data type can be float32, float64.
- output(Tensor): The output tensor of max pool2d operator, which is a 4-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
# max pool2d # max pool2d
input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32)) input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32, 32]).astype(np.float32))
MaxPool2D = nn.MaxPool2D(kernel_size=2, MaxPool2D = nn.MaxPool2D(kernel_size=2,
stride=2, padding=0) stride=2, padding=0)
output = MaxPool2D(input) output = MaxPool2D(input)
# output.shape [1, 3, 16, 16] # output.shape [1, 3, 16, 16]
# for return_mask=True # for return_mask=True
MaxPool2D = nn.MaxPool2D(kernel_size=2, stride=2, padding=0, return_mask=True) MaxPool2D = nn.MaxPool2D(kernel_size=2, stride=2, padding=0, return_mask=True)
output, max_indices = MaxPool2D(input) output, max_indices = MaxPool2D(input)
# output.shape [1, 3, 16, 16], max_indices.shape [1, 3, 16, 16], # output.shape [1, 3, 16, 16], max_indices.shape [1, 3, 16, 16],
""" """
def __init__(self, def __init__(self,
...@@ -532,59 +542,62 @@ class MaxPool3D(layers.Layer): ...@@ -532,59 +542,62 @@ class MaxPool3D(layers.Layer):
in NCDHW format, where N is batch size, C is the number of channels, in NCDHW format, where N is batch size, C is the number of channels,
H is the height of the feature, D is the depth of the feature, and W is the width of the feature. H is the height of the feature, D is the depth of the feature, and W is the width of the feature.
Args: Parameters:
kernel_size (int|list|tuple): The pool kernel size. If the kernel size kernel_size(int|list|tuple): The pool kernel size. If the kernel size
is a tuple or list, it must contain three integers, is a tuple or list, it must contain three integers,
(kernel_size_Depth, kernel_size_Height, kernel_size_Width). (kernel_size_Depth, kernel_size_Height, kernel_size_Width).
Otherwise, the pool kernel size will be the cube of an int. 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, stride(int|list|tuple, optional): The pool stride size. If pool stride size is a tuple or list,
it must contain three integers, [stride_Depth, stride_Height, stride_Width). it must contain three integers, [stride_Depth, stride_Height, stride_Width).
Otherwise, the pool stride size will be a cube of an int. 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. Default None, then stride will be equal to the kernel_size.
padding(str|int|list|tuple, optional): The padding size. Padding could be in one of the following forms.
1. A string in ['valid', 'same']. 1. A string in ['valid', 'same'].
2. An int, which means the feature map is zero padded by size of `padding` on every sides. 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. 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. 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). 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. The default value is 0.
ceil_mode (bool): ${ceil_mode_comment} ceil_mode(bool, optional): ${ceil_mode_comment}
return_mask (bool): Whether to return the max indices along with the outputs. return_mask(bool, optional): Whether to return the max indices along with the outputs.
data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`. data_format(str, optional): The data format of the input and output data. An optional string from: `"NCDHW"`,
The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of: `"NDHWC"`. The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
`[batch_size, input_channels, input_depth, input_height, input_width]`. `[batch_size, input_channels, input_depth, input_height, input_width]`.
name(str, optional): For detailed information, please refer name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Returns:None. Returns:
A callable object of MaxPool3D.
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.
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: Shape:
- x: 5-D tensor. - x(Tensor): The input tensor of max pool3d operator, which is a 5-D tensor.
- out: 5-D tensor. The data type can be float32, float64.
- output(Tensor): The output tensor of max pool3d operator, which is a 5-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
# max pool3d # max pool3d
input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 2, 3, 32, 32]).astype(np.float32)) input = paddle.to_tensor(np.random.uniform(-1, 1, [1, 2, 3, 32, 32]).astype(np.float32))
MaxPool3D = nn.MaxPool3D(kernel_size=2, MaxPool3D = nn.MaxPool3D(kernel_size=2,
stride=2, padding=0) stride=2, padding=0)
output = MaxPool3D(input) output = MaxPool3D(input)
# output.shape [1, 2, 3, 16, 16] # output.shape [1, 2, 3, 16, 16]
# for return_mask=True # for return_mask=True
MaxPool3D = nn.MaxPool3D(kernel_size=2, stride=2, padding=0, return_mask=True) MaxPool3D = nn.MaxPool3D(kernel_size=2, stride=2, padding=0, return_mask=True)
output, max_indices = MaxPool3D(input) output, max_indices = MaxPool3D(input)
# output.shape [1, 2, 3, 16, 16], max_indices.shape [1, 2, 3, 16, 16], # output.shape [1, 2, 3, 16, 16], max_indices.shape [1, 2, 3, 16, 16],
""" """
def __init__(self, def __init__(self,
...@@ -633,51 +646,52 @@ class AdaptiveAvgPool1D(layers.Layer): ...@@ -633,51 +646,52 @@ class AdaptiveAvgPool1D(layers.Layer):
.. math:: .. math::
lstart &= floor(i * L_{in} / L_{out}) lstart &= floor(i * L_{in} / L_{out})
lend &= ceil((i + 1) * L_{in} / L_{out}) lend &= ceil((i + 1) * L_{in} / L_{out})
Output(i) &= \\frac{sum(Input[lstart:lend])}{(lstart - lend)} Output(i) &= \frac{ \sum Input[lstart:lend]}{lend - lstart}
Args: Parameters:
output_size (int): The target output size. It must be an integer. output_size(int): The target output size. It must be an integer.
name(str, optional): For detailed information, please refer name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Returns: Returns:
None. A callable object of AdaptiveAvgPool1D.
Raises: Raises:
ValueError: 'output_size' should be an integer. ValueError: 'output_size' should be an integer.
Shape: Shape:
- x: 3-D tensor. - x(Tensor): 3-D tensor. The input tensor of adaptive avg pool1d operator, which is a 3-D tensor.
- out: 3-D tensor. The data type can be float32, float64.
- output(Tensor): 3-D tensor. The output tensor of adaptive avg pool1d operator, which is a 3-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
# average adaptive pool1d # average adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m], # 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 # output shape is [N, C, m], adaptive pool divide L dimension
# of input data into m grids averagely and performs poolings in each # of input data into m grids averagely and performs poolings in each
# grid to get output. # grid to get output.
# adaptive max pool performs calculations as follow: # adaptive max pool performs calculations as follow:
# #
# for i in range(m): # for i in range(m):
# lstart = floor(i * L / m) # lstart = floor(i * L / m)
# lend = ceil((i + 1) * L / m) # lend = ceil((i + 1) * L / m)
# output[:, :, i] = sum(input[:, :, lstart: lend])/(lstart - lend) # output[:, :, i] = sum(input[:, :, lstart: lend])/(lend - lstart)
# #
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
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))
AdaptiveAvgPool1D = nn.AdaptiveAvgPool1D(output_size=16) AdaptiveAvgPool1D = nn.AdaptiveAvgPool1D(output_size=16)
pool_out = AdaptiveAvgPool1D(data) pool_out = AdaptiveAvgPool1D(data)
# pool_out shape: [1, 3, 16] # pool_out shape: [1, 3, 16]
""" """
def __init__(self, output_size, name=None): def __init__(self, output_size, name=None):
...@@ -702,31 +716,32 @@ class AdaptiveAvgPool2D(layers.Layer): ...@@ -702,31 +716,32 @@ class AdaptiveAvgPool2D(layers.Layer):
.. math:: .. math::
hstart &= floor(i * H_{in} / H_{out}) hstart &= floor(i * H_{in} / H_{out})
hend &= ceil((i + 1) * H_{in} / H_{out}) hend &= ceil((i + 1) * H_{in} / H_{out})
wstart &= floor(j * W_{in} / W_{out}) wstart &= floor(j * W_{in} / W_{out})
wend &= ceil((j + 1) * W_{in} / W_{out}) wend &= ceil((j + 1) * W_{in} / W_{out})
Output(i ,j) &= \\frac{sum(Input[hstart:hend, wstart:wend])}{(hend - hstart) * (wend - wstart)} Output(i ,j) &= \frac{\sum Input[hstart:hend, wstart:wend]}{(hend - hstart) * (wend - wstart)}
Parameters: Parameters:
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, 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 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. the size will be the same as that of the input.
data_format (str): The data format of the input and output data. An optional string data_format(str, optional): 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 from: "NCHW", "NHWC". The default is "NCHW". When it is "NCHW", the data is stored in
the order of: [batch_size, input_channels, input_height, input_width]. the order of: [batch_size, input_channels, input_height, input_width].
name(str, optional): For detailed information, please refer name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Shape: Shape:
x (Tensor): The input tensor of adaptive avg pool2d operator, which is a 4-D tensor. The data type can be float32, float64. - x(Tensor): The input tensor of adaptive avg pool2d operator, which is a 4-D tensor.
output (Tensor): The output tensor of adaptive avg pool2d operator, which is a 4-D tensor. The data type is same as input x. The data type can be float32, float64.
- output(Tensor): The output tensor of adaptive avg pool2d operator, which is a 4-D tensor.
The data type is same as input x.
Returns: Returns:
A callable object of AdaptiveAvgPool2D. A callable object of AdaptiveAvgPool2D.
...@@ -787,34 +802,36 @@ class AdaptiveAvgPool3D(layers.Layer): ...@@ -787,34 +802,36 @@ class AdaptiveAvgPool3D(layers.Layer):
.. math:: .. math::
dstart &= floor(i * D_{in} / D_{out}) dstart &= floor(i * D_{in} / D_{out})
dend &= ceil((i + 1) * D_{in} / D_{out}) dend &= ceil((i + 1) * D_{in} / D_{out})
hstart &= floor(j * H_{in} / H_{out}) hstart &= floor(j * H_{in} / H_{out})
hend &= ceil((j + 1) * H_{in} / H_{out}) hend &= ceil((j + 1) * H_{in} / H_{out})
wstart &= floor(k * W_{in} / W_{out}) wstart &= floor(k * W_{in} / W_{out})
wend &= ceil((k + 1) * W_{in} / W_{out}) wend &= ceil((k + 1) * W_{in} / W_{out})
Output(i ,j, k) &= \\frac{sum(Input[dstart:dend, hstart:hend, wstart:wend])}{(dend - dstart) * (hend - hstart) * (wend - wstart)} Output(i ,j, k) &= \frac{\sum Input[dstart:dend, hstart:hend, wstart:wend]}
{(dend - dstart) * (hend - hstart) * (wend - wstart)}
Parameters: Parameters:
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, 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 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. the size will be the same as that of the input.
data_format (str): The data format of the input and output data. An optional string data_format(str, optional): 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 from: "NCDHW", "NDHWC". The default is "NCDHW". When it is "NCDHW", the data is stored in
the order of: [batch_size, input_channels, input_depth, input_height, input_width]. the order of: [batch_size, input_channels, input_depth, input_height, input_width].
name(str, optional): For detailed information, please refer name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Shape: Shape:
x (Tensor): The input tensor of adaptive avg pool3d operator, which is a 5-D tensor. The data type can be float32, float64. - x(Tensor): The input tensor of adaptive avg pool3d operator, which is a 5-D tensor.
output (Tensor): The output tensor of adaptive avg pool3d operator, which is a 5-D tensor. The data type is same as input x. The data type can be float32, float64\.
- output(Tensor): The output tensor of adaptive avg pool3d operator, which is a 5-D tensor.
The data type is same as input x.
Returns: Returns:
A callable object of AdaptiveAvgPool3D. A callable object of AdaptiveAvgPool3D.
...@@ -881,58 +898,59 @@ class AdaptiveMaxPool1D(layers.Layer): ...@@ -881,58 +898,59 @@ class AdaptiveMaxPool1D(layers.Layer):
.. math:: .. math::
lstart &= floor(i * L_{in} / L_{out}) lstart &= floor(i * L_{in} / L_{out})
lend &= ceil((i + 1) * L_{in} / L_{out}) lend &= ceil((i + 1) * L_{in} / L_{out})
Output(i) &= max(Input[lstart:lend]) Output(i) &= max(Input[lstart:lend])
Args: Parameters:
output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, output_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 one int.
return_mask (bool): If true, the index of max pooling point will be returned along return_mask(bool, optional): If true, the index of max pooling point will be returned along
with outputs. It cannot be set in average pooling type. Default False. with outputs. It cannot be set in average pooling type. Default False.
name(str, optional): For detailed information, please refer name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`.
to :ref:`api_guide_Name`. Usually name is no need to set and Usually name is no need to set and None by default.
None by default.
Returns: Returns:
None. A callable object of AdaptiveMaxPool1D.
Raises: Raises:
ValueError: 'pool_size' should be a integer or list or tuple with length as 1. ValueError: 'pool_size' should be a integer or list or tuple with length as 1.
Shape: Shape:
x (Tensor): The input tensor of adaptive max pool1d operator, which is a 3-D tensor. The data type can be float32, float64. - x(Tensor): The input tensor of adaptive max pool1d operator, which is a 3-D tensor.
output (Tensor): The output tensor of adaptive max pool1d operator, which is a 3-D tensor. The data type is same as input x. The data type can be float32, float64.
- output(Tensor): The output tensor of adaptive max pool1d operator, which is a 3-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
# max adaptive pool1d # max adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m], # 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 # output shape is [N, C, m], adaptive pool divide L dimension
# of input data into m grids averagely and performs poolings in each # of input data into m grids averagely and performs poolings in each
# grid to get output. # grid to get output.
# adaptive max pool performs calculations as follow: # adaptive max pool performs calculations as follow:
# #
# for i in range(m): # for i in range(m):
# lstart = floor(i * L / m) # lstart = floor(i * L / m)
# lend = ceil((i + 1) * L / m) # lend = ceil((i + 1) * L / m)
# output[:, :, i] = max(input[:, :, lstart: lend]) # output[:, :, i] = max(input[:, :, lstart: lend])
# #
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
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))
AdaptiveMaxPool1D = nn.AdaptiveMaxPool1D(output_size=16) AdaptiveMaxPool1D = nn.AdaptiveMaxPool1D(output_size=16)
pool_out = AdaptiveMaxPool1D(data) pool_out = AdaptiveMaxPool1D(data)
# pool_out shape: [1, 3, 16] # pool_out shape: [1, 3, 16]
# for return_mask = true # for return_mask = true
AdaptiveMaxPool1D = nn.AdaptiveMaxPool1D(output_size=16, return_mask=True) AdaptiveMaxPool1D = nn.AdaptiveMaxPool1D(output_size=16, return_mask=True)
pool_out, indices = AdaptiveMaxPool1D(data) pool_out, indices = AdaptiveMaxPool1D(data)
# pool_out shape: [1, 3, 16], indices shape: [1, 3, 16] # pool_out shape: [1, 3, 16], indices shape: [1, 3, 16]
""" """
...@@ -954,31 +972,36 @@ class AdaptiveMaxPool1D(layers.Layer): ...@@ -954,31 +972,36 @@ class AdaptiveMaxPool1D(layers.Layer):
class AdaptiveMaxPool2D(layers.Layer): class AdaptiveMaxPool2D(layers.Layer):
""" """
This operation applies 2D adaptive max pooling on input tensor. The h and w dimensions 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. 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.
For adaptive max pool2d: For adaptive max pool2d:
.. math:: .. math::
hstart &= floor(i * H_{in} / H_{out}) hstart &= floor(i * H_{in} / H_{out})
hend &= ceil((i + 1) * H_{in} / H_{out}) hend &= ceil((i + 1) * H_{in} / H_{out})
wstart &= floor(j * W_{in} / W_{out}) wstart &= floor(j * W_{in} / W_{out})
wend &= ceil((j + 1) * W_{in} / W_{out}) wend &= ceil((j + 1) * W_{in} / W_{out})
Output(i ,j) &= max(Input[hstart:hend, wstart:wend]) Output(i ,j) &= max(Input[hstart:hend, wstart:wend])
Parameters: Parameters:
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. output_size(int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain
return_mask (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. 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
name(str, optional): For detailed information, please refer the input.
to :ref:`api_guide_Name`. Usually name is no need to set and return_mask(bool, optional): If true, the index of max pooling point will be returned along with outputs.
None by default. 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: Shape:
x (Tensor): The input tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type can be float32, float64. - x(Tensor): The input tensor of adaptive max pool2d operator, which is a 4-D tensor.
output (Tensor): The output tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type is same as input x. 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: Returns:
A callable object of AdaptiveMaxPool2D. A callable object of AdaptiveMaxPool2D.
...@@ -1029,36 +1052,42 @@ class AdaptiveMaxPool2D(layers.Layer): ...@@ -1029,36 +1052,42 @@ class AdaptiveMaxPool2D(layers.Layer):
class AdaptiveMaxPool3D(layers.Layer): class AdaptiveMaxPool3D(layers.Layer):
""" """
This operation applies 3D adaptive max pooling on input tensor. The h and w dimensions This operation applies 3D adaptive max pooling on input tensor. The h and w dimensions of the output tensor are
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. determined by the parameter output_size. The difference between adaptive pooling and pooling is adaptive one focus
on the output size.
For adaptive max pool3d: For adaptive max pool3d:
.. math:: .. math::
dstart &= floor(i * D_{in} / D_{out}) dstart &= floor(i * D_{in} / D_{out})
dend &= ceil((i + 1) * D_{in} / D_{out}) dend &= ceil((i + 1) * D_{in} / D_{out})
hstart &= floor(j * H_{in} / H_{out}) hstart &= floor(j * H_{in} / H_{out})
hend &= ceil((j + 1) * H_{in} / H_{out}) hend &= ceil((j + 1) * H_{in} / H_{out})
wstart &= floor(k * W_{in} / W_{out}) wstart &= floor(k * W_{in} / W_{out})
wend &= ceil((k + 1) * W_{in} / W_{out}) wend &= ceil((k + 1) * W_{in} / W_{out})
Output(i ,j, k) &= max(Input[dstart:dend, hstart:hend, wstart:wend]) Output(i ,j, k) &= max(Input[dstart:dend, hstart:hend, wstart:wend])
Parameters: Parameters:
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. output_size(int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain
return_mask (bool): If true, the index of max pooling point will be returned along with outputs. Default False. 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
name(str, optional): For detailed information, please refer that of the input.
to :ref:`api_guide_Name`. Usually name is no need to set and return_mask(bool, optional): If true, the index of max pooling point will be returned along with outputs.
None by default. 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: Shape:
x (Tensor): The input tensor of adaptive max pool3d operator, which is a 5-D tensor. The data type can be float32, float64. - x(Tensor): The input tensor of adaptive max pool3d operator, which is a 5-D tensor.
output (Tensor): The output tensor of adaptive max pool3d operator, which is a 5-D tensor. The data type is same as input x. The data type can be float32, float64.
- output(Tensor): The output tensor of adaptive max pool3d operator, which is a 5-D tensor.
The data type is same as input x.
Returns: Returns:
A callable object of AdaptiveMaxPool3D. A callable object of AdaptiveMaxPool3D.
Examples: Examples:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册