目录
CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features
作者在论文中提出了一种新的数据增强的方法——CutMix(论文地址),论文源代码-Pytorch
摘要
区域的丢弃策略(Reginal dropout strategies)能够增强卷积神经网络分类器的性能。
优点: 该策略能够使得模型更有效的关注目标的明显部分,有好的泛化和目标定位能力。
缺点: 利用黑色像素或者随机噪声填充移除区域,这样的操作在训练过程中容易导致信息的缺失和无效性。
解决方法: 提出了CutMix——使用训练集中的图像填补移除区域。
Mixup、Cutout和CutMix三种数据增强方法
作者在论文中对比了三种数据增强的方法:Mixup,Cutout和CutMix在数据集中的性能。通过观察下图可以发现,CutMix在填充了训练集中的其他照片的同时,label也进行了相同比例转换。
CutMix
CutMix最大程度的利用了同一张图像上的两种不同图像信息。具有更好的分类性能和目标定位功能。
算法中涉及到的公式


对应的代码
整体算法:
for i, (input, target) in enumerate(train_loader):
# measure data loading time
data_time.update(time.time() - end)
input = input.cuda()
target = target.cuda()
r = np.random.rand(1)
if args.beta > 0 and r < args.cutmix_prob:
# 1.设定lambda的值,服从beta分布
lam = np.random.beta(args.beta, args.beta)
# 2.找到两个随机样本
rand_index = torch.randperm(input.size()[0]).cuda()
target_a = target
target_b = target[rand_index]
# 3.生成裁剪区域B
bbx1, bby1, bbx2, bby2 = rand_bbox(input.size(), lam)
# 4.将原有的样本A中的B区域,替换成样本B中的B区域
input[:, :, bbx1:bbx2, bby1:bby2] = input[rand_index, :, bbx1:bbx2, bby1:bby2]
# 5.根据裁剪区域坐标框的值调整lamda的值
lam = 1 - ((bbx2 - bbx1) * (bby2 - bby1) / (input.size()[-1] * input.size()[-2]))
# 6.将生成的新的训练样本丢到模型中进行训练
output = model(input)
# 7.按lamda值分配权重
loss = criterion(output, target_a) * lam + criterion(output, target_b) * (1. - lam)
裁剪区域B的坐标值函数:
def rand_bbox(size, lam):
W = size[2]
H = size[3]
# 论文里的公式2:求出B的rw,rh
cut_rat = np.sqrt(1. - lam)
cut_w = np.int(W * cut_rat)
cut_h = np.int(H * cut_rat)
# 论文里的公式2:求出B的rx,ry
cx = np.random.randint(W)
cy = np.random.randint(H)
# 限制坐标区域不超过样本大小
bbx1 = np.clip(cx - cut_w // 2, 0, W)
bby1 = np.clip(cy - cut_h // 2, 0, H)
bbx2 = np.clip(cx + cut_w // 2, 0, W)
bby2 = np.clip(cy + cut_h // 2, 0, H)
# 返回裁剪B区域的坐标值
return bbx1, bby1, bbx2, bby2
讨论
带有CutMix的模型学习到了什么?
保证在一幅图像中从局部视角上识别出两个目标,提高了训练效率。为了验证CutMix确实学习去识别两个目标,作者对CutMix、Cutout和Mixup进行了比较。通过观察下面的实验结果可以发现,CutMix能够精准的定位两个类别目标。
版权声明:本文为weixin_42621901原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。