MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / build_transform

Function build_transform

examples/pytorch/vit/ViT-quantization/data.py:126–163  ·  view source on GitHub ↗
(is_train, config)

Source from the content-addressed store, hash-verified

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

Callers 1

build_datasetFunction · 0.85

Calls 1

_pil_interpFunction · 0.85

Tested by

no test coverage detected