Hardswish

class paddle.nn. Hardswish ( name=None ) [source]

Hardswish activation

Hardswish is proposed in MobileNetV3, and performs better in computational stability and efficiency compared to swish function. For more details please refer to: https://arxiv.org/pdf/1905.02244.pdf

\[\begin{split}Hardswish(x)= \\left\\{ \\begin{aligned} &0, & & \\text{if } x \\leq -3 \\\\ &x, & & \\text{if } x \\geq 3 \\\\ &\\frac{x(x+3)}{6}, & & \\text{otherwise} \\end{aligned} \\right.\end{split}\]
Parameters

name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Shape:
  • input: Tensor with any shape.

  • output: Tensor with the same shape as input.

Examples

import paddle

x = paddle.to_tensor([-4., 5., 1.])
m = paddle.nn.Hardswish()
out = m(x) # [0., 5., 0.666667]
forward ( x )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

Extra representation of this layer, you can have custom implementation of your own layer.