評價此頁

Hardswish#

class torch.nn.modules.activation.Hardswish(inplace=False)[source]#

逐元素應用 Hardswish 函式。

論文中描述的方法:Searching for MobileNetV3

Hardswish 定義為

Hardswish(x)={0if x3,xif x+3,x(x+3)/6otherwise\text{Hardswish}(x) = \begin{cases} 0 & \text{if~} x \le -3, \\ x & \text{if~} x \ge +3, \\ x \cdot (x + 3) /6 & \text{otherwise} \end{cases}
引數

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

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

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

../_images/Hardswish.png

示例

>>> m = nn.Hardswish()
>>> input = torch.randn(2)
>>> output = m(input)
forward(input)[source]#

執行前向傳播。

返回型別

張量