Skip to content
fn

lp_pool2d

→Tensor
lp_pool2d(input: Tensor, norm_type: float, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, ceil_mode: bool = False)

2-D power-average pooling — (∑xp)1/p\big(\sum x^p\big)^{1/p}.

Two-dimensional version of lp_pool1d. The exponent pp interpolates between sum / average pooling (small pp) and max pooling (large pp), giving the network a tunable "softness" parameter.

Parameters

inputTensor
Input of shape (N, C, H, W), or (C, H, W) unbatched.
norm_typefloat
Exponent p>0p > 0, or inf.
kernel_sizeint or (int, int)
Size of the pooling window.
strideint or (int, int)= None
Window step. Defaults to kernel_size.
ceil_modebool= False
Use ceil instead of floor in the output-size formula.

Returns

Tensor

Output of shape (N, C, H_out, W_out).

Notes

Math (per window RR):

yi,c,h,w=(∑(m,n)∈Rxi,c,m,np)1/py_{i,c,h,w} = \left( \sum_{(m, n) \in R} x_{i,c,m,n}^p \right)^{1/p}

The power keeps the sign of xx; see lp_pool1d.

Examples

>>> import lucid
>>> from lucid.nn.functional import lp_pool2d
>>> x = lucid.randn(1, 8, 16, 16)
>>> y = lp_pool2d(x, norm_type=3.0, kernel_size=2)
>>> y.shape
(1, 8, 8, 8)

Used by 2