hardtanh¶
- paddle.nn.functional. hardtanh ( x, min=- 1.0, max=1.0, name=None ) [source]
-
hardtanh activation. Calculate the hardtanh of input x.
\[\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
-
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) – For details, please refer to Name. Generally, no setting is required. Default: None.
- Returns
-
A Tensor with the same data type and shape as
x
.
Examples
import paddle import paddle.nn.functional as F x = paddle.to_tensor([-1.5, 0.3, 2.5]) out = F.hardtanh(x) # [-1., 0.3, 1.]