Skip to content

Instantly share code, notes, and snippets.

@chrico-bu-uab
Last active November 26, 2019 03:11
Show Gist options
  • Save chrico-bu-uab/63ba87c18f8a314e1062f6d86254f285 to your computer and use it in GitHub Desktop.
Save chrico-bu-uab/63ba87c18f8a314e1062f6d86254f285 to your computer and use it in GitHub Desktop.
which version is better?
from scipy.special import expit
class Eswish1(Layer):
def __init__(self, beta):
self.ReLUness = 0
self.layertype = 'Eswish'
self.beta = beta
def forward(self, input, is_train):
self.input = input
self.sigmoid = expit(input)
self.fx = self.beta * input * self.sigmoid
return self.fx
def backward(self, dy):
grad = self.fx + self.sigmoid * (self.beta - self.fx)
return dy*grad
class Eswish2(Layer):
def __init__(self, beta):
self.ReLUness = 0
self.layertype = 'Eswish'
self.beta = beta
def forward(self, input, is_train):
self.input = input
sigmoid = expit(input)
fx = self.beta * input * sigmoid
self.grad = fx + sigmoid * (self.beta - fx)
return fx
def backward(self, dy):
return dy*self.grad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment