Hardswish

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

对每个元素应用Hardswish函数。

论文中提出的方法:搜索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

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

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

{BASE_RAW_UPLOAD_URL}/pytorch-doc-2.5/2d2e2c4d4861e44f41499aeecbaeb587.png

示例:

>>> m = nn.Hardswish()
>>> input = torch.randn(2)
>>> output = m(input)
本页目录