| 29 | |
| 30 | |
| 31 | def build_transform(is_train, args): |
| 32 | mean = IMAGENET_DEFAULT_MEAN |
| 33 | std = IMAGENET_DEFAULT_STD |
| 34 | # train transform |
| 35 | if is_train: |
| 36 | # this should always dispatch to transforms_imagenet_train |
| 37 | transform = create_transform( |
| 38 | input_size=args.input_size, |
| 39 | is_training=True, |
| 40 | color_jitter=args.color_jitter, |
| 41 | auto_augment=args.aa, |
| 42 | interpolation='bicubic', |
| 43 | re_prob=args.reprob, |
| 44 | re_mode=args.remode, |
| 45 | re_count=args.recount, |
| 46 | mean=mean, |
| 47 | std=std, |
| 48 | ) |
| 49 | return transform |
| 50 | |
| 51 | # eval transform |
| 52 | t = [] |
| 53 | if args.input_size <= 224: |
| 54 | crop_pct = 224 / 256 |
| 55 | else: |
| 56 | crop_pct = 1.0 |
| 57 | size = int(args.input_size / crop_pct) |
| 58 | t.append( |
| 59 | transforms.Resize(size, interpolation=PIL.Image.BICUBIC), # to maintain same ratio w.r.t. 224 images |
| 60 | ) |
| 61 | t.append(transforms.CenterCrop(args.input_size)) |
| 62 | |
| 63 | t.append(transforms.ToTensor()) |
| 64 | t.append(transforms.Normalize(mean, std)) |
| 65 | return transforms.Compose(t) |