知行编程网知行编程网  2022-06-06 16:00 知行编程网 隐藏边栏 |   抢沙发  41 
文章评分 0 次,平均分 0.0

深度学习 CNN trick 合集

来自 | 知乎   作者| sticky
链接 | https://zhuanlan.zhihu.com/p/137940586
编辑 | 深度学习这件小事
本文仅作学术交流,如有侵权,请联系后台删除。

这两天发现了一篇宝藏paper,2019年CVPR中的一篇 Bag of Tricks for Image Classification with Convolutional Neural Networks。这篇paper主要从3个方面讲述了提高现有baseline(ResNet-50)的有效trick:
1. 在新的硬件上有效训练
2. 在ResNet-50的基础上,对模型进行了一些微量的调整
3. 训练的一些技巧
Bag of Tricks for Image Classification with Convolutional Neural Networks

论文地址:

http://openaccess.thecvf.com/content_CVPR_2019/papers/He_Bag_of_Tricks_for_Image_Classification_with_Convolutional_Neural_Networks_CVPR_2019_paper.pdf

大概回顾这篇文章

   1. 在新的硬件上有效训练

1.1 背景

在ResNet刚提出的时候,为了考虑当时的硬件条件,不得不做很多跟performance相关的trade-offs。但是随着这几年硬件(尤其是GPU)的快速发展,很多与performance相关的trade-offs已经改变。其中包括:
1. 使用更大的batch size。例如从256到1024
2. 使用较低的数值精度。例如从FP32到FP16

1.2 使用更大的batch size

使用更大的batch size会导致减缓训练进度。对于凸问题,收敛速度会随着batch size的增加而降低。也就是说,在相同的epoch下,使用更大的batch size可能会导致验证集accuracy更低。因此使用一些trick来解决这个问题。
Linear scaling learning rate:例如,当我们选择初始学习率为0.1,batch size为256时,那么当我们将batch size增大至b时,就需要将初始学习率增加曾0.1×b/256
Learning rate warmup:例如,选择5个epoch去进行warmup,在这5个epoch中线性地从0开始增加学习率至初始学习率,然后再开始正常decay
Zero  :在residual block中的batch normalization(BN)中:BN首先标准化输入  ,得到  ,然后进行线性变化  ,其中  和  都是可以学习的参数,其值被初始化为1s和0s。而在这里初始化 
No bias decay:为了避免过拟合,对于权重weight和偏差bias,我们通常会使用weight decay。但在这里,仅对weight使用decay,而不对bias使用decay。

1.3 使用更低的数值精度

以前神经网络通常使用32-bit浮点数精度(FP32)来训练。但是现在的新的硬件增强了低精度数据类型的算术逻辑单元。例如Nvidia V100对FP32提供14 TFLOPS,而对FP16提供100 TFLOPS。因此,使用FP16时,总的训练速度加速了2~3倍:
深度学习 CNN trick 合集

Comparison of the training time and validation accuracy for ResNet-50 between the baseline (BS=256 with FP32) and a more hardware efficient setting (BS=1024 with FP16).
深度学习 CNN trick 合集

The breakdown effect for each effective training heuristic on ResNet-50.

   2. 模型调整

深度学习 CNN trick 合集

The architecture of ResNet-50. The convolution kernel size, output channel size and stride size (default is 1) are illustrated, similar for pooling layers.
主要对downsampling block和input steam(上图指出部分)做了一些改动:
1. downsampling做改动主要是由于使用stride=2的1×1 conv会忽略3/4的feature-map。因此,为了使输出的shape保持不变,将path A的前两个conv分别改为stride=1的1×1 conv和stride=2的3×3 conv,即ResNet-C;将path B换成stride=2的2×2 AvgPool和stride=1的1×1 conv,即ResNet-D
2. 而input steam做的改动主要是由于使用7×7 conv的计算cost是3×3的5.4倍。因此将7×7 conv换成3个连续的3×3conv,即ResNet-C
深度学习 CNN trick 合集

Three ResNet tweaks. ResNet-B modifies the downsampling block of Resnet. ResNet-C further modifies the input stem. On top of that, ResNet-D again modifies the downsampling block.
深度学习 CNN trick 合集

Compare ResNet-50 with three model tweaks onmodel size, FLOPs and ImageNet validation accuracy.

   3. 训练技巧

3.1 Cosine Learning Rate Decay

以往学习率衰减的策略一般是"step decay",即每隔一定的epoch,学习率才进行一次指数衰减。而现在,学习率随着epoch的增大不断衰减:
深度学习 CNN trick 合集
深度学习 CNN trick 合集

Visualization of learning rate schedules with warm-up. Top: cosine and step schedules for batch size 1024. Bottom: Top-1 validation accuracy curve with regard to the two schedules.

3.2 Label Smoothing

3.3 Knowledge Distillation

3.4 Mixup Training

在mixup中,每次随机采样两个样本  和  ,然后通过加权线性插值生成新的样本进行训练:
深度学习 CNN trick 合集
其中  为从  分布的得到的随机数。

3.5 Experiment Results

深度学习 CNN trick 合集

The validation accuracies on ImageNet for stacking training refinements one by one. We repeat each refinement on ResNet-50-D for 4 times with different initialization, and report the mean and standard deviation in the table.
<pre style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;color: rgb(0, 0, 0);font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong>完<strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">—</span></strong></span></strong></span></strong></p><section style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;font-family: -apple-system-font, system-ui, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;widows: 1;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="margin-top: 15px;margin-bottom: 25px;max-width: 100%;opacity: 0.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section><p style="margin-bottom: 15px;padding-right: 0em;padding-left: 0em;max-width: 100%;color: rgb(127, 127, 127);font-size: 12px;font-family: sans-serif;line-height: 25.5938px;letter-spacing: 3px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;font-family: 微软雅黑;caret-color: red;box-sizing: border-box !important;overflow-wrap: break-word !important;">为您推荐</span></strong></span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;">MIT校长评中美科技竞赛:胜利不是期盼对手的失利</p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 14px;">GitHub重大更新:在线开发上线,是时候卸载IDE了</span></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 14px;">美国官宣117000名 IT 人失业,真是史无前例!</span><br  /></p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;">数据分析入门常用的23个牛逼Pandas代码</p><p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;font-family: sans-serif;letter-spacing: 0px;opacity: 0.8;line-height: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;">知乎高赞:985计算机视觉毕业后找不到工作怎么办?<br  /></p></section></section></section></section></section></section></section></section>
深度学习 CNN trick 合集

本篇文章来源于: 深度学习这件小事

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写

发表评论

表情 格式 链接 私密 签到
扫一扫二维码分享