當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch Threshold用法及代碼示例

本文簡要介紹python語言中 torch.nn.Threshold 的用法。

用法:

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

參數

  • threshold-閾值的值

  • value-要替換的值

  • inplace-可以選擇就地執行操作。默認值:False

閾值輸入張量的每個元素。

閾值定義為:

形狀:
  • 輸入: ,其中 表示任意數量的維度。

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

例子:

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

相關用法


注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.nn.Threshold。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。