Hardtanh

class paddle.nn. Hardtanh ( min=- 1.0, max=1.0, name=None ) [source]

Hardtanh Activation. Create a callable object of Hardtanh.

\[\begin{split}Hardtanh(x)= \left\{ \begin{array}{cll} max,& & \text{if } x > max \\ min,& & \text{if } x < min \\ x,& & \text{otherwise} \end{array} \right.\end{split}\]
Parameters
  • min (float, optional) – The value of min for Hardtanh. Default is -1.

  • max (float, optional) – The value of max for Hardtanh. Default is 1.

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

Shape:
  • input: Tensor with any shape.

  • output: Tensor with the same shape as input.

Examples

>>> import paddle

>>> x = paddle.to_tensor([-1.5, 0.3, 2.5])
>>> m = paddle.nn.Hardtanh()
>>> out = m(x)
>>> print(out)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[-1.       , 0.30000001,  1.       ])
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.