Detectron2: DatasetMapper - How many augmented images are created?

Hi All

In detectron2, say I create a trainer based on the DefaultTrainer with a mapper based on DatasetMapper (code below). With how many images is my dataset augmented? Does the mapper create an augmented image for each of the transforms, e.g. for n images and T transforms my final training set has n(T+1) images? Or is there somewhere a parameter to tune that specifies how many augmented images are created for each input image, with the augmentations randomly sampled from the specified transforms?

Thanks!

from detectron2.engine import DefaultTrainer
from detectron2.data import DatasetMapper, build_detection_train_loader
from detectron2.data import transforms as T

def build_sem_seg_train_aug(cfg):

    augs = [T.ResizeShortestEdge(
            cfg.INPUT.MIN_SIZE_TRAIN, cfg.INPUT.MAX_SIZE_TRAIN, cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING
        ),
            T.RandomBrightness(0.5, 2),
            T.RandomContrast(0.5, 2),
            T.RandomSaturation(0.5, 2),
            T.RandomFlip(prob=0.5, horizontal=True, vertical=False),
            T.RandomFlip(prob=0.5, horizontal=False, vertical=True)]
    return augs

class Trainer(DefaultTrainer):
    @classmethod
    def build_train_loader(cls, cfg):
        mapper = DatasetMapper(cfg, is_train=True, augmentations=build_sem_seg_train_aug(cfg))
        return build_detection_train_loader(cfg, mapper=mapper)

The remainder of the model follows the Colab demo: Google Colab

1 Like

Hi @oryx ! did you get an answer? I have the same question.

Hi @oryx @Luis-PP , I have the same question. Did any of you get the answer? Thanks.