CV:基于Keras利用CNN主流架构之mini_XCEPTION训练情感分类模型hdf5并保存到指定文件夹下

图示过程

CV:基于Keras利用CNN主流架构之mini_XCEPTION训练情感分类模型hdf5并保存到指定文件夹下


核心代码

def mini_XCEPTION(input_shape, num_classes, l2_regularization=0.01):

   regularization = l2(l2_regularization)

   # base

   img_input = Input(input_shape)

   x = Conv2D(8, (3, 3), strides=(1, 1), kernel_regularizer=regularization,

                                           use_bias=False)(img_input)

   x = BatchNormalization()(x)

   x = Activation('relu')(x)

   x = Conv2D(8, (3, 3), strides=(1, 1), kernel_regularizer=regularization,

                                           use_bias=False)(x)

   x = BatchNormalization()(x)

   x = Activation('relu')(x)

   # module 1

   residual = Conv2D(16, (1, 1), strides=(2, 2),

                     padding='same', use_bias=False)(x)

   residual = BatchNormalization()(residual)

   x = SeparableConv2D(16, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = Activation('relu')(x)

   x = SeparableConv2D(16, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x)

   x = layers.add([x, residual])

   # module 2

   residual = Conv2D(32, (1, 1), strides=(2, 2),

                     padding='same', use_bias=False)(x)

   residual = BatchNormalization()(residual)

   x = SeparableConv2D(32, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = Activation('relu')(x)

   x = SeparableConv2D(32, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x)

   x = layers.add([x, residual])

   # module 3

   residual = Conv2D(64, (1, 1), strides=(2, 2),

                     padding='same', use_bias=False)(x)

   residual = BatchNormalization()(residual)

   x = SeparableConv2D(64, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = Activation('relu')(x)

   x = SeparableConv2D(64, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x)

   x = layers.add([x, residual])

   # module 4

   residual = Conv2D(128, (1, 1), strides=(2, 2),

                     padding='same', use_bias=False)(x)

   residual = BatchNormalization()(residual)

   x = SeparableConv2D(128, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = Activation('relu')(x)

   x = SeparableConv2D(128, (3, 3), padding='same',

                       kernel_regularizer=regularization,

                       use_bias=False)(x)

   x = BatchNormalization()(x)

   x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x)

   x = layers.add([x, residual])

   x = Conv2D(num_classes, (3, 3),

           #kernel_regularizer=regularization,

           padding='same')(x)

   x = GlobalAveragePooling2D()(x)

   output = Activation('softmax',name='predictions')(x)

   model = Model(img_input, output)

   return model


上一篇:【双11狂欢背后】微服务注册中心如何承载大型系统的千万级访问?


下一篇:SQL server 数据库危险存储过程删除与恢复