閾值 (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} y={x,value, if x>threshold otherwise 參數 threshold (float) – 閥值 value (float) – 用來替換的值 inplace (bool) – 可以選擇是否原地 (in-place) 執行操作。預設值:False 形狀 輸入: (∗)(*)(∗), 其中 ∗*∗ 代表任意數量的維度。 輸出: (∗)(*)(∗), 與輸入相同的形狀。 範例 >>> m = nn.Threshold(0.1, 20) >>> input = torch.randn(2) >>> output = m(input)