megengine.functional.nn.avg_pool2d#

avg_pool2d(inp, kernel_size, stride=None, padding=0, mode='average_count_exclude_padding')[source]#

Applies 2D average pooling over an input tensor.

Refer to AvgPool2d for more information.

Parameters:
  • inp (Tensor) – input tensor of shape \((N, C, H_{\text{in}}, W_{\text{in}})\) .

  • kernel_size (Union[int, Tuple[int, int]]) – size of the window used to calculate the average value.

  • stride (Union[int, Tuple[int, int], None]) – stride of the window. Default value is kernel_size.

  • padding (Union[int, Tuple[int, int]]) – implicit zero padding added on both sides. Default: 0.

  • mode (str) – whether to include the padding values while calculating the average, set to “average” will do counting. Default: “average_count_exclude_padding”

Return type:

Tensor

Returns:

output tensor of shape \((N, C, H_{\text{out}}, W_{\text{out}})\).

Examples

>>> import numpy as np
>>> inp = Tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4))
>>> F.avg_pool2d(inp, kernel_size=2, stride=2, padding=[1,0], mode="average")
    Tensor([[[[0.25 1.25]
     [6.5  8.5 ]]]], device=xpux:0)