def test_resize_in_memory(): tmpdir = tempfile.mkdtemp() tmp = tempfile.NamedTemporaryFile(dir=tmpdir, suffix='.JPEG') im = Image.new('RGB', original_dimensions) im.save(tmp.name, 'JPEG') resize = Operations.Resize(probability=1, width=larger_dimensions[0], height=larger_dimensions[1], resample_filter="BICUBIC") im = [im] im_resized = resize.perform_operation(im) assert im_resized[0].size == larger_dimensions resize_smaller = Operations.Resize(probability=1, width=smaller_dimensions[0], height=smaller_dimensions[1], resample_filter="BICUBIC") im_resized_smaller = resize_smaller.perform_operation(im) assert im_resized_smaller[0].size == smaller_dimensions tmp.close()
def __init__(self): self.imgaug_transform = iaa.Scale(size=512, interpolation="linear") self.solt_stream = slc.Stream([slt.Resize(resize_to=(512, 512))]) self.augmentor_op = Operations.Resize(probability=1, width=512, height=512, resample_filter="BILINEAR")
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 get_augmentation_group(data_aug_group, input_size, center=True, resize=True): resize_prob = 1 if resize else 0 center_prob = 1 if center else 0 DATA_AUGMENTATION_GROUPS = [ # GROUP 0 (NO DATA AUGMENTATION) [ # Center crop CropCenter(probability=center_prob), # Resize the image to the desired input size Operations.Resize(probability=resize_prob, width=input_size[0], height=input_size[1], resample_filter="BICUBIC") ], # GROUP 1 (Common transformations: rotations, flips, crops, shears) [ # Rotate the image by 90 degrees randomly Operations.Rotate(probability=0.5, rotation=-1), # Flip top/bottom Operations.Flip(probability=0.5, top_bottom_left_right="TOP_BOTTOM"), # Flip left/right Operations.Flip(probability=0.5, top_bottom_left_right="LEFT_RIGHT"), # Random crops Operations.CropPercentage(probability=0.5, percentage_area=0.85, centre=center, randomise_percentage_area=True), # Resize the image to the desired input size Operations.Resize(probability=resize_prob, width=input_size[0], height=input_size[1], resample_filter="BICUBIC") ], # GROUP 2 (Pixel intensity transformations) [ # Rotate the image by 90 degrees randomly Operations.Rotate(probability=0.5, rotation=-1), # Flip top/bottom Operations.Flip(probability=0.5, top_bottom_left_right="TOP_BOTTOM"), # Flip left/right Operations.Flip(probability=0.5, top_bottom_left_right="LEFT_RIGHT"), # Random change brightness of the image Operations.RandomBrightness(probability=0.5, min_factor=0.5, max_factor=1.5), # Random change saturation of the image Operations.RandomColor(probability=0.5, min_factor=0.5, max_factor=1.5), # Random change saturation of the image Operations.RandomContrast(probability=0.5, min_factor=0.5, max_factor=1.5), # Random crops Operations.CropPercentage(probability=0.5, percentage_area=0.85, centre=center, randomise_percentage_area=True), # Resize the image to the desired input size Operations.Resize(probability=resize_prob, width=input_size[0], height=input_size[1], resample_filter="BICUBIC") ], # GROUP 3 (Perspective transformations) [ # Rotate the image by 90 degrees randomly Operations.Rotate(probability=0.5, rotation=-1), # Flip top/bottom Operations.Flip(probability=0.5, top_bottom_left_right="TOP_BOTTOM"), # Flip left/right Operations.Flip(probability=0.5, top_bottom_left_right="LEFT_RIGHT"), # Shear Image Operations.Shear(probability=0.5, max_shear_left=20, max_shear_right=20), # Random Tilt up down Operations.Skew(probability=0.5, skew_type="TILT_TOP_BOTTOM", magnitude=1.0), # Random Tilt left right Operations.Skew(probability=0.5, skew_type="TILT_LEFT_RIGHT", magnitude=1.0), # Random Skew CORNER Operations.Skew(probability=0.5, skew_type="CORNER", magnitude=1.3), # Random crops Operations.CropPercentage(probability=0.5, percentage_area=0.85, centre=center, randomise_percentage_area=True), # Resize the image to the desired input size Operations.Resize(probability=resize_prob, width=input_size[0], height=input_size[1], resample_filter="BICUBIC") ], # GROUP 4 (Noise transformations) [ # Center crop CropCenter(probability=1), # Rotate the image by 90 degrees randomly Operations.Rotate(probability=0.5, rotation=-1), # Flip top/bottom Operations.Flip(probability=0.5, top_bottom_left_right="TOP_BOTTOM"), # Flip left/right Operations.Flip(probability=0.5, top_bottom_left_right="LEFT_RIGHT"), # Random distortions Operations.Distort(probability=0.5, grid_width=8, grid_height=8, magnitude=15), # Random erasing Operations.RandomErasing(probability=0.5, rectangle_area=0.25), # Random crops Operations.CropPercentage(probability=0.5, percentage_area=0.85, centre=center, randomise_percentage_area=True), # Resize the image to the desired input size Operations.Resize(probability=resize_prob, width=input_size[0], height=input_size[1], resample_filter="BICUBIC") ] ] return DATA_AUGMENTATION_GROUPS[data_aug_group]