From 71209a60997ad71bf87bc95304e16af2a766758c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 22 Aug 2020 16:59:31 -0700 Subject: [PATCH] exportable Hardswish() implementation --- utils/activations.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/activations.py b/utils/activations.py index 879f7b421..58225c6de 100644 --- a/utils/activations.py +++ b/utils/activations.py @@ -10,6 +10,13 @@ class Swish(nn.Module): # return x * torch.sigmoid(x) +class Hardswish(nn.Module): # alternative to nn.Hardswish() for export + @staticmethod + def forward(x): + # return x * F.hardsigmoid(x) + return x * F.hardtanh(x + 3, 0., 6.) / 6. + + class MemoryEfficientSwish(nn.Module): class F(torch.autograd.Function): @staticmethod