fn

relu6

Tensor
relu6(x: Tensor, inplace: bool = False)
source

Rectified linear unit clipped at six.

Introduced for quantisation-friendly mobile architectures (MobileNetV1 / V2): bounding ReLU above keeps activations inside a small fixed range so that low-precision integer arithmetic does not overflow.

Parameters

xTensor
Input tensor of any shape; activation is element-wise.
inplacebool= False
Accepted for API compatibility; currently ignored.

Returns

Tensor

Activated tensor with the same shape as x, values in [0,6][0, 6].

Notes

ReLU6(x)=min(max(0,x),6)\text{ReLU6}(x) = \min(\max(0, x), 6)

Derivative is 11 on (0,6)(0, 6) and 00 outside — so beyond suffering from "dead neurons" on the negative side, ReLU6 also kills gradients above 66. The trade-off is worthwhile for int8 quantisation where the symmetric [0,6][0, 6] range maps cleanly to a small dynamic-range integer codebook.

Examples

>>> import lucid
>>> from lucid.nn.functional import relu6
>>> x = lucid.tensor([-1.0, 0.0, 3.0, 7.0])
>>> relu6(x)
Tensor([0.0000, 0.0000, 3.0000, 6.0000])