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:
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:
& \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:
output of the convolution, and the corresponding activation function is
output of the convolution, and the corresponding activation function is
applied to the final result.
applied to the final result.
For each input :math:`X`, the equation is:
For each input :math:`X`, the equation is:
.. math::
.. math::
Out = \\sigma (W \\ast X + b)
Out = \sigma (W \\ast X + b)
Where:
Where:
* :math:`X`: Input value, a ``Tensor`` with NCHW format.
* :math:`X`: Input value, a ``Tensor`` with NCHW format.
* :math:`W`: Filter value, a ``Tensor`` with shape [MCHW] .
* :math:`W`: Filter value, a ``Tensor`` with shape [MCHW] .
* :math:`\\ast`: Convolution operation.
* :math:`\\ast`: Convolution operation.
* :math:`b`: Bias value, a 2-D ``Tensor`` with shape [M, 1].
* :math:`b`: Bias value, a 2-D ``Tensor`` with shape [M, 1].
* :math:`\\sigma`: Activation function.
* :math:`\\sigma`: Activation function.
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
Parameters:
Parameters:
in_channels(int): The number of channels in the input image.
in_channels(int): The number of input channels in the input image.
out_channels(int): The number of channels produced by convolution.
out_channels(int): The number of output channels produced by the convolution.
kernel_size (int|list|tuple): The size of convolution kernel.
kernel_size(int|list|tuple, optional): The size of the convolving kernel.
stride(int|list|tuple, optional): The stride size. If stride is a tuple, it must
stride(int|list|tuple, optional): The stride size. If stride is a tuple, it must
contain two integers, (stride_H, stride_W). Otherwise, the
contain three integers, (stride_H, stride_W). Otherwise, the
stride_H = stride_W = stride. Default: 1.
stride_H = stride_W = stride. The default value is 1.
padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms.
padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms.
1. a string in ['valid', 'same'].
1. a string in ['valid', 'same'].
2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding`on both sides
2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding`
3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...].
3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...].
4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions.
4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions.
5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
in_channels(int): The number of channels in the input image.
in_channels(int): The number of channels in the input image.
out_channels(int): The number of channels produced by the convolution.
out_channels(int): The number of channels produced by the convolution.
kernel_size(int|list|uple): The kernel size. If kernel_size is a tuple,
kernel_size(int|list|uple): The kernel size. If kernel_size is a tuple,
it must contain two integers, (kernel_size_H, kernel_size_W).
it must contain two integers, (kernel_size_H, kernel_size_W).
Otherwise, the kernel will be a square.
Otherwise, the kernel will be a square.
output_padding(int|list|tuple, optional): Additional size added to one side
stride(int|list|tuple, optional): The stride size. If stride is a tuple, it must
of each dimension in the output shape. Default: 0.
contain two integers, (stride_H, stride_W). Otherwise, the
stride_H = stride_W = stride. Default: 1.
padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms.
padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms.
1. a string in ['valid', 'same'].
1. a string in ['valid', 'same'].
2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding` on both sides
2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding` on both sides
...
@@ -682,9 +695,8 @@ class ConvTranspose2d(_ConvNd):
...
@@ -682,9 +695,8 @@ class ConvTranspose2d(_ConvNd):
4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions.
4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions.
5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
The default value is 0.
The default value is 0.
stride(int|list|tuple, optional): The stride size. If stride is a tuple, it must
output_padding(int|list|tuple, optional): Additional size added to one side
contain two integers, (stride_H, stride_W). Otherwise, the
of each dimension in the output shape. Default: 0.
stride_H = stride_W = stride. Default: 1.
dilation(int|list|tuple, optional): The dilation size. If dilation is a tuple, it must
dilation(int|list|tuple, optional): The dilation size. If dilation is a tuple, it must
contain two integers, (dilation_H, dilation_W). Otherwise, the
contain two integers, (dilation_H, dilation_W). Otherwise, the
dilation_H = dilation_W = dilation. Default: 1.
dilation_H = dilation_W = dilation. Default: 1.
...
@@ -694,29 +706,46 @@ class ConvTranspose2d(_ConvNd):
...
@@ -694,29 +706,46 @@ class ConvTranspose2d(_ConvNd):
first half of the input channels, while the second half of the
first half of the input channels, while the second half of the
filters is only connected to the second half of the input channels.
filters is only connected to the second half of the input channels.
Default: 1.
Default: 1.
weight_attr(ParamAttr, optional): The parameter attribute for learnable weights(Parameter)
weight_attr(ParamAttr, optional): The parameter attribute for learnable weights(Parameter)
of conv2d_transpose. If it is set to None or one attribute of ParamAttr, conv2d_transpose
of conv2d_transpose. If it is set to None or one attribute of ParamAttr, conv2d_transpose
will create ParamAttr as param_attr. If the Initializer of the param_attr
will create ParamAttr as param_attr. If the Initializer of the param_attr
is not set, the parameter is initialized with Xavier. Default: None.
is not set, the parameter is initialized with Xavier. Default: None.
bias_attr(ParamAttr|bool, optional): The attribute for the bias of conv2d_transpose.
bias_attr(ParamAttr|bool, optional): The attribute for the bias of conv2d_transpose.
If it is set to False, no bias will be added to the output units.
If it is set to False, no bias will be added to the output units.
If it is set to None or one attribute of ParamAttr, conv2d_transpose
If it is set to None or one attribute of ParamAttr, conv2d_transpose
will create ParamAttr as bias_attr. If the Initializer of the bias_attr
will create ParamAttr as bias_attr. If the Initializer of the bias_attr
is not set, the bias is initialized zero. Default: None.
is not set, the bias is initialized zero. Default: None.
data_format(str, optional): Data format that specifies the layout of input.
data_format(str, optional): Data format that specifies the layout of input.
It can be "NCHW" or "NHWC". Default: "NCHW".
It can be "NCHW" or "NHWC". Default: "NCHW".
Attribute:
Attribute:
**weight** (Parameter): the learnable weights of filters of this layer.
**weight** (Parameter): the learnable weights of filters of this layer.
**bias** (Parameter or None): the learnable bias of this layer.
**bias** (Parameter or None): the learnable bias of this layer.
provided, bias is added to the output of the convolution, and the
provided, bias is added to the output of the convolution, and the
corresponding activation function is applied to the final result.
corresponding activation function is applied to the final result.
For each input :math:`X`, the equation is:
For each input :math:`X`, the equation is:
.. math::
.. math::
Out = \sigma (W \\ast X + b)
Out = \sigma (W \\ast X + b)
In the above equation:
In the above equation:
* :math:`X`: Input value, a tensor with NCDHW or NDHWC format.
* :math:`X`: Input value, a tensor with NCDHW or NDHWC format.
* :math:`W`: Filter value, a tensor with MCDHW format.
* :math:`W`: Filter value, a tensor with MCDHW format.
* :math:`\\ast`: Convolution operation.
* :math:`\\ast`: Convolution operation.
* :math:`b`: Bias value, a 2-D tensor with shape [M, 1].
* :math:`b`: Bias value, a 2-D tensor with shape [M, 1].
* :math:`\\sigma`: Activation function.
* :math:`\\sigma`: Activation function.
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
Parameters:
Parameters:
in_channels(int): The number of input channels in the input image.
in_channels(int): The number of input channels in the input image.
out_channels(int): The number of output channels produced by the convolution.
out_channels(int): The number of output channels produced by the convolution.
kernel_size(int|list|tuple, optional): The size of the convolving kernel.
kernel_size(int|list|tuple, optional): The size of the convolving kernel.
stride(int|list|tuple, optional): The stride size. If stride is a tuple, it must
stride(int|list|tuple, optional): The stride size. If stride is a tuple, it must
contain three integers, (stride_D, stride_H, stride_W). Otherwise, the
contain three integers, (stride_D, stride_H, stride_W). Otherwise, the
stride_D = stride_H = stride_W = stride. The default value is 1.
stride_D = stride_H = stride_W = stride. The default value is 1.
padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms.
padding(int|str|tuple|list, optional): The padding size. Padding coule be in one of the following forms.
1. a string in ['valid', 'same'].
1. a string in ['valid', 'same'].
2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding`
2. an int, which means each spartial dimension(depth, height, width) is zero paded by size of `padding`
3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...].
3. a list[int] or tuple[int] whose length is the number of spartial dimensions, which contains the amount of padding on each side for each spartial dimension. It has the form [pad_d1, pad_d2, ...].
4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions.
4. a list[int] or tuple[int] whose length is 2 * number of spartial dimensions. It has the form [pad_before, pad_after, pad_before, pad_after, ...] for all spartial dimensions.
5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
The default value is 0.
The default value is 0.
dilation(int|list|tuple, optional): The dilation size. If dilation is a tuple, it must
dilation(int|list|tuple, optional): The dilation size. If dilation is a tuple, it must
contain three integers, (dilation_D, dilation_H, dilation_W). Otherwise, the
contain three integers, (dilation_D, dilation_H, dilation_W). Otherwise, the
dilation_D = dilation_H = dilation_W = dilation. The default value is 1.
dilation_D = dilation_H = dilation_W = dilation. The default value is 1.
groups(int, optional): The groups number of the Conv3d Layer. According to grouped
groups(int, optional): The groups number of the Conv3d Layer. According to grouped
convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
the first half of the filters is only connected to the first half
the first half of the filters is only connected to the first half
of the input channels, while the second half of the filters is only
of the input channels, while the second half of the filters is only
connected to the second half of the input channels. The default value is 1.
connected to the second half of the input channels. The default value is 1.
padding_mode(str, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Default: ``'zeros'``.
padding_mode(str, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Default: ``'zeros'``.
weight_attr(ParamAttr, optional): The parameter attribute for learnable parameters/weights
weight_attr(ParamAttr, optional): The parameter attribute for learnable parameters/weights
of conv3d. If it is set to None or one attribute of ParamAttr, conv3d
of conv3d. If it is set to None or one attribute of ParamAttr, conv3d
will create ParamAttr as param_attr. If it is set to None, the parameter
will create ParamAttr as param_attr. If it is set to None, the parameter
is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
:math:`(\\frac{2.0 }{filter\_elem\_num})^{0.5}`. The default value is None.
:math:`(\\frac{2.0 }{filter\_elem\_num})^{0.5}`. The default value is None.
bias_attr(ParamAttr|bool, optional): The parameter attribute for the bias of conv3d.
bias_attr(ParamAttr|bool, optional): The parameter attribute for the bias of conv3d.
If it is set to False, no bias will be added to the output units.
If it is set to False, no bias will be added to the output units.
If it is set to None or one attribute of ParamAttr, conv3d
If it is set to None or one attribute of ParamAttr, conv3d
will create ParamAttr as bias_attr. If the Initializer of the bias_attr
will create ParamAttr as bias_attr. If the Initializer of the bias_attr
is not set, the bias is initialized zero. The default value is None.
is not set, the bias is initialized zero. The default value is None.
data_format(str, optional): Data format that specifies the layout of input.
data_format(str, optional): Data format that specifies the layout of input.
It can be "NCDHW" or "NDHWC". Default: "NCDHW".
It can be "NCDHW" or "NDHWC". Default: "NCDHW".
Attribute:
Attribute:
**weight** (Parameter): the learnable weights of filters of this layer.
**weight** (Parameter): the learnable weights of filters of this layer.
**bias** (Parameter): the learnable bias of this layer.
**bias** (Parameter): the learnable bias of this layer.
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
# 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).
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): 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 three integers, [stride_Depth, stride_Height, 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 cube 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 3, [pad_depth, 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 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 `"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).
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.