MCPcopy
hub / github.com/microsoft/Swin-Transformer / build_transform

Function build_transform

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

Source from the content-addressed store, hash-verified

123
124
125def build_transform(is_train, config):
126 resize_im = config.DATA.IMG_SIZE > 32
127 if is_train:
128 # this should always dispatch to transforms_imagenet_train
129 transform = create_transform(
130 input_size=config.DATA.IMG_SIZE,
131 is_training=True,
132 color_jitter=config.AUG.COLOR_JITTER if config.AUG.COLOR_JITTER > 0 else None,
133 auto_augment=config.AUG.AUTO_AUGMENT if config.AUG.AUTO_AUGMENT != 'none' else None,
134 re_prob=config.AUG.REPROB,
135 re_mode=config.AUG.REMODE,
136 re_count=config.AUG.RECOUNT,
137 interpolation=config.DATA.INTERPOLATION,
138 )
139 if not resize_im:
140 # replace RandomResizedCropAndInterpolation with
141 # RandomCrop
142 transform.transforms[0] = transforms.RandomCrop(config.DATA.IMG_SIZE, padding=4)
143 return transform
144
145 t = []
146 if resize_im:
147 if config.TEST.CROP:
148 size = int((256 / 224) * config.DATA.IMG_SIZE)
149 t.append(
150 transforms.Resize(size, interpolation=_pil_interp(config.DATA.INTERPOLATION)),
151 # to maintain same ratio w.r.t. 224 images
152 )
153 t.append(transforms.CenterCrop(config.DATA.IMG_SIZE))
154 else:
155 t.append(
156 transforms.Resize((config.DATA.IMG_SIZE, config.DATA.IMG_SIZE),
157 interpolation=_pil_interp(config.DATA.INTERPOLATION))
158 )
159
160 t.append(transforms.ToTensor())
161 t.append(transforms.Normalize(IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD))
162 return transforms.Compose(t)

Callers 1

build_datasetFunction · 0.70

Calls 1

_pil_interpFunction · 0.85

Tested by

no test coverage detected