hardtanh
- paddle.nn.functional. hardtanh ( x: Tensor, min: float = -1.0, max: float = 1.0, name: str | None = None ) Tensor [source]
-
hardtanh activation. Calculate the hardtanh of input x.
hardtanh(x)={max,if x>maxmin,if x<minx,otherwise- 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|None, 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) >>> print(out) Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [-1. , 0.30000001, 1. ])