Hardsigmoid

paddle.nn. Hardsigmoid ( name=None ) [源代码]

Hardsigmoid 激活层,用于创建一个 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 \\ &x/6 + 1/2, & & \text{otherwise} \end{aligned} \right.\end{split}\]

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

参数

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

形状

  • input:任意形状的 Tensor。

  • output:和 input 具有相同形状的 Tensor。

代码示例

>>> import paddle

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