MCPcopy Create free account
hub / github.com/SwinTransformer/Transformer-SSL / build_transform

Function build_transform

data/build.py:95–180  ·  view source on GitHub ↗
(is_train, config)

Source from the content-addressed store, hash-verified

93
94
95def build_transform(is_train, config):
96 if config.AUG.SSL_AUG:
97 if config.AUG.SSL_AUG_TYPE == 'byol':
98 normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
99
100 transform_1 = transforms.Compose([
101 transforms.RandomResizedCrop(config.DATA.IMG_SIZE, scale=(config.AUG.SSL_AUG_CROP, 1.)),
102 transforms.RandomHorizontalFlip(),
103 transforms.RandomApply([transforms.ColorJitter(0.4, 0.4, 0.2, 0.1)], p=0.8),
104 transforms.RandomGrayscale(p=0.2),
105 transforms.RandomApply([GaussianBlur()], p=1.0),
106 transforms.ToTensor(),
107 normalize,
108 ])
109 transform_2 = transforms.Compose([
110 transforms.RandomResizedCrop(config.DATA.IMG_SIZE, scale=(config.AUG.SSL_AUG_CROP, 1.)),
111 transforms.RandomHorizontalFlip(),
112 transforms.RandomApply([transforms.ColorJitter(0.4, 0.4, 0.2, 0.1)], p=0.8),
113 transforms.RandomGrayscale(p=0.2),
114 transforms.RandomApply([GaussianBlur()], p=0.1),
115 transforms.RandomApply([ImageOps.solarize], p=0.2),
116 transforms.ToTensor(),
117 normalize,
118 ])
119
120 transform = (transform_1, transform_2)
121 return transform
122 else:
123 raise NotImplementedError
124
125 if config.AUG.SSL_LINEAR_AUG:
126 normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
127
128 if is_train:
129 transform = transforms.Compose([
130 transforms.RandomResizedCrop(config.DATA.IMG_SIZE),
131 transforms.RandomHorizontalFlip(),
132 transforms.ToTensor(),
133 normalize,
134 ])
135 else:
136 transform = transforms.Compose([
137 transforms.Resize(config.DATA.IMG_SIZE + 32),
138 transforms.CenterCrop(config.DATA.IMG_SIZE),
139 transforms.ToTensor(),
140 normalize,
141 ])
142 return transform
143
144 resize_im = config.DATA.IMG_SIZE > 32
145 if is_train:
146 # this should always dispatch to transforms_imagenet_train
147 transform = create_transform(
148 input_size=config.DATA.IMG_SIZE,
149 is_training=True,
150 color_jitter=config.AUG.COLOR_JITTER if config.AUG.COLOR_JITTER > 0 else None,
151 auto_augment=config.AUG.AUTO_AUGMENT if config.AUG.AUTO_AUGMENT != 'none' else None,
152 re_prob=config.AUG.REPROB,

Callers 1

build_datasetFunction · 0.85

Calls 1

GaussianBlurClass · 0.85

Tested by

no test coverage detected