模型压缩之Knowledge Adaptation for Efficient Semantic Segmentation

Knowledge Adaptation for Efficient Semantic Segmentation


image.png

原始文档:https://www.yuque.com/lart/gw5mta/kdess

CVPR2019使用蒸馏做语义分割的一篇文章。

主要工作

针对语义分割任务对传统蒸馏方法进行了一些改进

  • 使用自编码器来使得教师网络的知识更易学习
  • 使用关联适配模块来使得学生模型在学习教师知识的时候可以看到更多,提取更多的远程关联信息
  • 添加了了特征适配器来实现教师与学生特征之间的适配,促进更好的学习
  • 针对不同的结构设计了不同的损失来进行监督

对于目前在语义分割的工作中,模型一般会使用较大的分辨率的特征进行计算,导致网络参数量和计算复杂度太大,限制了实际的应用与发展,所以逐渐有工作开始探究如何处理这样的问题。一个思路是降低特征的分辨率,但是这会导致大量细节信息的缺失,不利于预测的准确性。如何解决这个困境,在准确性和效率之间找到更好的平衡,已经讨论了很长时间。被Hinton提出的知识蒸馏方法,因为其简单而有效的表现,收到了很多关注。

The knowledge in KD is defined as soft label output from a large teacher network, which contains more useful information, such as intraclass similarity, than one-hot encoding. The student network is supervised by both soft labels and hard one-hot labels simultaneously, reconciled by a hyper-parameter to adjust the loss weight.

Following KD, many methods are proposed to regulate the intermediate features. However, these methods are mainly designed for the image-level classification task without considering the spatial context structures. Moreover, in the semantic segmentation task, the feature maps from the teacher and student usually have inconsistent context and mismatched features. Thus these methods are improper to be used for semantic segmentation directly.

与本文有关的主要工作文章分析了三篇:

  1. Distilling the Knowledge in a Neural Network
    1. 开创性工作,主要针对图像分类任务
    2. 有一定的局限:
      1. FitNet的作者试图迫使学生在决策空间中模拟教师网络的输出分布,其中有用的上下文信息是级联的
      2. 对于图像级分类任务,需要的知识对于两个模型来说是相似的,但是语义分割的决策空间可能不同,因为两个模型有着不同的捕获远程和上下文依赖关系的能力,这依赖于网络的结构
      3. 温度超参数对于任务而言是敏感的,并且很难调整,尤其是对于大的基准数据集。
  2. FitNets: Hints for Thin Deep Nets
    1. 对于学习中间表示,而直接使用对齐特征图的方法,这对忽略两个模型之间的内在差异(如空间分辨率、通道数和网络架构)来说,可能不是一个好的选择
    2. 同时,两种模型的抽象能力存在显著差异,可能会使这种情况更加严重
  3. Paying More At-tention to Attention: Improving the Performance of Convo-lutional Neural Networks via Attention Transfer
    1. 旨在模拟学生和老师模型之间的注意力图,这基于假设:特征图沿通道维度的加和在图像分类任务中可能表示注意力分布
    2. 然而,这种假设可能不适合像素级的分割任务,因为不同的通道表示不同类的激活,简单地对通道进行求和就会得到混淆了的注意力图

网络结构

image.png

从图中可以看出文章的几个关键结构:

  1. Auto-Encoder
  2. Feature Adapter
  3. Affinity Distillation Module

关于文中反复提到的“知识”的表达,主要定为两个方面:

  1. The first part is designed for translating the knowledge from the teacher network to a compressed space that is more informative. The translator is achieved by training an autoencoder to compress the knowledge to a compact format that is easier to be learned by the student network, otherwise much harder due to the inherent structure differences.
  2. The second part is designed to capture long-range dependencies from the teacher network, which is difficult to be learned for small models due to the limited receptive field and abstracting capability. 小网络自身很难提取远程依赖关系,进而通过老师网络来进行学习。

Auto-Encoder

image.png

用来重构教师模型的特征,以获得更为有用和重要的信息。通过训练一个自编码器,来挖掘显式的结构信息,并将老师的知识“简化”,转换成对于学生网络更容易理解复制的知识。与低、中阶特征相比,高阶特征更适合我们的实际情况。低、中阶特征由于固有的网络差异,一般在在不同的模型中普遍存在或者而难以传输。

Directly transferring the outputs from teacher overlooks the inherent differences of network architecture between two models. Compact representation, on the other hand, can help the student focus on the most critical part by removing redundancy knowledge and noisy information.

在提出的模型中,自编码器将来自教师模型的最后的卷积层特征作为输入,其中使用了三个非一跨步的卷积层以及对称的转置卷积层。
这里对于自编码器训练的重构损失可以表达为:

image.png

  • E和D表示的就是对应的编码器和解码器
  • alpha对于所有试验设定为10e-7
  • 表示教师网络的最后的特征图,表示学生网络的最后的特征图

在训练auto-encoder的过程中,一个常见的问题是模型可能只学习一个恒等函数,这意味着提取的结构知识更有可能与输入特性共享相同的模式。这里对损失添加了一个l1范数来进行约束,因为l1范数可以产生一个稀疏表达。

这里的策略类似于_Babajide O. Ayinde and Jacek M. Zurada. Deep Learning of Constrained Autoencoders for Enhanced Understanding of Data. IEEE Trans. Neural Netw. & Learn. Syst., 2018._ 中用来正则化权重和重表示(re-represented)空间的策略。

Feature Adapter

image.png

为了解决特征不匹配问题和降低教师模型与学生模型之间存在的固有网络差异造成的影响,通过添加一个卷积层来作为特征适配器(feature adapter)。这里在整体训练的时候会设置一个损失函数,进而对知识迁移过程进约束:

image.png

  • 这里的E表示自编码器
  • I表示对于所有位置上对于student-teacher的成对信息的索引(也就是“所有位置集合“)
  • Cf是对于学生网络特征设置的适配器,这里使用了一个 3 × 3 3 \times 3 3×3核大小,步长为1,padding为1,包含BN和ReLU的卷积层
  • 特征在匹配之前进行归一化
  • 这里的p和q是不同的范数类型以归一化知识,来提升稳定性

Affinity Distillation Module

image.png

由于小网络缺乏抽象能力,在学习知识的过程中能力有限,这也导致其在捕获远程依赖关系的能力上有限。而捕获远程依赖关系对于语义分割任务而言是重要且有益的。文章因此针对小网络在学习大网络的知识的过程中,设置了一个新提出的affinity distillation module,借此来提取来自大的教师模型特征中的远程非局部依赖关系。

在学习中,有时通过提供额外的差异信息或相关联的信息来学习新知识会更有效。这里在网络中定义了关联信息,通过直接计算任意特征位置之间的交互,而不考虑其空间距离。这样,对于有些特征信息相近的像素位置可以得到较高的响应结果,而对于差异较大的结果会得到较低的响应结果。(这里相比**余弦距离(向量空间中两个向量夹角的余弦值)**多了一些数值大小关系上的考虑)

这里实际上设计计算关联矩阵的时候,使用的还是余弦距离(注意这里表示的是A矩阵中对应于位置(i,j)处的值的计算,也就是得到的是一个1x1的值):

image.png


余弦距离,可以看出就是向量点积或內积除以各自的L2范数,也就是各自的长度、模:

image.png


  • 这里的运算应该表示的是点积,这样才能由两个1xc的矢量计算得到一个的1x1的值
  • 这里的A整体表示的是使用空间归一化以后的关联矩阵,是一个mxm的矩阵,表示两个hxw的特征图上任意点之间的关联
  • 这里的 Φ \Phi Φ表示最后一层特征图,大小为hxwxc,对应前面的m=hxw,所以实际上是将两个特征图向量化了
  • 教师和学生都有自己的一个关联矩阵

这里使用l2损失来约束教师与学生之间的关联矩阵,定义如下:

image.png

Train Process

image.png
有几个关键点:

  1. 教师模型事先是训练好的(是从哪些数据集上训练的呢?和学生模型训练使用的是一样的数据么?
  2. 学生网络使用了三个损失来进行监督,使用权重系数beta和gamma(试验中被设置为50和1)加权获得最终的整体:
    1. 使用真值标签监督的交叉熵损失Lce
    2. 适配损失Ladapt
    3. 关联转换损失Laff
  3. WE、WD、WS表示编码器、解码器和学生模型的参数
  4. 要注意整体结构图,虽然训练了一个自编码器,但是实际在训练学生模型的时候,使用的仅是其编码器部分,所以第一阶段主要寻找一个最优的编码器

实验细节

  • Training teacher network
    • To demonstrate the effectiveness of our method, we select two totally different teacher models, ResNet-50 and Xception-41. Both atrous convolution and atrous spatial pyramid pooling (ASPP) are utilized to obtain a series of feature maps with large size.
    • We use mini-batch stochastic gradient descent (SGD) with batch size 16 (at least 12), momentum 0.9, and weight decay 4×10e−5 in training. Similar to [Encoder-Decoder with Atrous Separable Convolution for Semantic Image Segmentation], we apply the poly learning rate strategy with power 0.9. The initial learning rate is 0.007.
    • General data augmentation methods are also used in network training, such as randomly flipping the images and randomly performing scale jitter.
      • For the Pascal VOC dataset, the training process can be split into two steps.First, we train 300K iterations on the COCO dataset, then 30K iterations on the trainaug dataset.
      • For theCityscapes dataset, we do not pre-train our model on the COCO dataset for fair comparison. We train 90K iterations on the train-fine dataset, which is fine tuned on trainval and train-coarse to evaluate on test dataset.
      • For the Pascal Context dataset, the COCO dataset is not used for pre-training. 30k iterations are trained on the train set and evaluated on the val set.
  • Training auto encoder.
    • We finished the auto-encoder training within one epoch with a learning rate of 0.1.
    • Large weight decay of 10e−4 is used to attribute low energy to a smaller portion of the input points.
  • Training the whole system.
    • Most of the training parameters are similar to the process of training the teacher network, except that our student network does not involve the ASPP and the decoder, which are exactly the same with [MobileNetV2: Inverted Residuals and Linear Bottlenecks].
    • With the help of atrous convolution, low resolution feature maps are generated.
    • During the training process, the parameters of the teacher net WT and the parameters for auto-encoder WE are fixed without updating.

对于关联矩阵A中的特定位置进行可视化:

image.png

可以看出来,通过添加关联蒸馏模块,使得对于全局的响应更为明确和清晰。上图中绘制的彩图,是全图关于原图红色加号位置得到的响应情况。

image.png

因为如果两个模型具有不同的输出特征,关联矩阵会不匹配。为了显示单个关联模块的效果,我们将特征映射的大小调整为相同的尺寸(resize)

image.png

在图1中可以找到不同输出步幅设置的比较。其中16s模型甚至比仅使用8%FLOPS的4s输出的基线模型更好,而不引入额外的参数

image.png

这是其他的一些验证试验。In this experiment, we make comparisons with other knowl-edge distillation methods: KD [11] and FitNet [20],

  1. KD is designed for image-level classification. The knowledge defined in KD is the soft label output by a teacher network. The soften degree is controlled by a hyper-parameter temperature t, which has a significant influence on the distillation and learning processes. We set t to 2, 4, 6. To make fair comparisons, we bilinearly upsample the logits map to the size of the teacher network.
  2. FitNet, different from KD, tries to match the intermediate representation between two models. But this requires similar network design. In our experiments, we directly upsample the feature map of the last layer and add a ℓ2 loss. The loss curve is shown in Figure 5.

image.png

image.png

Our method achieves better performances than KD, with all the hyper-parameters fixed across all experiments and datasets. Our method also outperforms FitNet by 1.2 points, indicating that the knowl-edge defined by our method alleviates the inherent difference of two networks.

image.png

Compared with the traditional methods, the qualitative segmentation results in Figure 4 visually demonstrate the effectiveness of our distillation method for objects that require more context information, which is captured by our proposed affinity transfer module.

image.png

On the other hand, the knowledge translator and adapter reduce the loss of the detailed information and produce more consistent and detail-preserving predictions, as shown in Figure 6.

image.png

image.png

一些思考

  • 文章中关于模型如何生成最终的预测没有讲太多,有可能是直接上采样?
  • 这篇文章比较实验的设计
    • 主要针对的是一些轻量模型
    • 自身的消融实验
    • 主要比较了运算量和参数以及相关的指标

参考链接

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
CVPR 2019中发表了一篇题为“迁移学习:无监督领域自适应的对比适应网络(Contrastive Adaptation Network for Unsupervised Domain Adaptation)”的论文。这篇论文主要介绍了一种用于无监督领域自适应的对比适应网络。 迁移学习是指将从一个源领域学到的知识应用到一个目标领域的任务中。在无监督领域自适应中,源领域和目标领域的标签信息是不可用的,因此算法需要通过从源领域到目标领域的无监督样本对齐来实现知识迁移。 该论文提出的对比适应网络(Contrastive Adaptation Network,CAN)的目标是通过优化源领域上的特征表示,使其能够适应目标领域的特征分布。CAN的关键思想是通过对比损失来对源领域和目标领域的特征进行匹配。 具体地说,CAN首先通过一个共享的特征提取器来提取源领域和目标领域的特征表示。然后,通过对比损失函数来测量源领域和目标领域的特征之间的差异。对比损失函数的目标是使源领域和目标领域的特征在特定的度量空间中更加接近。最后,CAN通过最小化对比损失来优化特征提取器,以使源领域的特征能够适应目标领域。 该论文还对CAN进行了实验验证。实验结果表明,与其他无监督领域自适应方法相比,CAN在多个图像分类任务上取得了更好的性能,证明了其有效性和优越性。 综上所述,这篇CVPR 2019论文介绍了一种用于无监督领域自适应的对比适应网络,通过对源领域和目标领域的特征进行对比学习,使得源领域的特征能够适应目标领域。该方法在实验中展现了较好的性能,有望在无监督领域自适应任务中发挥重要作用。
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值