(is_train, randaug=True, input_size=224, interpolation='bicubic', std_mode='IMAGENET_INCEPTION')
| 419 | |
| 420 | |
| 421 | def build_transform(is_train, randaug=True, input_size=224, interpolation='bicubic', std_mode='IMAGENET_INCEPTION'): |
| 422 | if std_mode == 'IMAGENET_INCEPTION': |
| 423 | mean = IMAGENET_INCEPTION_MEAN |
| 424 | std = IMAGENET_INCEPTION_STD |
| 425 | elif std_mode == 'OPENAI_CLIP': |
| 426 | mean = OPENAI_CLIP_MEAN |
| 427 | std = OPENAI_CLIP_STD |
| 428 | else: |
| 429 | raise NotImplementedError |
| 430 | |
| 431 | if is_train: |
| 432 | crop_scale = float(os.environ.get('TRAIN_CROP_SCALE', 0.9999)) |
| 433 | t = [ |
| 434 | RandomResizedCropAndInterpolation( |
| 435 | input_size, scale=(crop_scale, 1.0), interpolation='bicubic'), |
| 436 | # transforms.RandomHorizontalFlip(), |
| 437 | ] |
| 438 | if randaug and os.environ.get('TRAIN_DO_AUG', 'False') == 'True': |
| 439 | print(f'@@@@@ Do random aug during training', flush=True) |
| 440 | t.append( |
| 441 | RandomAugment( |
| 442 | 2, 7, isPIL=True, |
| 443 | augs=[ |
| 444 | 'Identity', 'AutoContrast', 'Equalize', 'Brightness', 'Sharpness', |
| 445 | 'ShearX', 'ShearY', 'TranslateX', 'TranslateY', 'Rotate', |
| 446 | ])) |
| 447 | else: |
| 448 | print(f'@@@@@ Skip random aug during training', flush=True) |
| 449 | t += [ |
| 450 | transforms.ToTensor(), |
| 451 | transforms.Normalize(mean=mean, std=std), |
| 452 | ] |
| 453 | t = transforms.Compose(t) |
| 454 | else: |
| 455 | t = transforms.Compose([ |
| 456 | transforms.Resize((input_size, input_size), |
| 457 | interpolation=transforms.InterpolationMode.BICUBIC), |
| 458 | transforms.ToTensor(), |
| 459 | transforms.Normalize(mean=mean, std=std) |
| 460 | ]) |
| 461 | |
| 462 | return t |
| 463 | |
| 464 | |
| 465 | def img2b64(img_path): |
no test coverage detected