(is_train, config)
| 115 | |
| 116 | |
| 117 | def build_transform(is_train, config): |
| 118 | resize_im = config.DATA.IMG_SIZE > 32 |
| 119 | if is_train: |
| 120 | # this should always dispatch to transforms_imagenet_train |
| 121 | |
| 122 | if config.AUG.PRESET is None: |
| 123 | transform = create_transform( |
| 124 | input_size=config.DATA.IMG_SIZE, |
| 125 | is_training=True, |
| 126 | color_jitter=config.AUG.COLOR_JITTER if config.AUG.COLOR_JITTER > 0 else None, |
| 127 | auto_augment=config.AUG.AUTO_AUGMENT if config.AUG.AUTO_AUGMENT != 'none' else None, |
| 128 | re_prob=config.AUG.REPROB, |
| 129 | re_mode=config.AUG.REMODE, |
| 130 | re_count=config.AUG.RECOUNT, |
| 131 | interpolation=config.DATA.INTERPOLATION, |
| 132 | ) |
| 133 | print('=============================== original AUG! ', config.AUG.AUTO_AUGMENT) |
| 134 | if not resize_im: |
| 135 | # replace RandomResizedCropAndInterpolation with |
| 136 | # RandomCrop |
| 137 | transform.transforms[0] = transforms.RandomCrop(config.DATA.IMG_SIZE, padding=4) |
| 138 | |
| 139 | elif config.AUG.PRESET.strip() == 'raug15': |
| 140 | from train.randaug import RandAugPolicy |
| 141 | transform = transforms.Compose([ |
| 142 | transforms.RandomResizedCrop(config.DATA.IMG_SIZE), |
| 143 | transforms.RandomHorizontalFlip(), |
| 144 | RandAugPolicy(magnitude=15), |
| 145 | transforms.ToTensor(), |
| 146 | transforms.Normalize(IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD), |
| 147 | ]) |
| 148 | print('---------------------- RAND AUG 15 distortion!') |
| 149 | |
| 150 | elif config.AUG.PRESET.strip() == 'weak': |
| 151 | transform = transforms.Compose([ |
| 152 | transforms.RandomResizedCrop(config.DATA.IMG_SIZE), |
| 153 | transforms.RandomHorizontalFlip(), |
| 154 | transforms.ToTensor(), |
| 155 | transforms.Normalize(IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD), |
| 156 | ]) |
| 157 | elif config.AUG.PRESET.strip() == 'none': |
| 158 | transform = transforms.Compose([ |
| 159 | transforms.Resize(config.DATA.IMG_SIZE, interpolation=_pil_interp(config.DATA.INTERPOLATION)), |
| 160 | transforms.CenterCrop(config.DATA.IMG_SIZE), |
| 161 | transforms.ToTensor(), |
| 162 | transforms.Normalize(IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD), |
| 163 | ]) |
| 164 | else: |
| 165 | raise ValueError('???' + config.AUG.PRESET) |
| 166 | print(transform) |
| 167 | return transform |
| 168 | |
| 169 | t = [] |
| 170 | if resize_im: |
| 171 | if config.TEST.CROP: |
| 172 | size = int((256 / 224) * config.DATA.TEST_SIZE) |
| 173 | t.append(transforms.Resize(size, interpolation=_pil_interp(config.DATA.INTERPOLATION)), |
| 174 | # to maintain same ratio w.r.t. 224 images |
no test coverage detected