mindspore.nn.HShrink
- class mindspore.nn.HShrink(lambd=0.5)[source]
Applies Hard Shrink activation function element-wise.
The formula is defined as follows:
HShrink Activation Function Graph:
- Parameters
lambd (number, optional) – The threshold
defined by the Hard Shrink formula. Default:0.5
.
- Inputs:
input (Tensor) - The input of Hard Shrink. Supported dtypes:
Ascend: float16, float32, bfloat16.
CPU/GPU: float16, float32.
- Outputs:
Tensor, the same shape and data type as the input.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import Tensor, nn >>> import numpy as np >>> input = Tensor(np.array([[0.5, 1, 2.0], [0.0533, 0.0776, -2.1233]]), mindspore.float32) >>> hshrink = nn.HShrink() >>> output = hshrink(input) >>> print(output) [[ 0. 1. 2. ] [ 0. 0. -2.1233]]