mindspore.ops.HShrink

查看源文件
class mindspore.ops.HShrink(lambd=0.5)[源代码]

Hard Shrink激活函数。

更多参考详见 mindspore.ops.hardshrink()

参数:
  • lambd (float,可选) - Hard Shrink公式定义的阈值 \(\lambda\) 。默认值: 0.5

输入:
  • input_x (Tensor) - Hard Shrink的输入,数据类型为float16或float32。

输出:

Tensor,shape和数据类型与输入 input_x 相同。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore as ms
>>> import mindspore.ops as ops
>>> from mindspore import Tensor, nn
>>> import numpy as np
>>> input_x = Tensor(np.array([[0.5,  1,  2.0], [0.0533, 0.0776, -2.1233]]), ms.float32)
>>> hshrink = ops.HShrink()
>>> output = hshrink(input_x)
>>> print(output)
[[ 0.      1.      2.    ]
[ 0.      0.     -2.1233]]