Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

mish activation function tensorflow

import matplotlib.pyplot as plt
%matplotlib inline

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from keras.engine.base_layer import Layer
from keras.layers import Activation, Dense
from keras import backend as K
from sklearn.model_selection import train_test_split
from keras.datasets import mnist
from keras.optimizers import SGD
from keras.utils import np_utils
from __future__ import print_function
import keras
from keras.models import Sequential
from keras.layers.core import Flatten
from keras.layers import Dropout
from keras.layers import Conv2D, MaxPooling2D
from keras.layers.normalization import BatchNormalization
import numpy as np

class Mish(Layer):
    '''
    Mish Activation Function.
    .. math::
        mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x}))
    Shape:
        - 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.
    Examples:
        >>> 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
      
      

def mish(x):
	return keras.layers.Lambda(lambda x: x*K.tanh(K.softplus(x)))(x)
 
 ###### Use in your model ##########
 
 model.add(Dense(128,activation= mish))
Comment

PREVIOUS NEXT
Code Example
Python :: replacing values in pandas dataframe 
Python :: converting capital letters to lowercase and viceversa in python 
Python :: calculate entropy 
Python :: How to convert a string to a dataframe in Python 
Python :: zermelo api 
Python :: python requests token x-www-form-urlencoded 
Python :: how to extract zip file in jupyter notebook 
Python :: create dataframe from csv and name columns pandas 
Python :: python console command 
Python :: pyqt5 qtwebenginewidgets not found 
Python :: ROLL D6 
Python :: text to speech to specific language python 
Python :: delete a record by id in flask sqlalchemy 
Python :: opposite of .isin pandas 
Python :: how to reset a variable in python 
Python :: np array describe 
Python :: Print a nested list line by line in python 
Python :: how to open a website with selenium python 
Python :: filter an importrange 
Python :: python scatterplot 
Python :: how to graph with python 
Python :: undo cell delete kaggle 
Python :: install chromedriver ubuntu python 
Python :: python how to install numpy on pycharm 
Python :: how to create list from a to z in python 
Python :: insert video in tkinter 
Python :: python for doing os command execution 
Python :: django make migrations 
Python :: python for with iterator index 
Python :: python no new line 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =