class

LPPool2d

extendsModule
LPPool2d(norm_type: float, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, ceil_mode: bool = False)
source

Applies 2-D power-average (Lp-norm) pooling over a spatial feature map.

For each kH×kWk_H \times k_W window the module computes:

y[n,c,h,w]=(kh=0kH1kw=0kW1x ⁣[n,c,hsH+kh,wsW+kw]p)1/py[n,c,h,w] = \left( \sum_{k_h=0}^{k_H-1} \sum_{k_w=0}^{k_W-1} \left|x\!\left[n,\,c,\,h \cdot s_H + k_h,\,w \cdot s_W + k_w\right]\right|^p \right)^{1/p}

with pp = norm_type.

Special cases (same as LPPool1d):

  • p=1p = 1 — sum pooling.
  • p=2p = 2 — Euclidean (energy) pooling.
  • pp \to \infty — max pooling.

Parameters

norm_typefloat
The exponent pp.
kernel_sizeint or tuple[int, int]
Window size (k_H, k_W). A scalar is broadcast.
strideint or tuple[int, int] or None= None
Step between windows. Defaults to kernel_size.
ceil_modebool= False
Use ceiling for output sizes. Default: False.

Attributes

norm_typefloat
khint
Kernel height.
kwint
Kernel width.
shint
Stride along the height dimension.
swint
Stride along the width dimension.
ceil_modebool

Notes

  • 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_dim passes (H-axis then W-axis) followed by element-wise power, reduction, and inverse power. Fully GPU-compatible via engine primitives.
  • Lp pooling with p=2p = 2 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)
source

Initialise the LPPool2d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply the pooling operation to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *) where * are the spatial dimensions appropriate for this pooling layer.

Returns

Tensor

Pooled output tensor.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.