class RandomSizedCrop_64_512(BenchmarkTest): def __init__(self): self.augmentor_pipeline = Pipeline() self.augmentor_pipeline.add_operation( Operations.Crop(probability=1, width=64, height=64, centre=False)) self.augmentor_pipeline.add_operation( Operations.Resize(probability=1, width=512, height=512, resample_filter="BILINEAR")) self.imgaug_transform = iaa.Sequential([ iaa.CropToFixedSize(width=64, height=64), iaa.Scale(size=512, interpolation="linear") ]) self.solt_stream = slc.Stream([ slt.CropTransform(crop_size=(64, 64), crop_mode="r"), slt.ResizeTransform(resize_to=(512, 512)) ]) def albumentations(self, img): img = albumentations.random_crop(img, crop_height=64, crop_width=64, h_start=0, w_start=0) return albumentations.resize(img, height=512, width=512) def augmentor(self, img): for operation in self.augmentor_pipeline.operations: img, = operation.perform_operation([img]) return np.array(img, np.uint8, copy=True) def torchvision_transform(self, img): img = torchvision.crop(img, top=0, left=0, height=64, width=64) return torchvision.resize(img, (512, 512))
class BrightnessContrast(BenchmarkTest): def __init__(self): self.imgaug_transform = iaa.Sequential([ iaa.Multiply((1.5, 1.5), per_channel=False), iaa.Add((127, 127), per_channel=False) ]) self.augmentor_pipeline = Pipeline() self.augmentor_pipeline.add_operation( Operations.RandomBrightness(probability=1, min_factor=1.5, max_factor=1.5)) self.augmentor_pipeline.add_operation( Operations.RandomContrast(probability=1, min_factor=1.5, max_factor=1.5)) self.solt_stream = slc.Stream([ slt.ImageRandomBrightness(p=1, brightness_range=(127, 127)), slt.ImageRandomContrast(p=1, contrast_range=(1.5, 1.5)), ]) def albumentations(self, img): return albumentations.brightness_contrast_adjust(img, alpha=1.5, beta=0.5, beta_by_max=True) def torchvision_transform(self, img): img = torchvision.adjust_brightness(img, brightness_factor=1.5) img = torchvision.adjust_contrast(img, contrast_factor=1.5) return img def augmentor(self, img): for operation in self.augmentor_pipeline.operations: img, = operation.perform_operation([img]) return np.array(img, np.uint8, copy=True)
def create_aug_pipeline_train(input_size): """Image Augmentation Pipeline for Training Set.""" p_train = Pipeline() # Random crop p_train.add_operation(CropPercentageRange(probability=1, min_percentage_area=0.8, max_percentage_area=1, centre=False)) # Rotate the image by either 90, 180, or 270 degrees randomly p_train.rotate_random_90(probability=0.5) # Flip the image along its vertical axis p_train.flip_top_bottom(probability=0.5) # Flip the image along its horizontal axis p_train.flip_left_right(probability=0.5) # Random change brightness of the image p_train.random_brightness(probability=0.5, min_factor=0.9, max_factor=1.1) # Random change saturation of the image p_train.random_color(probability=0.5, min_factor=0.9, max_factor=1.1) # Resize the image to the desired input size of the model p_train.resize(probability=1, width=input_size[0], height=input_size[1]) return p_train