MaxPooling#

class deeptrack.optical.math.MaxPooling(ksize: int | tuple[int, int] | tuple[int, int, int] | Callable[[...], int | tuple[int, int] | tuple[int, int, int]] = 2, channel_axis: int | None = None, **kwargs: Any)#

Bases: Pool

Max pooling over spatial dimensions.

Reduces spatial resolution by taking the maximum over non-overlapping blocks of size ksize.

The interpretation of dimensions depends on channel_axis:

  • If channel_axis is specified, pooling is applied independently per channel and never across channels.

  • If channel_axis=None, all dimensions are treated as spatial.

Input arrays are cropped from the origin so that each spatial dimension is divisible by the pooling size.

Works with both NumPy and PyTorch backends.

Parameters#

ksize: int or tuple

Pooling window size.

channel_axis: int or None, default=None

Axis corresponding to channels.

Notes#

  • Equivalent to standard max pooling with stride equal to kernel size.

  • Preserves extrema and is non-linear (unlike average pooling).

Examples#

>>> import deeptrack as dt
>>> import numpy as np
>>>
>>> image = np.random.rand(4, 4, 3)
>>> pool = dt.MaxPooling(ksize=2, channel_axis=-1)
>>> out = pool(image)
>>> out.shape
(2, 2, 3)