GhostNet: More Features from Cheap Operations

原文地址:GhostNet: More Features from Cheap Operations

官方实现:huawei-noah/CV-Backbones

复现地址:ZJCV/ZCls

摘要

Deploying convolutional neural networks (CNNs) on embedded devices is difficult due to the limited memory and computation resources. The redundancy in feature maps is an important characteristic of those successful CNNs, but has rarely been investigated in neural architecture design. This paper proposes a novel Ghost module to generate more feature maps from cheap operations. Based on a set of intrinsic feature maps, we apply a series of linear transformations with cheap cost to generate many ghost feature maps that could fully reveal information underlying intrinsic features. The proposed Ghost module can be taken as a plug-and-play component to upgrade existing convolutional neural networks. Ghost bottlenecks are designed to stack Ghost modules, and then the lightweight GhostNet can be easily established. Experiments conducted on benchmarks demonstrate that the proposed Ghost module is an impressive alternative of convolution layers in baseline models, and our GhostNet can achieve higher recognition performance (e.g. 75.7% top-1 accuracy) than MobileNetV3 with similar computational cost on the ImageNet ILSVRC-2012 classification dataset. Code is available at https://github.com/huawei-noah/ghostnet.

由于有限的内存和计算资源,在嵌入式设备上部署卷积神经网络非常困难。特征映射中的冗余是那些成功的CNN的一个重要特征,但在神经结构设计中很少被研究。本文提出了一种新的Ghost模块,通过廉价的操作生成更多的特征图。基于一组内在特征映射,我们以低廉的成本应用一系列线性变换来生成能够充分揭示内在特征背后的信息的多个重影特征映射。所提出的Ghost模块可以作为即插即用组件来升级现有的卷积神经网络。Ghost瓶颈旨在堆叠Ghost模块,然后可以轻松建立轻量级GhostNet。在基准上进行的实验表明,所提出的Ghost模块是基线模型中卷积层的一个令人印象深刻的替代方案,并且我们的GhostNet可以在ImageNet ILSVRC-2012分类数据集上以相似的计算成本实现比MobileNetV3更高的识别性能(例如,75.7%的前1准确率)。代码已开源:https://github.com/huawei-noah/ghostnet

简介

在设计轻量级模型的过程中,出现了许多方法,大体分为两种方式:

  1. 对已有模型进行轻量化操作,比如剪枝、量化和知识蒸馏;
  2. 设计轻量级算子,比如MobileNet系统使用的深度可分离卷积(深度卷积+逐点卷积)、ShuffleNet系列设计的分组卷积+通道重排操作

论文同样设计了一个新的轻量级模块 - Ghost。通过实验发现特征图之间存在冗余性和相关性,如图1所示,论文设计的Ghost模块运用简单线性操作对一部分卷积生成的特征图进行扩增,以期通过生成更多的冗余特征图在更少参数和计算量的情况下实现更好的性能。通过堆叠Ghost模块得到的GhostNet也超越了MobileNetV3

GhostModule

公式推理

假定输入数据为\(X\in R^{c\times h\times w}\),其中

  • \(c\)是通道数;
  • \(h\)是图像高;
  • \(w\)是图像宽。

对于卷积操作,其计算如下:

\[ Y=X\ast f + b ,\ Y\in R^{h'\times w'\times n} ,\ f\in R^{c\times k\times k\times n} \]

  • \(\ast\)表示卷积操作
  • \(b\)表示偏置操作
  • \(Y\)表示输出特征图
  • \(f\)表示卷积核,卷积核大小为\(k\times k\)

对于Ghost模块,首先使用卷积层生成\(m\)个特征图\({Y}'\in R^{h'\times w'\times m}\)

\[ Y'\in X*f' \]

  • 滤波器大小为\({f}'\in R^{c\times k\times k\times m}\)
  • \(m\leq n\)

对特征图\({Y}'\)执行线性操作,生成\(s\)个ghost特征图:

\[ y_{ij} = \Phi_{i,j}({y}'_{i}), \forall i = 1, ... , m, j=1, ..., s \]

  • \({y}'_{i}\)表示\({Y}'\)中第\(i\)个特征图;
  • \(\Phi_{i,j}\)表示第\(j\)个线性操作(共\(s-1\)个),生成第\(j\)ghost特征图\(y_{ij}\)
  • 最后一个线性操作\(\Phi_{i,s}\)表示一致性映射,用于保留原先\({Y}'\)的内在特征图;

经过线性操作(论文推荐使用深度卷积)后,能够得到\(n=m\cdot s\)个特征图\(Y=[y_{11}, y_{12}, ..., y_{ms}]\)

复杂度估计

普通卷积操作的FLOPs计算公式如下:

\[ n\cdot {h}'\cdot {w}'\cdot c\cdot k\cdot k \]

Ghost模块中,额外运用了一个一致性映射(identity mapping)以及\(m\cdot (s-1)=\frac{n}{s}\cdot (s-1)\)个线性操作。假定每个线性操作的核大小为\(d\times d\)GhostNet使用了相同大小(\(3\times 3\)或者\(5\times 5\)

其理论FLOPs与普通卷积的比率计算如下:

\[ r_{s} = \frac{n\cdot {h}'\cdot {w}'\cdot c\cdot k\cdot k}{\frac{n}{s}\cdot {h}'\cdot {w}'\cdot c\cdot k\cdot k + (s-1)\cdot \frac{n}{s}\cdot {h}'\cdot {w}'\cdot d\cdot d} = \frac{c\cdot k\cdot k}{\frac{1}{s}\cdot c\cdot k\cdot k + \frac{s-1}{s}\cdot d\cdot d} \approx \frac{s\cdot c}{s + c-1} \approx s \]

其中\(d\times d\)\(k\times k\)拥有相近的大小并且\(s\ll c\)。其理论参数压缩比计算公式如下:

\[ r_{c} = \frac{n\cdot c\cdot k\cdot k}{\frac{n}{s}\cdot c\cdot k\cdot k+(s-1)\cdot \frac{n}{s}\cdot d\cdot d} \approx \frac{s\cdot c}{s+c-1} \approx s \]

GhostBottleneck

GhostBottleneck执行先膨胀后缩减的策略:

  • 第一个GhostModule作为扩张层进行维度扩张,设置了一个超参数\(expansion\ ratio\),用于计算输出通道数和输入通道数的比率
  • 第二个GhostModule用于维度衰减;
  • 在每一层之后均执行BN+ReLU,同时参考MobileNetV2设计,在第二个GhostModule之后不应用ReLU
  • stride=2时,在shortcut路径执行下采样操作;同时在两个GhostModule之间插入一个深度卷积;
  • 在实际实现中,对于GhostModule中的primary convolution执行逐点卷积操作

GhostNet

GhostNet整体设计参考了MobileNetV3

  • 第一层是一个标准卷积层,其滤波器个数为16
  • 后续跟着不同的GhostBottleneck,依据输入特征图个数划分到不同阶段;
  • 在每个阶段中,对最后一个GhostBottleneck执行stride=2,其余均执行stride=1
  • 因为hard-swish的延迟原因,在GhostNet中并没有采用;

确定s和d大小

\(s\)用于确定GhostModule的计算量加速以及参数压缩比率,\(d\)用于确定线性操作的核大小。论文基于Cifar10数据集以及VGG-16模型进行了实验

首先,将GhostModule替换普通卷积层得到Ghost-VGG-16模型,固定\(s=2\),调整\(s\in [1, 3, 5, 7]\),其实验结果如表3所示,\(d=3\)能够实现最好的性能

其次,固定\(d=3\),调整\(s\in [2,3,4,5]\),其实验结果如表4所示,\(s=2\)能够得到比较平衡的效果。

注:从试验结果看,提高\(s\)确实能够有效降低计算量和参数个数,同时模型精度并没有较大降低

确定\(s=2\)\(d=3\)大小后,论文测试了Ghost-VGG-16Ghost-ResNet-56如下:

ImageNet

论文测试了在ResNet-50中插入GhostModule的结果:

同时测试了GhostNet与其他轻量级模型的比较: