Data Augmentation

Augmentor

class ezflow.functional.data_augmentation.augmentor.FlowAugmentor(crop_size, color_aug_params={'aug_prob': 0.2}, eraser_aug_params={'aug_prob': 0.5}, spatial_aug_params={'aug_prob': 0.8})[source]

Class for appyling a series of augmentations to a pair of images and a flow field

Parameters
  • crop_size (int) – Size of the crop to be applied to the images.

  • color_aug_params (dict) – Parameters for the color augmentation.

  • eraser_aug_params (dict) – Parameters for the eraser augmentation.

  • spatial_aug_params (dict) – Parameters for the spatial augmentation.

class ezflow.functional.data_augmentation.augmentor.SparseFlowAugmentor(crop_size, color_aug_params={'aug_prob': 0.2}, eraser_aug_params={'aug_prob': 0.5}, spatial_aug_params={'aug_prob': 0.8})[source]

Class for appyling a series of augmentations to a pair of images, flow field and valid flow field.

Parameters
  • crop_size (int) – Size of the crop to be applied to the images.

  • color_aug_params (dict) – Parameters for the color augmentation.

  • eraser_aug_params (dict) – Parameters for the eraser augmentation.

  • spatial_aug_params (dict) – Parameters for the spatial augmentation.

Operations

ezflow.functional.data_augmentation.operations.color_transform(img1, img2, aug_prob=0.2, brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1592356687898089)[source]

Photometric augmentation

Parameters
  • img1 (PIL Image or numpy.ndarray) – First of the pair of images

  • img2 (PIL Image or numpy.ndarray) – Second of the pair of images

  • aug_prob (float) – Probability of applying the augmentation

  • brightness (float) – Brightness augmentation factor

  • contrast (float) – Contrast augmentation factor

  • saturation (float) – Saturation augmentation factor

  • hue (float) – Hue augmentation factor

Returns

  • img1 (PIL Image or numpy.ndarray) – Augmented image 1

  • img2 (PIL Image or numpy.ndarray) – Augmented image 2

ezflow.functional.data_augmentation.operations.crop(img1, img2, flow, crop_size=(256, 256), crop_type='center', sparse_transform=False, valid=None)[source]

Function to crop the images and flow field

Parameters
  • img1 (PIL Image or numpy.ndarray) – First of the pair of images

  • img2 (PIL Image or numpy.ndarray) – Second of the pair of images

  • flow (numpy.ndarray) – Flow field

  • valid (numpy.ndarray) – Valid flow mask

  • crop_size (tuple) – Size of the crop

  • crop_type (str) – Type of cropping

  • sparse_transform (bool) – Whether to apply sparse transform

Returns

  • img1 (PIL Image or numpy.ndarray) – Augmented image 1

  • img2 (PIL Image or numpy.ndarray) – Augmented image 2

  • flow (numpy.ndarray) – Augmented flow field

ezflow.functional.data_augmentation.operations.eraser_transform(img1, img2, bounds=[50, 100], aug_prob=0.5)[source]

Occlusion augmentation :param img1: First of the pair of images :type img1: PIL Image or numpy.ndarray :param img2: Second of the pair of images :type img2: PIL Image or numpy.ndarray :param bounds: Bounds of the eraser :type bounds: list of int :param aug_prob: Probability of applying the augmentation :type aug_prob: float

Returns

  • img1 (PIL Image or numpy.ndarray) – Augmented image 1

  • img2 (PIL Image or numpy.ndarray) – Augmented image 2

ezflow.functional.data_augmentation.operations.resize_sparse_flow_map(flow, valid, fx=1.0, fy=1.0)[source]

Resize flow field and valid flow by the scaling factor of fx and fy

Parameters
  • flow (numpy.ndarray) – Flow field

  • valid (numpy.ndarray) – Valid Flow field

  • fx (float) – Scaling factor along x

  • fy (float) – Scaling factor along y

Returns

  • flow (numpy.ndarray) – Flow field

  • valid (numpy.ndarray) – Valid Flow field

ezflow.functional.data_augmentation.operations.sparse_spatial_transform(img1, img2, flow, valid, crop_size, aug_prob=0.8, min_scale=- 0.2, max_scale=0.5, flip=True, h_flip_prob=0.5)[source]

Sparse spatial augmentation.

Parameters
  • img1 (PIL Image or numpy.ndarray) – First of the pair of images

  • img2 (PIL Image or numpy.ndarray) – Second of the pair of images

  • flow (numpy.ndarray) – Flow field

  • valid (numpy.ndarray) – Valid flow field

  • crop_size (list of int) – Size of the crop

  • aug_prob (float) – Probability of applying the augmentation

  • min_scale (float) – Minimum scale factor

  • max_scale (float) – Maximum scale factor

  • flip (bool) – Whether to apply the flip transform

  • h_flip_prob (float) – Probability of applying the horizontal flip transform

  • v_flip_prob (float) – Probability of applying the vertical flip transform

Returns

  • img1 (PIL Image or numpy.ndarray) – Augmented image 1

  • img2 (PIL Image or numpy.ndarray) – Augmented image 2

  • flow (numpy.ndarray) – Augmented flow field

  • valid (numpy.ndarray) – Valid flow field

ezflow.functional.data_augmentation.operations.spatial_transform(img1, img2, flow, crop_size, aug_prob=0.8, stretch_prob=0.8, max_stretch=0.2, min_scale=- 0.2, max_scale=0.5, flip=True, h_flip_prob=0.5, v_flip_prob=0.1)[source]

Spatial augmentation

Parameters
  • img1 (PIL Image or numpy.ndarray) – First of the pair of images

  • img2 (PIL Image or numpy.ndarray) – Second of the pair of images

  • flow (numpy.ndarray) – Flow field

  • crop_size (list of int) – Size of the crop

  • aug_prob (float) – Probability of applying the augmentation

  • stretch_prob (float) – Probability of applying the stretch transform

  • max_stretch (float) – Maximum stretch factor

  • min_scale (float) – Minimum scale factor

  • max_scale (float) – Maximum scale factor

  • flip (bool) – Whether to apply the flip transform

  • h_flip_prob (float) – Probability of applying the horizontal flip transform

  • v_flip_prob (float) – Probability of applying the vertical flip transform

Returns

  • img1 (PIL Image or numpy.ndarray) – Augmented image 1

  • img2 (PIL Image or numpy.ndarray) – Augmented image 2

  • flow (numpy.ndarray) – Augmented flow field