- paddle.nn.functional. adaptive_max_pool2d ( x, output_size, return_mask=False, name=None )
This operation applies a 2D adaptive max pooling on input tensor. See more details in api_nn_pooling_AdaptiveMaxPool2d .
x (Tensor) – The input tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type can be float16, float32, float64, int32 or int64.
output_size (int|list|tuple) – The pool kernel size. If pool kernel size is a tuple or list, it must contain two elements, (H, W). H and W can be either a int, or None which means the size will be the same as that of the input.
return_mask (bool) – If true, the index of max pooling point will be returned along with outputs. Default False.
name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.
The output tensor of adaptive max pool2d result. The data type is same as input tensor.
- Return type
# max adaptive pool2d # suppose input data in the shape of [N, C, H, W], `output_size` is [m, n] # output shape is [N, C, m, n], adaptive pool divide H and W dimensions # of input data into m*n grids averagely and performs poolings in each # grid to get output. # adaptive max pool performs calculations as follow: # # for i in range(m): # for j in range(n): # hstart = floor(i * H / m) # hend = ceil((i + 1) * H / m) # wstart = floor(i * W / n) # wend = ceil((i + 1) * W / n) # output[:, :, i, j] = max(input[:, :, hstart: hend, wstart: wend]) # import paddle input_data = paddle.randn(shape=(2, 3, 32, 32)) out = paddle.nn.functional.adaptive_max_pool2d( x = input_data, output_size=[3, 3]) # out.shape is [2, 3, 3, 3]