5.1. data_augmentor module

5.1.1. Summary

Classes:

Blur

Gaussian blur filter.

Brightness

Adjust image brightness.

Color

Adjust image color.

Contrast

Adjust image contrast.

Crop

Crop image.

FlipLeftRight

Flip left right.

FlipTopBottom

Flip top bottom.

Hue

Change image hue.

Pad

Add padding to images.

RandomErasing

Class that performs Random Erasing in Random Erasing Data Augmentation by Zhong et al.

RandomErasingForDetection

Class that performs Random Erasing in Random Erasing Data Augmentation by Zhong et al.

RandomPatchCut

Cut out random patches of the image.

Rotate

Rotate.

SSDRandomCrop

SSD random crop.

5.1.2. Reference

class lmnet.data_augmentor.Blur(value=(0, 1))

Gaussian blur filter.

Reference:

https://pillow.readthedocs.io/en/stable/reference/ImageFilter.html#PIL.ImageFilter.GaussianBlur

Parameters

value (int | list | tuple) – Blur radius. Default is random number from 0 to 1. References default is 2.

class lmnet.data_augmentor.Brightness(value=(0.75, 1.25))

Adjust image brightness.

Reference:

https://pillow.readthedocs.io/en/stable/reference/ImageEnhance.html#PIL.ImageEnhance.PIL.ImageEnhance.Brightness

Parameters

value (int | list | tuple) – An enhancement factor of 0.0 gives a black image. A factor of 1.0 gives the original image.

class lmnet.data_augmentor.Color(value=(0.75, 1.25))

Adjust image color.

Reference:

https://pillow.readthedocs.io/en/stable/reference/ImageEnhance.html#PIL.ImageEnhance.PIL.ImageEnhance.Color

Parameters

value (int | list | tuple) – An enhancement factor of 0.0 gives a black and white image. A factor of 1.0 gives the original image.

class lmnet.data_augmentor.Contrast(value=(0.75, 1.25))

Adjust image contrast.

Reference:

https://pillow.readthedocs.io/en/stable/reference/ImageEnhance.html#PIL.ImageEnhance.PIL.ImageEnhance.Contrast

Parameters

value (int | list | tuple) – An enhancement factor of 0.0 gives a solid grey image. A factor of 1.0 gives the original image.

class lmnet.data_augmentor.Crop(size, resize=None)

Crop image.

Parameters
  • size (int | list | tuple) – Crop to this size.

  • resize (int | list | tuple) – If there are resize param, resize and crop.

class lmnet.data_augmentor.FlipLeftRight(probability=0.5)

Flip left right.

Parameters

probability (number) – Probability for flipping.

class lmnet.data_augmentor.FlipTopBottom(probability=0.5)

Flip top bottom.

Parameters

probability (number) – Probability for flipping.

class lmnet.data_augmentor.Hue(value=(-10, 10))

Change image hue.

Parameters

value (int | list | tuple) – Assume the value in -255, 255. When the value is 0, nothing to do.

class lmnet.data_augmentor.Pad(value, fill=0)

Add padding to images.

Parameters
  • value (int or tuple) – Padding on each border. If a single int is provided this is used to pad all borders. If tuple of length 2 is provided this is the padding on left/right and top/bottom respectively. If a tuple of length 4 is provided this is the padding for the left, top, right and bottom borders respectively.

  • fill (int) – Pixel fill value. Default is 0.

class lmnet.data_augmentor.RandomErasing(probability=0.5, sl=0.02, sh=0.4, r1=0.3, content_type='mean', mean=[125, 122, 114])

Class that performs Random Erasing in Random Erasing Data Augmentation by Zhong et al. The following Args(hyper parameters) are referred to the paper.

Parameters
  • probability (float) – The probability that the operation will be performed.

  • sl (float) – min erasing area

  • sh (float) – max erasing area

  • r1 (float) – min aspect ratio

  • content_type (string) – type of erasing value: {“mean”, “random”}

  • mean (list) – erasing value if you use “mean” mode (mean ImageNet pixel value)

class lmnet.data_augmentor.RandomErasingForDetection(probability=0.5, sl=0.02, sh=0.2, r1=0.3, content_type='mean', mean=[125, 122, 114], i_a=True, o_a=True)

Class that performs Random Erasing in Random Erasing Data Augmentation by Zhong et al. The following Args(hyper parameters) are referred to the paper. This Augmentation can be used when you train object detection task.

Parameters
  • probability (float) – The probability that the operation will be performed.

  • sl (float) – min erasing area

  • sh (float) – max erasing area

  • r1 (float) – min aspect ratio

  • content_type (string) – type of erasing value: {“mean”, “random”}

  • mean (list) – erasing value if you use “mean” mode (mean ImageNet pixel value)

  • i_a (bool) – image-aware, random erase an entire image.

  • o_a (bool) – object-aware, random erase each object bounding boxes.

class lmnet.data_augmentor.RandomPatchCut(num_patch=1, max_size=10, square=True)

Cut out random patches of the image.

Parameters
  • num_patch (int) – number of random patch cut-outs to generate

  • max_size (int) – maximum size of the patch edge, in percentages of image size

  • square (bool) – force square aspect ratio for patch shape

class lmnet.data_augmentor.Rotate(angle_range=(0, 90))

Rotate.

Parameters

angle_range (int | list | tuple) – Angle range.

class lmnet.data_augmentor.SSDRandomCrop(min_crop_ratio=0.3)

SSD random crop.

References

https://github.com/amdegroot/ssd.pytorch/blob/master/utils/augmentations.py#L208

Parameters

min_crop_ratio (number) – Minimum crop ratio for cropping the