37,719
社区成员
发帖
与我相关
我的任务
分享
import tensorflow as tf
from tensorflow.keras.layers import Activation
from tensorflow.keras.utils import get_custom_objects
class Mish(Activation):
'''
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 = Activation('Mish', name="conv1_act")(X_input)
'''
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)})
input_layer = Input((S,S,L,1))
conv_layer1 = Conv3D(filters=10,kernel_size=(3,3,3),activation='relu')(input_layer)
conv3d_shape = conv_layer1._keras_shape
conv_layer1 = Reshape((conv3d_shape[1], conv3d_shape[2], conv3d_shape[3]*conv3d_shape[4]))(conv_layer1)
conv_layer3 = Conv2D(filters=80, kernel_size=(3,3), activation='relu')(conv_layer1)
output_layer = conv_layer3