Hardsigmoid

class paddle.nn. Hardsigmoid ( name=None ) [source]

Hardsigmoid Activiation Layers, Construct a callable object of the Hardsigmoid class. This layer calcluate 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}{rcl} 0, & & \text{if } \ x \leq -3 \\ 1, & & \text{if } \ x \geq 3 \\ x/6 + 1/2, & & \text{otherwise} \end{array} \right.\end{split}\]
Parameters

name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Shape:

x: N-D tensor, available dtype is float32, float64.

Returns

A callable object of Hardsigmoid.

Examples

>>> 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])
forward ( x )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

Extra representation of this layer, you can have custom implementation of your own layer.