📅  最后修改于: 2023-12-03 14:56:06.517000             🧑  作者: Mango
深度智能可分离卷积神经网络(Deeply-Intelligent Separable Convolutional Neural Network,DIS-CNN)是一种基于卷积神经网络(CNN)的深度学习算法。相比于传统的CNN,DIS-CNN 在计算效率和精度上都有很大提升。
可分离卷积是 DIS-CNN 实现的基础。可分离卷积将传统的卷积操作拆分成两步:深度方向的卷积和空间方向的卷积。具体来说,对于一个输入张量,可分离卷积首先对每个通道做深度方向的卷积,然后再对空间维度进行卷积。这样一来,可分离卷积的参数量会大大降低,从而提高了计算效率。
DIS-CNN 的架构由三部分组成:深度可分离卷积模块、特征融合模块和分类模块。
深度可分离卷积模块由多个可分离卷积层组成,每个可分离卷积层分别对输入特征图做深度方向的卷积和空间方向的卷积。这样做的好处是大幅减小了卷积层的参数量。每个可分离卷积层后都有一个批次标准化层(Batch Normalization)和一个激活函数(Activation Function),来对输出特征图做归一化和非线性变换。
特征融合模块将不同深度可分离卷积模块的输出特征图进行融合。具体来说,特征融合模块将高层和低层的特征图按照一定的比例加权融合,得到最终的特征图。特征融合模块的作用是加速特征提取过程,同时也可以提高模型的鲁棒性。
分类模块由数个全连接层组成,用于将特征图映射成分类结果。最后一层采用 softmax 激活函数来得到类别概率。在训练过程中,使用交叉熵损失函数来计算预测结果与真实结果的差异。
相较于传统的 CNN,DIS-CNN 具有以下优势:
[1] Hu J, Shen L, Sun G. Squeeze-and-excitation networks[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2018: 7132-7141.
[2] Chollet F. Xception: Deep learning with depthwise separable convolutions[J]. arXiv preprint, 2017.
[3] Howard A G, Zhu M, Chen B, et al. MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications[J]. arXiv preprint arXiv:1704.04861, 2017.
import tensorflow as tf
from tensorflow.keras.layers import Input, SeparableConv2D, BatchNormalization, Activation, Concatenate, GlobalAveragePooling2D, Dense
def DIS_CNN(image_size, num_classes, num_filters=[32, 64, 128]):
inputs = Input(shape=(image_size, image_size, 3))
# 深度可分离卷积模块
x = inputs
for f in num_filters:
x = SeparableConv2D(f, 3, padding='same', use_bias=False)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = SeparableConv2D(f, 3, padding='same', use_bias=False)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = SeparableConv2D(f, 3, padding='same', use_bias=False)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = tf.keras.layers.MaxPooling2D(2)(x)
# 特征融合模块
low_level_feature = x # 记录最底层的特征
high_level_feature = x
for f in reversed(num_filters[:-1]):
high_level_feature = SeparableConv2D(f, 3, padding='same', use_bias=False)(high_level_feature)
high_level_feature = BatchNormalization()(high_level_feature)
high_level_feature = Activation('relu')(high_level_feature)
high_level_feature = SeparableConv2D(f, 3, padding='same', use_bias=False)(high_level_feature)
high_level_feature = BatchNormalization()(high_level_feature)
high_level_feature = Activation('relu')(high_level_feature)
high_level_feature = SeparableConv2D(f, 3, padding='same', use_bias=False)(high_level_feature)
high_level_feature = BatchNormalization()(high_level_feature)
high_level_feature = Activation('relu')(high_level_feature)
low_level_feature = tf.keras.layers.UpSampling2D(size=(2, 2))(low_level_feature)
high_level_feature = Concatenate()([high_level_feature, low_level_feature])
# 分类模块
x = GlobalAveragePooling2D()(high_level_feature)
x = Dense(num_classes, activation='softmax')(x)
return tf.keras.models.Model(inputs, x)