AvgPool2d#

class AvgPool2d(kernel_size, stride=None, padding=0, mode='average_count_exclude_padding', **kwargs)[source]#

Applies a 2D average pooling over an input.

For instance, given an input of the size \((N, C, H_{\text{in}}, W_{\text{in}})\) and kernel_size \((kH, kW)\), this layer generates the output of the size \((N, C, H_{\text{out}}, W_{\text{out}})\) through a process described as:

\[out(N_i, C_j, h, w) = \frac{1}{kH * kW} \sum_{m=0}^{kH-1} \sum_{n=0}^{kW-1} input(N_i, C_j, stride[0] \times h + m, stride[1] \times w + n)\]

If padding is non-zero, then the input is implicitly zero-padded on both sides for padding number of points.

Parameters:
  • kernel_size (Union[int, Tuple[int, int]]) – the size of the window.

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

  • padding (Union[int, Tuple[int, int]]) – implicit zero padding to be 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”

Examples

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