Hardswish#
- class brainstate.nn.Hardswish(name=None)#
Applies the Hardswish function, element-wise.
As described in the paper Searching for MobileNetV3.
Hardswish is defined as:
\[\begin{split}\text{Hardswish}(x) = \begin{cases} 0 & \text{if~} x \le -3, \\ x & \text{if~} x \ge +3, \\ x \cdot (x + 3) /6 & \text{otherwise} \end{cases}\end{split}\]Shape#
Input: \((*)\), where \(*\) means any number of dimensions.
Output: \((*)\), same shape as the input.
Examples
>>> import brainstate.nn as nn >>> import brainstate >>> m = nn.Hardswish() >>> x = brainstate.random.randn(2) >>> output = m(x)