megengine.functional.nn.max_pool2d

max_pool2d(inp, kernel_size, stride=None, padding=0)[source]

Applies a 2D max pooling over an input tensor.

Refer to MaxPool2d 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 max 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.

Return type

Tensor

Returns

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

Examples

>>> import numpy as np
>>> input = Tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4))
>>> F.nn.max_pool2d(input, 2, 1, 0)
Tensor([[[[ 5.  6.  7.]
   [ 9. 10. 11.]]]], device=xpux:0)