class
LPPool2d
extends
ModuleLPPool2d(norm_type: float, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, ceil_mode: bool = False)Applies 2-D power-average (Lp-norm) pooling over a spatial feature map.
For each window the module computes:
with = norm_type.
Special cases (same as LPPool1d):
- — sum pooling.
- — Euclidean (energy) pooling.
- — max pooling.
Parameters
norm_typefloatThe exponent .
kernel_sizeint or tuple[int, int]Window size
(k_H, k_W). A scalar is broadcast.strideint or tuple[int, int] or None= NoneStep between windows. Defaults to
kernel_size.ceil_modebool= FalseUse ceiling for output sizes. Default:
False.Attributes
norm_typefloatkhintKernel height.
kwintKernel width.
shintStride along the height dimension.
swintStride along the width dimension.
ceil_modeboolNotes
-
Input:
(N, C, H_in, W_in) -
Output:
(N, C, H_out, W_out)where
H_{out} = \left\lfloor \frac{H_{in} - k_H}{s_H} \right\rfloor + 1, \quad W_{out} = \left\lfloor \frac{W_{in} - k_W}{s_W} \right\rfloor + 1
- Implemented as two sequential
unfold_dimpasses (H-axis then W-axis) followed by element-wise power, reduction, and inverse power. Fully GPU-compatible via engine primitives. - Lp pooling with appears in energy-based models and certain biologically-inspired convolutional architectures.
Examples
L2 energy pooling:
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.LPPool2d(norm_type=2, kernel_size=2, stride=2)
>>> x = lucid.ones((1, 32, 16, 16))
>>> y = pool(x)
>>> y.shape
(1, 32, 8, 8)
Asymmetric window with p=1 (sum pooling):
>>> pool = nn.LPPool2d(norm_type=1, kernel_size=(3, 1), stride=(1, 1))
>>> x = lucid.ones((2, 16, 10, 8))
>>> y = pool(x)
>>> y.shape
(2, 16, 8, 8)Methods (3)
dunder
__init__
→None__init__(norm_type: float, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, ceil_mode: bool = False)Initialise the LPPool2d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the pooling operation to the input tensor.
Parameters
inputTensorInput tensor of shape where are the
spatial dimensions appropriate for this pooling layer.
Returns
TensorPooled output tensor.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.