CV:基于Keras利用CNN主流架构之mini_XCEPTION训练情感分类模型hdf5并保存到指定文件夹下-阿里云开发者社区

开发者社区> 人工智能> 正文
登录阅读全文

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

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

图示过程

image.png


核心代码

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


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
人工智能
使用钉钉扫一扫加入圈子
+ 订阅

了解行业+人工智能最先进的技术和实践,参与行业+人工智能实践项目

其他文章
最新文章
相关文章