mindspore.nn.AdaptiveAvgPool2d

class mindspore.nn.AdaptiveAvgPool2d(output_size)[source]

This operator applies a 2D adaptive average pooling to an input signal composed of multiple input planes. That is, for any input size, the size of the specified output is H x W. The number of output features is equal to the number of input features.

The input and output data format can be "NCHW" and "CHW". N is the batch size, C is the number of channels, H is the feature height, and W is the feature width.

hstart=floor(iHin/Hout)hend=ceil((i+1)Hin/Hout)wstart=floor(jWin/Wout)wend=ceil((j+1)Win/Wout)Output(i,j)=Input[hstart:hend,wstart:wend](hendhstart)(wendwstart)
Parameters

output_size (Union[int, tuple]) – The target output size is H x W. output_size can be a tuple consisted of int type H and W, or a single H for H x H, or None. If it is None, it means the output size is the same as the input size.

Inputs:
  • input (Tensor) - The input of AdaptiveAvgPool2d, which is a 3D or 4D tensor, with float16, float32 or float64 data type.

Outputs:

Tensor of shape (N,Cout,Hout,Wout).

Raises
  • ValueError – If output_size is a tuple and the length of output_size is not 2.

  • TypeError – If input is not a Tensor.

  • TypeError – If dtype of input is not float16, float32 or float64.

  • ValueError – If the dimension of input is less than or equal to the dimension of output_size.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> pool = ms.nn.AdaptiveAvgPool2d(2)
>>> input_x = ms.Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
...                            [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
...                            [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]), ms.float32)
>>> output = pool(input_x)
>>> result = output.shape
>>> print(result)
(3, 2, 2)