Skip to content
fn

prelu

→Tensor
prelu(input: Tensor, weight: Tensor)

Parametric Rectified Linear Unit (He et al. 2015).

Variant of leaky_relu whose negative slope is a learnable parameter rather than a fixed hyperparameter. In practice weight may be a scalar (shared across channels) or a per-channel vector, matching the convention of the reference framework's nn.PReLU.

Parameters

inputTensor
Input tensor.
weightTensor
Learnable slope α\alpha. Either a scalar tensor (slope shared across all elements) or a 1-D tensor broadcastable against input along the channel dimension.

Returns

Tensor

Activated tensor with the same shape as input.

Notes

PReLU(x)=max⁡(0,x)+αmin⁡(0,x)\text{PReLU}(x) = \max(0, x) + \alpha \min(0, x)

Allows the optimiser to discover the optimal negative-side slope per channel; the original paper showed this reaches super-human ImageNet accuracy. When α=0\alpha = 0 recovers relu; for a fixed non-zero α\alpha see leaky_relu.

Examples

>>> import lucid
>>> from lucid.nn.functional import prelu
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0])
>>> w = lucid.tensor(0.25)
>>> prelu(x, w)
tensor([-0.5, -0.25, 0., 1.])

Used by 2