Skip to content
class

ReLU6

extends_InplaceActivation
ReLU6(inplace: bool = False)

ReLU6 activation function.

Applies element-wise:

ReLU6(x)=min⁡ ⁣(max⁡(0, x), 6)\text{ReLU6}(x) = \min\!\bigl(\max(0,\, x),\, 6\bigr)

A capped variant of ReLU that clamps activations to the range [0,6][0, 6]. The hard cap prevents activations from growing unboundedly, which can improve robustness of fixed-point quantisation (8-bit or lower) by keeping the dynamic range bounded. Widely used in mobile architectures such as MobileNetV1 and MobileNetV2.

Parameters

inplacebool= False
If True, modifies the input tensor in-place. Default: False.

Notes

  • Input: (∗)(*) — any shape.
  • Output: (∗)(*) — same shape as input, values in [0,6][0, 6].

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.ReLU6()
>>> x = lucid.tensor([-1.0, 0.0, 3.0, 6.0, 10.0])
>>> m(x)
tensor([0., 0., 3., 6., 6.])
>>> # Quantisation-friendly activation in depthwise-separable convolutions
>>> x = lucid.randn(4, 32, 14, 14)
>>> out = m(x)
>>> out.shape
(4, 32, 14, 14)

Used by 1

Instance methods

1
fn

forward

→Tensor
forward(input: Tensor)

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.