AdaptiveMaxPool2d#

class AdaptiveMaxPool2d(oshp, **kwargs)[source]#

Applies a 2D max adaptive pooling over an input.

For instance, given an input of the size \((N, C, H, W)\) and an output shape \((OH, OW)\), this layer generates the output of the size \((N, C, OH, OW)\) 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}\]

kernel_size and stride can be inferred from input shape and out shape:

  • padding: (0, 0)

  • stride: (floor(IH / OH), floor(IW / OW))

  • kernel_size: (IH - (OH - 1) * stride_h, IW - (OW - 1) * stride_w)

Examples

>>> import numpy as np
>>> m = M.AdaptiveMaxPool2d((2, 2))
>>> inp = mge.tensor(np.arange(0, 16).astype("float32").reshape(1, 1, 4, 4))
>>> oup = m(inp)
>>> oup.numpy()
array([[[[ 5.,  7.],
         [13., 15.]]]], dtype=float32)