評價此頁

Hardtanh#

class torch.nn.modules.activation.Hardtanh(min_val=-1.0, max_val=1.0, inplace=False, min_value=None, max_value=None)[原始碼]#

逐元素應用 HardTanh 函式。

HardTanh 定義為:

HardTanh(x)={max_val if x> max_val min_val if x< min_val x otherwise \text{HardTanh}(x) = \begin{cases} \text{max\_val} & \text{ if } x > \text{ max\_val } \\ \text{min\_val} & \text{ if } x < \text{ min\_val } \\ x & \text{ otherwise } \\ \end{cases}
引數
  • min_val (float) – 線性區域範圍的最小值。預設為 -1。

  • max_val (float) – 線性區域範圍的最大值。預設為 1。

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

關鍵字引數 min_valuemax_value 已被棄用,取而代之的是 min_valmax_val

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

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

../_images/Hardtanh.png

示例

>>> m = nn.Hardtanh(-2, 2)
>>> input = torch.randn(2)
>>> output = m(input)
extra_repr()[原始碼]#

返回模組的額外表示。

返回型別

str

forward(input)[原始碼]#

執行前向傳播。

返回型別

張量