mindspore.mint.nn.Hardswish

class mindspore.mint.nn.Hardswish

Applies Hard Swish activation function element-wise.

Hard swish is defined as:

Hardswish(input)={0, if input3,input, if input+3,input(input+3)/6, otherwise 

Hardswish Activation Function Graph:

../../_images/Hardswish.png
Inputs:
  • input (Tensor) - The input of Hardswish.

Outputs:

Tensor, with the same type and shape as the input.

Raises
  • TypeError – If input is not a tensor.

  • TypeError – If input is neither int nor float.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> from mindspore import Tensor, mint
>>> import numpy as np
>>> input = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16)
>>> hswish = mint.nn.Hardswish()
>>> result = hswish(input)
>>> print(result)
[-0.3333 -0.3333  0.      1.667   0.6665]