LocalResponseNorm
ModuleLocalResponseNorm(size: int, alpha: float = 0.0001, beta: float = 0.75, k: float = 1.0)Local Response Normalization (LRN) across adjacent channels.
Normalises each activation by the mean of the squared activations in a window of channels around it, at the same spatial position:
Channels outside [0, C) count as zero and still count in the
denominator ; for an even size the window leans
towards the lower channels. The module is a thin wrapper over
lucid.nn.functional.local_response_norm, which owns the
rule.
LRN was introduced in the AlexNet paper as a biologically-inspired lateral inhibition mechanism: strongly-activated neurons suppress their neighbors, encouraging competition across feature detectors at the same spatial location. It has largely been superseded by Batch Normalization in modern architectures, but remains available for reproducing historical results.
Parameters
sizeintalphafloat= 0.00011e-4.betafloat= 0.750.75.kfloat= 1.01.0.Notes
- Input: where denotes zero or more spatial dimensions. The channel axis must be axis 1.
- Output: same shape as the input.
- Inputs with fewer than 2 dimensions are returned unchanged.
- The original AlexNet used
size=5,alpha=1e-4,beta=0.75,k=2.0— adjustingkis important to control how strongly unsuppressed channels are penalized.
Examples
Reproduce the AlexNet LRN configuration:
>>> import lucid
>>> import lucid.nn as nn
>>> lrn = nn.LocalResponseNorm(size=5, alpha=1e-4, beta=0.75, k=2.0)
>>> x = lucid.randn(2, 96, 27, 27) # e.g. after first conv in AlexNet
>>> out = lrn(x)
>>> out.shape
(2, 96, 27, 27)
Minimal example with a 1-D channel tensor:
>>> lrn_small = nn.LocalResponseNorm(size=3)
>>> x2 = lucid.randn(4, 32, 64) # (N, C, L)
>>> out2 = lrn_small(x2)
>>> out2.shape
(4, 32, 64)Used by 1
Constructors
1Instance methods
2Return a string representation of the layer's configuration.