Skip to content

Instantly share code, notes, and snippets.

@SamJakob
Last active March 29, 2022 00:59
Show Gist options
  • Save SamJakob/4dcdc1a025e16d8562f29c7114f596de to your computer and use it in GitHub Desktop.
Save SamJakob/4dcdc1a025e16d8562f29c7114f596de to your computer and use it in GitHub Desktop.
from tensorflow.keras import backend as K
@tensorflow.function
def angeleaky_elu(x, alpha=1.0):
"""
Custom activation function that introduces a bias between 0 < x < 0.5 to
'throttle' the positive values that the network is not confident in.
"""
return K.switch(
x <= 0, K.elu(x, alpha),
K.switch(
x >= 0.5, K.elu(x, alpha),
K.elu(x, alpha) / 3
)
)
@tensorflow.function
def angeleaky_relu(x, alpha=1.0):
"""
Custom activation function that introduces a bias between 0 < x < 0.5 to
'throttle' the positive values that the network is not confident in.
"""
return K.switch(
x <= 0, K.relu(x, alpha),
K.switch(
x >= 0.5, K.relu(x, alpha),
K.relu(x, alpha) / 3
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment