mish activation function tensorflow

Solutions on MaxInterview for mish activation function tensorflow by the best coders in the world

showing results for - "mish activation function tensorflow"
Nele
23 Sep 2018
1import matplotlib.pyplot as plt
2%matplotlib inline
3
4from __future__ import absolute_import
5from __future__ import division
6from __future__ import print_function
7
8from keras.engine.base_layer import Layer
9from keras.layers import Activation, Dense
10from keras import backend as K
11from sklearn.model_selection import train_test_split
12from keras.datasets import mnist
13from keras.optimizers import SGD
14from keras.utils import np_utils
15from __future__ import print_function
16import keras
17from keras.models import Sequential
18from keras.layers.core import Flatten
19from keras.layers import Dropout
20from keras.layers import Conv2D, MaxPooling2D
21from keras.layers.normalization import BatchNormalization
22import numpy as np
23
24class Mish(Layer):
25    '''
26    Mish Activation Function.
27    .. math::
28        mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x}))
29    Shape:
30        - Input: Arbitrary. Use the keyword argument `input_shape`
31        (tuple of integers, does not include the samples axis)
32        when using this layer as the first layer in a model.
33        - Output: Same shape as the input.
34    Examples:
35        >>> X_input = Input(input_shape)
36        >>> X = Mish()(X_input)
37    '''
38
39    def __init__(self, **kwargs):
40        super(Mish, self).__init__(**kwargs)
41        self.supports_masking = True
42
43    def call(self, inputs):
44        return inputs * K.tanh(K.softplus(inputs))
45
46    def get_config(self):
47        base_config = super(Mish, self).get_config()
48        return dict(list(base_config.items()) + list(config.items()))
49
50    def compute_output_shape(self, input_shape):
51        return input_shape
52      
53      
54
55def mish(x):
56	return keras.layers.Lambda(lambda x: x*K.tanh(K.softplus(x)))(x)
57 
58 ###### Use in your model ##########
59 
60 model.add(Dense(128,activation= mish))