Bag of Tricks for Image Classification with Convolutional Neural Networks
这篇文章来自李沐大神团队,使用各种CNN tricks,将原始的resnet在imagenet上提升了四个点。记录一下,可以用到自己的网络上。如果图片显示不了,点击链接观看
baseline
model: resnet50
transform部分使用pytorch的torchvision接口
train transform:
- transforms.RandomResizedCrop(224)
- transforms.RandomHorizontalFlip(0.5)
- transforms.ColorJitter(brightness=0.4, ntrast=0.4, saturation=0.4)
- PCA noise ——— normal distribution N(0, 0.1)
- transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
val transform:
- transforms.Resize(256)
- transforms.CenterCrop(224)
parameters initialized:
conv and lr: Xavier uniformly [-a, a], a = \(\sqrt{6 /\left(d_{i n}+d_{o u t}\right)}\),\(d_{in}\) and \(d_{out}\) are the input and output channel sizes
bn: \(\gamma\) = 1, \(\beta\) = 0
optimizer:NAG
epoch:120
lr: 0.1, divided by 10 every 30 epochs
batchsize: 256
Tricks
Efficient Training
Large batch training:
- 大的batch减小了梯度的噪声,可以适当放大学习率。论文中调整为0.1 X b/256.
- 网络初始的时候,参数离目标很远,较大的学习率会发生数值不稳定,应使用较小的学习线性递增到设置的lr,比如m个batch(5个epoch),初始学习率为n,第i个batch的学习率为i*n/m.
- 把每一个resnet block最后一个bn层的\(\gamma\)设置为0
- 只有weight decay,没有bias decay
Low precision training:
将FP32换成FP16可以不丧失精度使训练更快,技巧是存储所有参数和激活使用FP16来计算梯度。同时,FP32中的所有参数都有一个副本,用于参数更新。
result:
efficient是bs1024 + FP16的结果,更快更好。

以下是加上五个变量的实验结果,加入LR warmup和Zero \(\gamma\)效果明显,另外两个作用不是很大。

Model Tweaks
文章对原始的resnet block的下采样层进行了改动,共有三个版本。
以下是原始的resnet结构图:

三个版本对downsample的改动如下:

Resnet-B: 原始的downsample是在conv1x1进行stride为2的下采样,这样会损失3/4的信息,resnet-B则不会。
Resnet-C: 这个调整最早来自于Inception-v2,引入1x1可以减小计算量和参数,作者将前两层的输出通道变为32来达到减小计算量的效果。
Resnet-D: resnet-b的pathB分支还是会损失3/4的信息,通过引入avgpool来改善这种影响。
result:

略微提高计算量,Resnet-D版本差不多提高一个点。
Training Refinements
Cosine Learning Rate Decay:
将学习率变为余弦函数的曲线,公式如下:
\[
\eta_{t}=\frac{1}{2}\left(1+\cos \left(\frac{t \pi}{T}\right)\right) \eta
\]
\(n\)是初始学习率,t是第t个batch,T是总batch数,与stepLR的曲线如下所示,开始的直线是LR warmup,可以看到余弦退火精度要高一些:

label smooth:原始的label是one-hot标签,过于苛刻,label smooth将标签进行软化,其他类别也需要有低的概率,变为如下所示的公式,一般\(\varepsilon\)的取值为0.1.
\[
q_{i}=\left\{\begin{array}{ll}{1-\varepsilon} & {\text { if } i=y} \\ {\varepsilon /(K-1)} & {\text { otherwise }}\end{array}\right.
\]
Knowledge Distillation:知识蒸馏是使用一个老师模型来训练当前模型,帮助当前模型训练的更好,老师模型一般使用精确度更好的预训练模型,文章是使用Resnet152作为老师模型来训练resnet50,通过约束当前模型的softmax输出与老师模型保持一致来提高当前模型。所以损失函数变成下面的形式:
\[
\ell(p, \operatorname{softmax}(z))+T^{2} \ell(\operatorname{softmax}(r / T), \operatorname{softmax}(z / T))
\]
Mixup Training:这是一种新式的数据增强策略,随机采样两个样本(可不同类别),进行权重插值(x是图像,y是标签),公式如下:
\[
\begin{aligned} \hat{x} &=\lambda x_{i}+(1-\lambda) x_{j} \\ \hat{y} &=\lambda y_{i}+(1-\lambda) y_{j} \end{aligned}
\]
\(\lambda\)的范围是0到1,一般采样beta分布。
result:

可以看到cosine decay,label smooth和mixup还是很有用的,对模型提高不少,但Knowledge Distillation不同模型效果不同,还得进行实验。
参考
Bag of Tricks for Image Classification with Convolutional Neural Networks的更多相关文章
- Bag of Tricks for Image Classification with Convolutional Neural Networks笔记
以下内容摘自<Bag of Tricks for Image Classification with Convolutional Neural Networks>. 1 高效训练 1.1 ...
- 训练技巧详解【含有部分代码】Bag of Tricks for Image Classification with Convolutional Neural Networks
训练技巧详解[含有部分代码]Bag of Tricks for Image Classification with Convolutional Neural Networks 置顶 2018-12-1 ...
- Bag of Tricks for Image Classification with Convolutional Neural Networks论文笔记
一.高效的训练 1.Large-batch training 使用大的batch size可能会减小训练过程(收敛的慢?我之前训练的时候挺喜欢用较大的batch size),即在相同的迭代次数 ...
- Notes on Large-scale Video Classification with Convolutional Neural Networks
Use bigger datasets for CNN in hope of better performance. A new data set for sports video classific ...
- Deep learning_CNN_Review:A Survey of the Recent Architectures of Deep Convolutional Neural Networks——2019
CNN综述文章 的翻译 [2019 CVPR] A Survey of the Recent Architectures of Deep Convolutional Neural Networks 翻 ...
- 《ImageNet Classification with Deep Convolutional Neural Networks》 剖析
<ImageNet Classification with Deep Convolutional Neural Networks> 剖析 CNN 领域的经典之作, 作者训练了一个面向数量为 ...
- 读convolutional Neural Networks Applied to House Numbers Digit Classification 的收获。
本文以下内容来自读论文以后认为有价值的地方,论文来自:convolutional Neural Networks Applied to House Numbers Digit Classificati ...
- [转]XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks
感谢: XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks XNOR-Net ImageNet Cl ...
- ImageNet Classification with Deep Convolutional Neural Networks(译文)转载
ImageNet Classification with Deep Convolutional Neural Networks Alex Krizhevsky, Ilya Sutskever, Geo ...
随机推荐
- canvas应用
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- ceph安装笔记
配置源 ceph版本为luminous [root@ceph-node1 ~]# yum install -y https://dl.fedoraproject.org/pub/epel/epel-r ...
- 关于eclipse中启动tomcat提示启动超时问题
tomcat启动超时问题百分之九十时因为项目中mapper.xml(持久层接口的映射文件编写错误) 一般来讲文件中出错点是[忘写参数类型parameterType] [多逗号少逗号] [标签残缺 ...
- 【STM32-V7】STM32H743XIH6开发板,丰富软件资源,强劲硬件配置,大量软件解决方案持续更新中(2019-12-12)
说明: 争取做更多的实战性应用,分享更多的嵌入式技术,希望能在实际项目中帮到大家. (1)V7将大力加强对初学者的支持力度,已经更新至63章,下载链接,后37章和一批视频教程将加紧制作. (2)事隔五 ...
- jQuery-文件上传问题解决
后端要求文件上传需传参数为二进制流,用form-data方式传递,如下图所示: 为了满足该输入参数要求,上传代码如下: <input type="file" id=" ...
- SpringBoot2.0 基础案例(15):配置MongoDB数据库,实现增删改查逻辑
本文源码:GitHub·点这里 || GitEE·点这里 一.NoSQL简介 1.NoSQL 概念 NoSQL( Not Only SQL ),意即"不仅仅是SQL".对不同于传统 ...
- Python中Collections模块的Counter容器类使用教程
1.collections模块 collections模块自Python 2.4版本开始被引入,包含了dict.set.list.tuple以外的一些特殊的容器类型,分别是: OrderedDict类 ...
- Grafana+Prometheus 监控 MySQL
转自:Grafana+Prometheus 监控 MySQL 架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.lin ...
- 前vue.js+elementui,后koa2,nodejs搭建网站
1,安装 nodejs,npm 2,使用 npm 安装 vue,vue-cli 3,使用脚手架搭建项目,添加依赖:axios,vue-router,elementui,vuex 等 4,建立 rout ...
- UIView创建xib
这里有两种类都可以实现,但是推荐用Empty类来创建 (Empty): 参考链接:https://blog.csdn.net/wtdask/article/details/76439295 https ...