快捷鍵

閾值 (Threshold)

class torch.nn.Threshold(threshold, value, inplace=False)[source][source]

對輸入 Tensor 的每個元素進行閾值處理。

閾值定義為

y={x, if x>thresholdvalue, otherwise y = \begin{cases} x, &\text{ if } x > \text{threshold} \\ \text{value}, &\text{ otherwise } \end{cases}
參數
  • threshold (float) – 閥值

  • value (float) – 用來替換的值

  • inplace (bool) – 可以選擇是否原地 (in-place) 執行操作。預設值:False

形狀
  • 輸入: ()(*), 其中 * 代表任意數量的維度。

  • 輸出: ()(*), 與輸入相同的形狀。

範例

>>> m = nn.Threshold(0.1, 20)
>>> input = torch.randn(2)
>>> output = m(input)

文件

取得 PyTorch 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源