This is a data augmentation for object detection, using bounding boxes.
There were no-objects images during training when using Mosaic[1] because of image center position of objects. So we implemented a augmentation pasting bboxes in the empty space of a training image(BboxCutMix).
There is already a method using bounding boxes like copy-paste[2]. But BboxCutMix has two differences from copy-paste.
- Make hard to find a bounding box when training using offset margin.
- Have full edge information(no-occluded objects).
The detailed procedure of BboxCutMix is shown in the image below. The offset margin was added to prevent easy finding out a bounding box. And we applied data augmentations for each cropped objects. Finally, cropped objects are inserted into the training image.
- run the command
$ pip install -r requirements.txt
- initialize variables and add the code in your Dataset class like below.
from bbox_cutmix import *
from torch.utils.data import Dataset
class customDataset(Dataset):
...
self.ims = ... # training images (list | (#_img, H, W, C))
self.im_files = ... # path of traning images (list)
self.img_size = ... # traning images size (int)
self.indices = ... # range(0, #_img)
self.labels = ... # labels of traning data (list | (#_img, #_obj, class, x, y, w, h))
…
# load image
if bbox_cutmix:
# h, w are height and width of img
img, labels = bbox_cutmix(self, img, labels, h, w)
…
- Zhiwei et al, AMRNet: Chips Augmentation in Aerial Images Object Detection, https://arxiv.org/abs/2009.07168
- Golnaz et al, Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation, https://arxiv.org/abs/2012.07177