hardsigmoid

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

hardsigmoid activation.

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{aligned} &0, & & \\text{if } x \\leq -3 \\\\ &1, & & \\text{if } x \\geq 3 \\\\ &slope * x + offset, & & \\text{otherwise} \\end{aligned} \\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) – Name for the operation (optional, default is None). For more information, please refer to Name.

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) # [0., 1., 0.666667]