hardsigmoid

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

hardsigmoid 激活层。sigmoid 的分段线性逼近激活函数,速度比 sigmoid 快,详细解释参见 Noisy Activation Functions

\[\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}\]

其中,\(x\) 为输入的 Tensor。

参数

  • offset (float,可选) - hardsigmoid 的截距。默认值为 0.5。

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回

Tensor,数据类型和形状同 x 一致。

代码示例

>>> 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])