mindspore.nn.HSwish

class mindspore.nn.HSwish[source]

Applies Hard Swish activation function element-wise.

Hard swish is defined as:

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

HSwish Activation Function Graph:

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

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 GPU CPU

Examples

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