【GridMask】《GridMask Data Augmentation》
创始人
2024-01-29 17:07:51

在这里插入图片描述

arXiv-2020


文章目录

  • 1 Background and Motivation
  • 2 Related Work
  • 3 Advantages / Contributions
  • 4 GridMask
  • 5 Experiments
    • 5.1 Image Classification
    • 5.2 Object Detection on COCO Dataset
    • 5.3 Semantic Segmentation on Cityscapes
    • 5.4 Expand Grid as Regularization
  • 6 Conclusion(own)


1 Background and Motivation

数据增广方法可以有效的缓解模型的过拟合

现有的数据增广方法可以大致分成如下3类

  • spatial transformation(random scale, crop, flip and random rotation)
  • color distortion( brightness, hue)
  • information dropping(random erasing, cutout,HaS)

好的 information dropping 数据增广方法要 achieve reasonable balance between deletion and reserving of regional information on the images

删太多,把数据变成了噪声

删太少,目标没啥变化,失去了增广的意义

在这里插入图片描述
本文,作者提出GridMask,deletes uniformly distributed areas and finally forms a grid shape,在多个任务的公开数据集上效果均有提升
在这里插入图片描述

2 Related Work

  • spatial transformation(random scale, crop, flip and random rotation)
  • color distortion( brightness, hue)
  • information dropping(random erasing, cutout,HaS)

3 Advantages / Contributions

提出 GridMask structured data augmentation 方法,在公开的分类、目标检测、分割的benchmark 上比 baseline 好

4 GridMask

在这里插入图片描述
作用形式
x~=x×M\widetilde{x}= x \times Mx=x×M

其中 x∈RH×W×Cx \in \mathbb{R}^{H \times W \times C}x∈RH×W×C 为 输入图像,x~∈RH×W×C\widetilde{x} \in \mathbb{R}^{H \times W \times C}x∈RH×W×C 为增广后的图像,M∈{0,1}H×WM \in \{0,1\}^{H \times W}M∈{0,1}H×W 为 binary mask that stores pixels to be removed,0 的话表示挡住,1 的话表示保留

形成 MMM 的话有 4 个超参数 (r,d,δx,δy)(r, d, \delta_x, \delta_y)(r,d,δx​,δy​)

在这里插入图片描述
1)Choice of rrr

rrr is the ratio of the shorter gray edge in a unit,determines the keep ratio of an input image,值介于 0~1 之间

the keep ratio kkk of a given mask MMM as

k=sum(M)H×Wk = \frac{sum(M)}{H \times W}k=H×Wsum(M)​

rrr 和 kkk 的关系是

k=1−(1−r)2=2r−r2k = 1-(1-r)^2 = 2r-r^2k=1−(1−r)2=2r−r2

rrr 的值小于1,rrr 和 kkk 正相关

kkk 越大,灰色区域越多,遮挡越少
kkk 越小,黑色区域越多,遮挡越多

2)Choice of ddd

ddd is the length of one unit

一个 unit 内(橙色虚线框),灰色区域的长度为 l=r×dl = r \times dl=r×d

d=random(dmin,dmax)d = random(d_{min}, d_{max})d=random(dmin​,dmax​)

在这里插入图片描述
这么画歧义更合适

3)Choice of δx\delta_xδx​ and δy\delta_yδy​

δx\delta_xδx​ and δy\delta_yδy​ are the distances between the first intact unit and boundary of the image. can shift the mask

δx(δy)=random(0,d−1)\delta_x(\delta_y) = random(0, d-1)δx​(δy​)=random(0,d−1)

4)Statistics of Unsuccessful Cases
在这里插入图片描述
99 percent of an object is removed or reserved, we call it a failure case

GridMask has lower chance to yield failure cases than Cutout and HaS

5)The Scheme to Use GridMask

increase the probability of GridMask linearly with the training epochs until an upper bound P is achieved.

中间的概率用 ppp 表示,后续实验中有涉及到

5 Experiments

Datasets

  • ImageNet
  • COCO
  • Cityscapes

5.1 Image Classification

1)ImageNet
在这里插入图片描述
比 Cutout 和 HaS 更好,It is because we handle the aforementioned failure cases better

Benefit to CNN
在这里插入图片描述
focus on large important regions

2)CIFAR10
在这里插入图片描述
Combined with AutoAugment, we achieve SOTA result on these models.

3)Ablation Study

(1)Hyperparameter rrr
在这里插入图片描述

r 越大,mask 1 越多,遮挡的越少,说明数据比较复杂

r 越小,mask 1 越少,遮挡的越多,说明数据比较简单

we should keep more information on complex datasets to avoid under-fitting, and delete more on simple datasets to reduce over-fitting

(2)Hyperparameter ddd
在这里插入图片描述

the diversity of d can increase robustness of the network

(3)Variations of GridMask

reversed GridMask:keep what we drop in GridMask, and drop what we keep in GridMask

在这里插入图片描述
效果不错,也印证了 GridMask 有很好的 balance between deletion and reserving

random GridMask:drop a block in every unit with a certain probability of pup_upu​.

在这里插入图片描述

pup_upu​ 越大,越贴近原始 GridMask

效果不行

5.2 Object Detection on COCO Dataset

在这里插入图片描述
不加 GridMask,training epochs 越多,过拟合越严重,加了以后,训练久一点, 精度还有上升空间

5.3 Semantic Segmentation on Cityscapes

在这里插入图片描述

5.4 Expand Grid as Regularization

联合 GridMask 和 Mixup,ImageNet 上 SOTA在这里插入图片描述

6 Conclusion(own)

GridMask Data Augmentation
在这里插入图片描述


代码实现,考虑了旋转增广,所以 mask 生成的时候是在以原图对角线为边长的情况下生成的,最后取原图区域
https://github.com/dvlab-research/GridMask/blob/master/imagenet_grid/utils/grid.py

在这里插入图片描述

import torch
import numpy as np
import math
import PIL.Image as Image
import torchvision.transforms as T
import matplotlib.pyplot as pltclass Grid(object):def __init__(self, d1=96, d2=224, rotate=1, ratio=0.5, mode=1, prob=1.):self.d1 = d1self.d2 = d2self.rotate = rotateself.ratio = ratio # rself.mode = mode # reversed?self.st_prob = self.prob = prob # pdef set_prob(self, epoch, max_epoch):self.prob = self.st_prob * min(1, epoch / max_epoch)def forward(self, img):if np.random.rand() > self.prob:return imgh = img.size(1)w = img.size(2)# 1.5 * h, 1.5 * w works fine with the squared images# But with rectangular input, the mask might not be able to recover back to the input image shape# A square mask with edge length equal to the diagnoal of the input image # will be able to cover all the image spot after the rotation. This is also the minimum square.hh = math.ceil((math.sqrt(h * h + w * w)))d = np.random.randint(self.d1, self.d2)# d = self.d# maybe use ceil? but i guess no big differenceself.l = math.ceil(d * self.ratio)mask = np.ones((hh, hh), np.float32)st_h = np.random.randint(d)  # delta yst_w = np.random.randint(d)  # delta xfor i in range(-1, hh // d + 1):s = d * i + st_ht = s + self.ls = max(min(s, hh), 0)t = max(min(t, hh), 0)mask[s:t, :] *= 0for i in range(-1, hh // d + 1):s = d * i + st_wt = s + self.ls = max(min(s, hh), 0)t = max(min(t, hh), 0)mask[:, s:t] *= 0r = np.random.randint(self.rotate)mask = Image.fromarray(np.uint8(mask))mask = mask.rotate(r)mask = np.asarray(mask)mask = mask[(hh - h) // 2:(hh - h) // 2 + h, (hh - w) // 2:(hh - w) // 2 + w] # 这里结合原理图方便看懂一些mask = torch.from_numpy(mask).float().cuda()if self.mode == 1:mask = 1 - maskmask = mask.expand_as(img)img = img.cuda() * maskreturn imgif __name__ == "__main__":image = Image.open("2.jpg").convert("RGB")tr = T.Compose([T.Resize((224,224)),T.ToTensor()])x = tr(image)gridmask_image = Grid(d1=64, d2=96).forward(x)print(gridmask_image.shape)# print(gridmask_image.shape())fig, axs = plt.subplots(1,2)to_plot = lambda x: x.permute(1,2,0).cpu().numpy()axs[0].imshow(to_plot(x))axs[1].imshow(to_plot(gridmask_image))plt.show()

在这里插入图片描述

相关内容

热门资讯

埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
平遥古城在哪 平遥古城基本现状 城垣恢宏,雉堞连云市井街巷,店肆林立四合院落,青砖瓦屋这里是平遥古城历经千年沧桑而古朴宛然,风姿依旧...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...
脚上的穴位图 脚面经络图对应的... 人体穴位作用图解大全更清晰直观的标注了各个人体穴位的作用,包括头部穴位图、胸部穴位图、背部穴位图、胳...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
平遥古城在哪 平遥古城基本现状 城垣恢宏,雉堞连云市井街巷,店肆林立四合院落,青砖瓦屋这里是平遥古城历经千年沧桑而古朴宛然,风姿依旧...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...