(is_train, config)
| 285 | |
| 286 | |
| 287 | def build_transform(is_train, config): |
| 288 | resize_im = config.DATA.IMG_SIZE > 32 |
| 289 | if is_train: |
| 290 | # this should always dispatch to transforms_imagenet_train |
| 291 | transform = create_transform( |
| 292 | input_size=config.DATA.IMG_SIZE, |
| 293 | is_training=True, |
| 294 | color_jitter=config.AUG.COLOR_JITTER |
| 295 | if config.AUG.COLOR_JITTER > 0 else None, |
| 296 | auto_augment=config.AUG.AUTO_AUGMENT |
| 297 | if config.AUG.AUTO_AUGMENT != 'none' else None, |
| 298 | re_prob=config.AUG.REPROB, |
| 299 | re_mode=config.AUG.REMODE, |
| 300 | re_count=config.AUG.RECOUNT, |
| 301 | interpolation=config.DATA.INTERPOLATION, |
| 302 | ) |
| 303 | if not resize_im: |
| 304 | # replace RandomResizedCropAndInterpolation with |
| 305 | # RandomCrop |
| 306 | transform.transforms[0] = transforms.RandomCrop(config.DATA.IMG_SIZE, padding=4) |
| 307 | |
| 308 | return transform |
| 309 | |
| 310 | t = [] |
| 311 | if resize_im: |
| 312 | if config.TEST.CROP: |
| 313 | size = int(1.0 * config.DATA.IMG_SIZE) |
| 314 | t.append( |
| 315 | transforms.Resize(size, interpolation=_pil_interp(config.DATA.INTERPOLATION)), |
| 316 | # to maintain same ratio w.r.t. 224 images |
| 317 | ) |
| 318 | t.append(transforms.CenterCrop(config.DATA.IMG_SIZE)) |
| 319 | elif config.AUG.RANDOM_RESIZED_CROP: |
| 320 | t.append( |
| 321 | transforms.RandomResizedCrop( |
| 322 | (config.DATA.IMG_SIZE, config.DATA.IMG_SIZE), |
| 323 | interpolation=_pil_interp(config.DATA.INTERPOLATION))) |
| 324 | else: |
| 325 | t.append( |
| 326 | transforms.Resize( |
| 327 | (config.DATA.IMG_SIZE, config.DATA.IMG_SIZE), |
| 328 | interpolation=_pil_interp(config.DATA.INTERPOLATION))) |
| 329 | t.append(transforms.ToTensor()) |
| 330 | t.append(transforms.Normalize(config.AUG.MEAN, config.AUG.STD)) |
| 331 | |
| 332 | return transforms.Compose(t) |
no test coverage detected