Skip to content

Instantly share code, notes, and snippets.

Created August 12, 2019 12:58
What would you like to do?
Mish Class Definition in Keras
# Keras Implementation of Mish Activation Function.
# Import Necessary Modules.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from keras.engine.base_layer import Layer
from keras import backend as K
class Mish(Layer):
Mish Activation Function.
.. math::
mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x}))
- Input: Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
- Output: Same shape as the input.
>>> X_input = Input(input_shape)
>>> X = Mish()(X_input)
def __init__(self, **kwargs):
super(Mish, self).__init__(**kwargs)
self.supports_masking = True
def call(self, inputs):
return inputs * K.tanh(K.softplus(inputs))
def get_config(self):
base_config = super(Mish, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
def compute_output_shape(self, input_shape):
return input_shape
Copy link

rupshali commented Oct 6, 2020

Thanks a lot @digantamisra98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment