mindspore.mint.nn.Hardswish
- class mindspore.mint.nn.Hardswish[source]
Applies the Hard Swish activation function element-wise.
Hard Swish is defined as:
\[\begin{split}\text{Hardswish}(input) = \begin{cases} 0, & \text{ if } input \leq -3, \\ input, & \text{ if } input \geq +3, \\ input*(input + 3)/6, & \text{ otherwise } \end{cases}\end{split}\]Hardswish Activation Function Graph:
- Inputs:
input (Tensor) - The input tensor to be processed by Hard Swish.
- Outputs:
Tensor, with the same type and shape as the input.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> import numpy as np >>> input = mindspore.Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16) >>> hswish = mindspore.mint.nn.Hardswish() >>> result = hswish(input) >>> print(result) [-0.3333 -0.3333 0. 1.667 0.6665]