hardsigmoid

paddle.nn.functional. hardsigmoid ( x, slope=0.1666667, offset=0.5, name=None ) [source]

hardsigmoid activation. Calculate the hardsigmoid of input x. A 3-part piecewise linear approximation of sigmoid(https://arxiv.org/abs/1603.00391), which is much faster than sigmoid.

\[\begin{split}hardsigmoid(x)= \left\{ \begin{array}{lcl} 0, & &\text{if } \ x \leq -3 \\ 1, & &\text{if } \ x \geq 3 \\ slope * x + offset, & &\text{otherwise} \end{array} \right.\end{split}\]
Parameters
  • x (Tensor) – The input Tensor with data type float32, float64.

  • slope (float, optional) – The slope of hardsigmoid function. Default is 0.1666667.

  • offset (float, optional) – The offset of hardsigmoid function. Default is 0.5.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

A Tensor with the same data type and shape as x .

Examples

>>> import paddle
>>> import paddle.nn.functional as F

>>> x = paddle.to_tensor([-4., 5., 1.])
>>> out = F.hardsigmoid(x)
>>> print(out)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.        , 1.        , 0.66666669])