def get_transform(train): base_size = 520 crop_size = 480 min_size = int((0.5 if train else 1.0) * base_size) max_size = int((2.0 if train else 1.0) * base_size) transforms = [] transforms.append(T.RandomResize(min_size, max_size)) if train: transforms.append( T.RandomColorJitter(brightness=0.25, contrast=0.25, saturation=0.25, hue=0.25)) transforms.append(T.RandomGaussianSmoothing(radius=[0, 5])) transforms.append(T.RandomRotation(degrees=30, fill=0)) transforms.append(T.RandomHorizontalFlip(0.5)) transforms.append(T.RandomPerspective(fill=0)) transforms.append(T.RandomCrop(crop_size, fill=0)) transforms.append(T.RandomGrayscale(p=0.1)) transforms.append(T.ToTensor()) transforms.append( T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])) return T.Compose(transforms)
def get_transform(train, net_w=416, net_h=416): transforms = [] transforms.append(T.ToTensor()) if train == True: transforms.append(T.RandomSpatialJitter(jitter=0.3,net_w=net_w,net_h=net_h)) transforms.append(T.RandomColorJitter(hue=0.1,saturation=1.5,exposure=1.5)) transforms.append(T.RandomHorizontalFlip(prob=0.5)) else: transforms.append(T.MakeLetterBoxImage(width=net_w,height=net_h)) return T.Compose(transforms)