1.Mish公式
m i s h ( x ) = x ∗ t a n h ( s o f t p l u s ( x ) ) = x ∗ t a n h ( l n ( 1 + e x ) ) mish(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^{x}))\, mish(x)=x∗tanh(softplus(x))=x∗tanh(ln(1+ex))
2.图像
3.ReLU、Swish、Mish在MNIST数据集效果比较
4.代码
import tensorflow as tf
from tensorflow.keras.layers import Activation
from tensorflow.keras.utils import get_custom_objects
class Mish(Activation):
def __init__(self, activation, **kwargs):
super(Mish, self).__init__(activation, **kwargs)
self.__name__ = 'Mish'
def mish(inputs):
return inputs * tf.math.tanh(tf.math.softplus(inputs))
get_custom_objects().update({'Mish': Mish(mish)})
#使用方法
x = Activation('Mish')(x)