hardsigmoid
- paddle.nn.functional. hardsigmoid ( x: Tensor, slope: float = 0.1666667, offset: float = 0.5, name: str | None = None ) Tensor [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.
hardsigmoid(x)={0,if x≤−31,if x≥3slope∗x+offset,otherwise- 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|None, 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])