Spaces:
Runtime error
Runtime error
File size: 2,636 Bytes
c310e19 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
from . import transforms as T
def build_transforms(cfg, is_train=True):
to_bgr255 = cfg.INPUT.TO_BGR255
normalize_transform = T.Normalize(
mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD, to_bgr255=to_bgr255
)
if is_train:
min_size = cfg.INPUT.MIN_SIZE_TRAIN
max_size = cfg.INPUT.MAX_SIZE_TRAIN
# flip_prob = 0.5 # cfg.INPUT.FLIP_PROB_TRAIN
# flip_prob = 0
# rotate_prob = 0.5
rotate_prob = 0.5
pixel_aug_prob = 0.2
random_crop_prob = cfg.DATASETS.RANDOM_CROP_PROB
else:
min_size = cfg.INPUT.MIN_SIZE_TEST
max_size = cfg.INPUT.MAX_SIZE_TEST
# flip_prob = 0
rotate_prob = 0
pixel_aug_prob = 0
random_crop_prob = 0
to_bgr255 = cfg.INPUT.TO_BGR255
normalize_transform = T.Normalize(
mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD, to_bgr255=to_bgr255
)
if cfg.DATASETS.AUG and is_train:
if cfg.DATASETS.FIX_CROP:
transform = T.Compose(
[
T.RandomCrop(1.0, crop_min_size=512, crop_max_size=640, max_trys=50),
T.RandomBrightness(pixel_aug_prob),
T.RandomContrast(pixel_aug_prob),
T.RandomHue(pixel_aug_prob),
T.RandomSaturation(pixel_aug_prob),
T.RandomGamma(pixel_aug_prob),
T.RandomRotate(rotate_prob),
T.Resize(min_size, max_size, cfg.INPUT.STRICT_RESIZE),
T.ToTensor(),
normalize_transform,
]
)
else:
transform = T.Compose(
[
T.RandomCrop(random_crop_prob),
T.RandomBrightness(pixel_aug_prob),
T.RandomContrast(pixel_aug_prob),
T.RandomHue(pixel_aug_prob),
T.RandomSaturation(pixel_aug_prob),
T.RandomGamma(pixel_aug_prob),
T.RandomRotate(rotate_prob, max_theta=cfg.DATASETS.MAX_ROTATE_THETA, fix_rotate=cfg.DATASETS.FIX_ROTATE),
T.Resize(min_size, max_size, cfg.INPUT.STRICT_RESIZE),
T.ToTensor(),
normalize_transform,
]
)
else:
transform = T.Compose(
[
T.Resize(min_size, max_size, cfg.INPUT.STRICT_RESIZE),
T.ToTensor(),
normalize_transform,
]
)
return transform
|