快捷方式

Hardshrink

class torch.nn.Hardshrink(lambd=0.5)[source][source]

逐元素地应用 Hard Shrinkage (Hardshrink) 函数。

Hardshrink 定义为

HardShrink(x)={x, if x>λx, if x<λ0, otherwise \text{HardShrink}(x) = \begin{cases} x, & \text{ if } x > \lambda \\ x, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}
参数

lambd (float) – Hardshrink 公式中的 λ\lambda 值。默认值:0.5

形状
  • 输入: ()(*),其中 * 表示任意数量的维度。

  • 输出: ()(*),与输入形状相同。

../_images/Hardshrink.png

示例

>>> m = nn.Hardshrink()
>>> input = torch.randn(2)
>>> output = m(input)

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得您的问题解答

查看资源