hardswish¶
hardswish 激活函数。在 MobileNetV3 架构中被提出,相较于 swish 函数,具有数值稳定性好,计算速度快等优点,具体原理请参考:https://arxiv.org/pdf/1905.02244.pdf
hardswish(x)={0,if x≤−3x,if x≥3x(x+3)6,otherwise
其中,x 为输入的 Tensor。
返回¶
Tensor
,数据类型和形状同x
一致。
代码示例¶
>>> import paddle
>>> import paddle.nn.functional as F
>>> x = paddle.to_tensor([-4., 5., 1.])
>>> out = F.hardswish(x)
>>> print(out)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0. , 5. , 0.66666669])