Skip to content

Instantly share code, notes, and snippets.

@spirosdim
Created April 6, 2022 14:28
Show Gist options
  • Save spirosdim/853b490e7da589888b83732185210577 to your computer and use it in GitHub Desktop.
Save spirosdim/853b490e7da589888b83732185210577 to your computer and use it in GitHub Desktop.
Add augmentations on the Trainer class, Detectron2
class MyTrainer(DefaultTrainer):
@classmethod
def build_train_loader(cls, cfg):
mapper_train = DatasetMapper(cfg,
is_train=True,
augmentations=[ #Apply a sequence of augmentations.
T.RandomFlip(prob=0.5, horizontal=False, vertical=True),
T.RandomFlip(prob=0.5, horizontal=True, vertical=False),
T.RandomRotation(angle=[0, 90, 180, 270], sample_style="choice"),
T.RandomApply(T.RandomBrightness(0.9, 1.1), prob=0.5),
T.RandomApply(T.RandomContrast(0.9, 1.1), prob=0.5),
T.RandomApply(T.RandomSaturation(0.9, 1.1), prob=0.5),
T.RandomApply(T.RandomLighting(0.9), prob=0.5),
]
)
return build_detection_train_loader(cfg, mapper=mapper_train)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment