AveragePooling#
- class deeptrack.optical.math.AveragePooling(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:
PoolAverage pooling over spatial dimensions.
Reduces spatial resolution by computing the mean over non-overlapping blocks of size ksize.
The interpretation of dimensions depends on channel_axis: - If channel_axis is specified, pooling is applied only over spatial
dimensions and independently per channel.
If channel_axis=None, all dimensions are treated as spatial and are pooled jointly.
Input arrays are cropped from the origin so that each spatial dimension is divisible by the pooling size. Cropping is not centered.
This implementation is consistent across NumPy and PyTorch backends.
Parameters#
- ksize: int or tuple
Pooling window size. Can be: - int → same size for all spatial dimensions - (px, py) → 2D pooling - (pz, px, py) → 3D pooling
- channel_axis: int or None, default=None
Axis corresponding to channels. If None, all dimensions are treated as spatial.
Notes#
Channels are never pooled when channel_axis is specified.
The operation is equivalent to strided average pooling with stride equal to kernel size.
Behavior matches skimage.measure.block_reduce (NumPy) and torch.nn.functional.avg_pool* (PyTorch).
Examples#
>>> import deeptrack as dt
>>> import numpy as np >>> >>> image = np.ones((4, 4, 3)) >>> pool = dt.AveragePooling(ksize=2, channel_axis=-1) >>> out = pool(image) >>> out.shape (2, 2, 3)
>>> pool = dt.AveragePooling(ksize=2, channel_axis=None) >>> out = pool(image) >>> out.shape (2, 2, 1)