mindspore.mint.nn.Hardsigmoid

View Source On Gitee
class mindspore.mint.nn.Hardsigmoid

Applies Hard Sigmoid activation function element-wise.

Hard Sigmoid is defined as:

Hardsigmoid(input)={0, if input3,1, if input+3,input/6+1/2, otherwise 

Hardsigmoid Activation Function Graph:

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

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)
>>> hsigmoid = mint.nn.Hardsigmoid()
>>> result = hsigmoid(input)
>>> print(result)
[0.3333 0.1666 0.5    0.8335 0.6665]