Shortcuts

Hardswish

class torch.nn.Hardswish(inplace=False)[源代码]

逐元素应用 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}
Parameters

inplace (布尔值) – 可以选择就地执行操作。默认值:False

Shape:
  • 输入:()(*),其中 * 表示任意数量的维度。

  • 输出: ()(*), 与输入形状相同。

../_images/Hardswish.png

示例:

>>> m = nn.Hardswish()
>>> input = torch.randn(2)
>>> output = m(input)
优云智算