fn
hardswish
→Tensorhardswish(x: Tensor)Hard Swish activation — piecewise linear approximation of silu.
Introduced in MobileNetV3 (Howard et al. 2019) as a compute-friendly replacement for the sigmoid in Swish: the exponential is approximated by a clipped linear function, which is far cheaper on mobile / quantised hardware while preserving the shape of the activation.
Parameters
xTensorInput tensor of any shape; activation is element-wise.
Returns
TensorActivated tensor with the same shape as x.
Notes
Continuous but only piecewise- (the second derivative jumps
at ). Cheap to evaluate and to quantise — preferred
over silu in mobile architectures.
Examples
>>> import lucid
>>> from lucid.nn.functional import hardswish
>>> x = lucid.tensor([-4.0, -1.0, 0.0, 1.0, 4.0])
>>> hardswish(x)
Tensor([ 0.0000, -0.3333, 0.0000, 0.6667, 4.0000])