快捷方式

Hardshrink

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

逐元素套用 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 的全面開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學課程

檢視教學

資源

尋找開發資源並取得您的問題解答

檢視資源