fn

lp_pool2d

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

2-D Lp-norm 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

xTensor
Input of shape (N, C, H, W).
norm_typefloat
Exponent p>0p > 0.
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 operator is fully differentiable for any p>0p > 0.

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)