评价此页

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}
参数

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

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

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

../_images/Hardswish.png

示例

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

执行前向传播。

返回类型

张量