MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / DataAugmentationDINO

Class DataAugmentationDINO

main_selfpatch.py:487–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485 self.patch_center = self.patch_center * self.center_momentum + batch_center * (1 - self.center_momentum)
486
487class DataAugmentationDINO(object):
488 def __init__(self, global_crops_scale, local_crops_scale, local_crops_number):
489 flip_and_color_jitter = transforms.Compose([
490 transforms.RandomHorizontalFlip(p=0.5),
491 transforms.RandomApply(
492 [transforms.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1)],
493 p=0.8
494 ),
495 transforms.RandomGrayscale(p=0.2),
496 ])
497 normalize = transforms.Compose([
498 transforms.ToTensor(),
499 transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
500 ])
501
502 # first global crop
503 self.global_transfo1 = transforms.Compose([
504 transforms.RandomResizedCrop(224, scale=global_crops_scale, interpolation=Image.BICUBIC),
505 flip_and_color_jitter,
506 utils.GaussianBlur(1.0),
507 normalize,
508 ])
509 # second global crop
510 self.global_transfo2 = transforms.Compose([
511 transforms.RandomResizedCrop(224, scale=global_crops_scale, interpolation=Image.BICUBIC),
512 flip_and_color_jitter,
513 utils.GaussianBlur(0.1),
514 utils.Solarization(0.2),
515 normalize,
516 ])
517 # transformation for the local small crops
518 self.local_crops_number = local_crops_number
519 self.local_transfo = transforms.Compose([
520 transforms.RandomResizedCrop(96, scale=local_crops_scale, interpolation=Image.BICUBIC),
521 flip_and_color_jitter,
522 utils.GaussianBlur(p=0.5),
523 normalize,
524 ])
525
526 def __call__(self, image):
527 crops = []
528 crops.append(self.global_transfo1(image))
529 crops.append(self.global_transfo2(image))
530 for _ in range(self.local_crops_number):
531 crops.append(self.local_transfo(image))
532 return crops
533
534
535if __name__ == '__main__':

Callers 1

train_dinoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected