hswish.py 603 Bytes
Newer Older
louzana's avatar
louzana committed
1
2
3
4
5
6
7
import torch.nn as nn

from .registry import ACTIVATION_LAYERS


@ACTIVATION_LAYERS.register_module()
class HSwish(nn.Module):
Kai Chen's avatar
Kai Chen committed
8
9
10
11
12
13
    """Hard Swish Module.

    This module applies the hard swish function:

    .. math::
        Hswish(x) = x * ReLU6(x + 3) / 6
louzana's avatar
louzana committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

    Args:
        inplace (bool): can optionally do the operation in-place.
            Default: False.

    Returns:
        Tensor: The output tensor.
    """

    def __init__(self, inplace=False):
        super(HSwish, self).__init__()
        self.act = nn.ReLU6(inplace)

    def forward(self, x):
        return x * self.act(x + 3) / 6