hardtanh

paddle.nn.functional. hardtanh ( x, min=- 1.0, max=1.0, name=None ) [source]

hardtanh activation

\[\begin{split}hardtanh(x)= \\begin{cases} max, \\text{if } x > max \\\\ min, \\text{if } x < min \\\\ x, \\text{otherwise} \\end{cases}\end{split}\]
Parameters
  • x (Tensor) – The input Tensor with data type float32, float64.

  • min (float, optional) – The minimum value of the linear region range. Default is -1.

  • max (float, optional) – The maximum value of the linear region range. Default is 1.

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

Returns

A Tensor with the same data type and shape as x .

Examples

import paddle
import paddle.nn.functional as F
import numpy as np

x = paddle.to_tensor(np.array([-1.5, 0.3, 2.5]))
out = F.hardtanh(x) # [-1., 0.3, 1.]