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:

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)