fn
avg_pool2d
→Tensoravg_pool2d(x: Tensor, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, padding: int | tuple[int, int] = 0, ceil_mode: bool = False, count_include_pad: bool = True, divisor_override: int | None = None)2-D average pooling over a sliding window.
Replaces each spatial window with its arithmetic mean. Common as
the last spatial reduction before a fully connected classifier
(modern nets often use adaptive_avg_pool2d for the final
pool because it adapts to arbitrary input sizes).
Parameters
xTensorInput of shape
(N, C, H, W).kernel_sizeint or (int, int)Size of the pooling window.
strideint or (int, int)= NoneWindow step. Defaults to
kernel_size.paddingint or (int, int)= 0Implicit zero-padding on each spatial side.
ceil_modebool= FalseUse ceil instead of floor in the output-size formula.
count_include_padbool= TrueWhen
True, padding cells contribute to the denominator.divisor_overrideint= NoneExplicit denominator overriding
|R| (rare; useful for
symmetric / weight-style averages).Returns
TensorOutput of shape (N, C, H_out, W_out) where each dim obeys
Notes
Math:
Average-pool's gradient is the uniform distribution over the window, which produces smoother backward signals than max-pool.
Examples
>>> import lucid
>>> from lucid.nn.functional import avg_pool2d
>>> x = lucid.randn(1, 8, 28, 28)
>>> y = avg_pool2d(x, kernel_size=2)
>>> y.shape
(1, 8, 14, 14)