HardELiSH関数は、ELiSHのシグモイド関数をハードシグモイド に置き換えた近似(ハード版)で、計算コストを削減しつつ、類似の効果を得るために利用される活性化関数です。
出力は、
です。
活性化関数
更新日:
# PyTorch
import torch
import torch.nn as nn
class NN(nn.Module):
def __init__(self):
super().__init__()
def hard_sigmoid(self, x):
return torch.clamp((x + 1) / 2, min=0.0, max=1.0)
def hard_elish(self, x):
hs = self.hard_sigmoid(x)
return torch.where(x >= 0, x * hs, (torch.exp(x) - 1) * hs)
def forward(self, x):
x = self.hard_elish(x)
return x