(is_train, args)
| 100 | |
| 101 | |
| 102 | def build_transform(is_train, args): |
| 103 | resize_im = args.input_size > 32 |
| 104 | if is_train: |
| 105 | # this should always dispatch to transforms_imagenet_train |
| 106 | transform = create_transform( |
| 107 | input_size=args.input_size, |
| 108 | is_training=True, |
| 109 | color_jitter=args.color_jitter, |
| 110 | auto_augment=args.aa, |
| 111 | interpolation=args.train_interpolation, |
| 112 | re_prob=args.reprob, |
| 113 | re_mode=args.remode, |
| 114 | re_count=args.recount, |
| 115 | ) |
| 116 | if not resize_im: |
| 117 | # replace RandomResizedCropAndInterpolation with |
| 118 | # RandomCrop |
| 119 | transform.transforms[0] = transforms.RandomCrop( |
| 120 | args.input_size, padding=4) |
| 121 | return transform |
| 122 | |
| 123 | t = [] |
| 124 | if args.finetune: |
| 125 | t.append( |
| 126 | transforms.Resize((args.input_size, args.input_size), |
| 127 | interpolation=3) |
| 128 | ) |
| 129 | else: |
| 130 | if resize_im: |
| 131 | size = int((256 / 224) * args.input_size) |
| 132 | t.append( |
| 133 | # to maintain same ratio w.r.t. 224 images |
| 134 | transforms.Resize(size, interpolation=3), |
| 135 | ) |
| 136 | t.append(transforms.CenterCrop(args.input_size)) |
| 137 | |
| 138 | t.append(transforms.ToTensor()) |
| 139 | t.append(transforms.Normalize(IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD)) |
| 140 | return transforms.Compose(t) |
no test coverage detected