class
ReLU6
extends
ModuleReLU6(inplace: bool = False)ReLU6 activation function.
Applies element-wise:
A capped variant of ReLU that clamps activations to the range . 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= FalseAccepted for API compatibility; currently unused. Default:
False.Notes
- Input: — any shape.
- Output: — same shape as input, values in .
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)Methods (2)
dunder
__init__
→None__init__(inplace: bool = False)Initialise the ReLU6 module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.