max_pool2d#

ivy.max_pool2d(x, kernel, strides, padding, /, *, data_format='NHWC', dilation=1, ceil_mode=False, out=None)[source]#

Compute a 2-D max pool given 4-D input x.

Parameters:
  • x (Union[Array, NativeArray]) – Input image [batch_size,h,w,d_in].

  • kernel (Union[int, Tuple[int], Tuple[int, int]]) – Size of the kernel i.e., the sliding window for each dimension of input. [h,w].

  • strides (Union[int, Tuple[int], Tuple[int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (Union[str, int, Tuple[int], Tuple[int, int]]) – SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str) – NHWC” or “NCHW”. Defaults to “NHWC”. (default: 'NHWC')

  • out (Optional[Array]) – optional output array, for writing the result to. (default: None)

Return type:

Array

Returns:

  • ret – The result of the pooling operation.

  • Both the description and the type hints above assumes an array input

  • for simplicity, but this function is *nestable, and therefore*

  • also accepts ivy.Container instances in place of any of

  • the arguments.

Examples

>>> x = ivy.arange(12.).reshape((2, 1, 3, 2))
>>> print(ivy.max_pool2d(x, (2, 2), (1, 1), 'SAME'))
ivy.array([[[[ 2,  3],
         [ 4,  5],
         [ 4,  5]]],
[[[ 8, 9],

[10, 11], [10, 11]]]])

>>> x = ivy.arange(48.).reshape((2, 4, 3, 2))
>>> print(ivy.max_pool2d(x, 3, 1, 'VALID'))
ivy.array([[[[16, 17]],

[[22, 23]]],

[[[40, 41]],

[[46, 47]]]])

Array.max_pool2d(self, kernel, strides, padding, /, *, data_format='NHWC', dilation=1, ceil_mode=False, out=None)#

ivy.Array instance method variant of ivy.max_pool2d. This method simply wraps the function, and so the docstring for ivy.max_pool2d also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input image [batch_size,h,w,d_in].

  • kernel (Union[int, Tuple[int], Tuple[int, int]]) – The size of the window for each dimension of the input tensor.

  • strides (Union[int, Tuple[int], Tuple[int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (str) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str) – “NHWC” or “NCHW”. Defaults to “NHWC”. (default: 'NHWC')

  • out (Optional[Array]) – optional output array, for writing the result to. It must have a shape that (default: None) the inputs broadcast to.

Return type:

Array

Returns:

ret – The result of the max pooling operation.

Examples

>>> x = ivy.arange(12.).reshape((2, 1, 3, 2))
>>> print(x.max_pool2d((2, 2), (1, 1), 'SAME'))
ivy.array([[[[ 2,  3],
         [ 4,  5],
         [ 4,  5]]],
       [[[ 8,  9],
         [10, 11],
         [10, 11]]]])
>>> x = ivy.arange(48.).reshape((2, 4, 3, 2))
>>> print(x.max_pool2d(3, 1, 'VALID'))
ivy.array([[[[16, 17]],
        [[22, 23]]],
       [[[40, 41]],
        [[46, 47]]]])
Container.max_pool2d(self, kernel, strides, padding, /, *, data_format='NHWC', dilation=1, ceil_mode=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#

ivy.Container instance method variant of ivy.max_pool2d. This method simply wraps the function, and so the docstring for ivy.max_pool2d also applies to this method with minimal changes.

Parameters:
  • x – Input image [batch_size,h,w,d_in].

  • kernel (Union[int, Tuple[int], Tuple[int, int]]) – The size of the window to take a max over.

  • strides (Union[int, Tuple[int], Tuple[int, int]]) – The stride of the sliding window for each dimension of input.

  • padding (str) – “SAME” or “VALID” indicating the algorithm, or list indicating the per-dimension paddings.

  • data_format (str) – “NHWC” or “NCHW”. Defaults to “NHWC”. (default: 'NHWC')

  • dilations – The dilation factor for each dimension of input. (Default value = 1)

  • out (Optional[Container]) – optional output array, for writing the result to. It must have a shape (default: None) that the inputs broadcast to.

Return type:

Container

Returns:

ret – The result of the pooling operation.

Examples

>>> a = ivy.arange(12).reshape((2, 1, 3, 2))
>>> b = ivy.arange(48).reshape((2, 4, 3, 2))
>>> x = ivy.Container({'a': a, 'b': b})
>>> print(x.max_pool2d((2, 2), (1, 1), "SAME"))
{
    a: (<class ivy.array.array.Array> shape=[2, 1, 3, 2]),
    b: (<class ivy.array.array.Array> shape=[2, 4, 3, 2])
}