SSD中的数据增强细节

在SSD中数据增强起着至关重要的作用,从原文的实验结果可以看出,数据增强可以为提高8.8%mAP。如下表所示:

数据增强对于提高小目标的检测精度尤为重要,因为它在分类器可以看到更多对象结构的图像中创建放大图像。数据增强还可用于处理包含被遮挡对象的图像,通过将裁剪的图像包括在训练数据中,在训练数据中只能看到对象的一部分。在SSD中数据增强包括如下步骤:

  • 光度畸变(Photometric Distortions)
    • 随机亮度(Random Brightness)
    • 随机对比度,色调和饱和度(Random Contrast, Hue, Saturation)
    • 随机光噪声(RandomLightingNoise)
  • 几何畸变(Geometric Distortions)
    • 随机扩展(RandomExpand)
    • 随机裁剪(RandomCrop)
    • 随机翻转(RandomMirror)

Photometric Distortions

Random Brightness

这个是从$[-\delta,\delta]$中随机选择一个值添加到图像的所有像素中,默认值设置为32。

1
2
3
4
5
def __call__(self, image, boxes=None, labels=None):
if random.randint(2):
delta = random.uniform(-self.delta, self.delta)
image += delta
return image, boxes, labels

Random Contrast, Hue, Saturation

对于Contrast, Hue, Saturation的应用,有两种选择:Contrast + Hue + Saturation和Hue + Saturation + Contrast。每种选择概率为0.5.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
self.pd = [
RandomContrast(),
ConvertColor(transform='HSV'),
RandomSaturation(),
RandomHue(),
ConvertColor(current='HSV', transform='BGR'),
RandomContrast()
]

im, boxes, labels = self.rand_brightness(im, boxes, labels)
if random.randint(2):
distort = Compose(self.pd[:-1])
else:
distort = Compose(self.pd[1:])
im, boxes, labels = distort(im, boxes, labels)

需要注意的是,Contrast应用于RGB空间,而Hue, Saturation则是应用HSV空间。因此,在应用每个操作之前,必须执行适当的颜色空间转换。应用随机contrast之后,随机hue and 随机saturation操作与随机Brightness类似。随机saturation如下:

1
2
3
4
5
def __call__(self, image, boxes=None, labels=None):
if random.randint(2):
image[:, :, 1] *= random.uniform(self.lower, self.upper)

return image, boxes, labels

RandomLightingNoise

最后一个 光度畸变是随机光噪声,这种操作主要是颜色通道的随机交换。三个通道有六种jiaohua

1
2
3
self.perms = ((0, 1, 2), (0, 2, 1),
(1, 0, 2), (1, 2, 0),
(2, 0, 1), (2, 1, 0))

随机交换后如下:

Geometric Distortions

RandomExpand

随机扩展的发生概率为0.5,随机扩展的步骤如下

RandomCrop

这一步主要是在上一步随机扩展的基础上,对目标进行随机裁剪,有利于缓解目标遮挡问题。随机生成裁剪框,如果框与目标的iou不满足要求则删除,如果iou满足要求,而目标中心点不包含在随机裁剪框也删除。

部分例子如下:

其中,红色表示ground truth,绿色表示随机裁剪的框。

RandomMirror

随机裁剪主要是镜像翻转。很简单。

最后,对经过数据增强的图像resize到(300,300),然后减均值。
代码参考: https://github.com/amdegroot/ssd.pytorch/