MaxPool2d

class MaxPool2d(kernel_size, stride=None, padding=0, **kwargs)[source]

Applies a 2D max 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:

\[\begin{aligned} out(N_i, C_j, h, w) ={} & \max_{m=0, \ldots, kH-1} \max_{n=0, \ldots, kW-1} \text{input}(N_i, C_j, \text{stride[0]} \times h + m, \text{stride[1]} \times w + n) \end{aligned}\]

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]]) – 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.

Shape:
  • Input: \((N, C, H_{in}, W_{in})\) or \((C, H_{in}, W_{in})\)

  • Output: \((N, C, H_{out}, W_{out})\) or \((C, H_{out}, W_{out})\), where

    \[H_{out} = \left\lfloor\frac{H_{in} + 2 * \text{padding[0]} - \text{dilation[0]} \times (\text{kernel\_size[0]} - 1) - 1}{\text{stride[0]}} + 1\right\rfloor\]
    \[W_{out} = \left\lfloor\frac{W_{in} + 2 * \text{padding[1]} - \text{dilation[1]} \times (\text{kernel\_size[1]} - 1) - 1}{\text{stride[1]}} + 1\right\rfloor\]
Returns

module. The instance of the MaxPool2d module.

Return type

Return type

Examples

>>> import numpy as np
>>> m = M.MaxPool2d(kernel_size=3, stride=1, padding=0)
>>> inp = mge.tensor(np.arange(0, 16).astype("float32").reshape(1, 1, 4, 4))
>>> oup = m(inp)
>>> oup.numpy()
array([[[[10., 11.],
         [14., 15.]]]], dtype=float32)