data_aug.data_aug¶
data_aug contains common image and bounding boxes transforms. They can be chained together using Sequence

class
data_aug.data_aug.
Sequence
(augmentations, probs=1)¶ Initialise Sequence object
Apply a Sequence of transformations to the images/boxes.
Parameters:  augemnetations (list) – List containing Transformation Objects in Sequence they are to be applied
 probs (int or list) – If int, the probability with which each of the transformation will be applied. If list, the length must be equal to augmentations. Each element of this list is the probability with which each corresponding transformation is applied
Returns: Sequence Object
Return type:
Transforms Not Involving change in Bounding Boxes¶
These transforms should be applied before the ones involving change in bounding boxes

class
data_aug.data_aug.
RandomHSV
(hue=None, saturation=None, brightness=None)¶ HSV Transform to vary hue saturation and brightness
Hue has a range of 0179 Saturation and Brightness have a range of 0255. Chose the amount you want to change thhe above quantities accordingly.
Parameters:  hue (None or int or tuple (int)) – If None, the hue of the image is left unchanged. If int, a random int is uniformly sampled from (hue, hue) and added to the hue of the image. If tuple, the int is sampled from the range specified by the tuple.
 saturation (None or int or tuple(int)) – If None, the saturation of the image is left unchanged. If int, a random int is uniformly sampled from (saturation, saturation) and added to the hue of the image. If tuple, the int is sampled from the range specified by the tuple.
 brightness (None or int or tuple(int)) – If None, the brightness of the image is left unchanged. If int, a random int is uniformly sampled from (brightness, brightness) and added to the hue of the image. If tuple, the int is sampled from the range specified by the tuple.
Returns:  numpy.ndaaray – Transformed image in the numpy format of shape HxWxC
 numpy.ndarray – Resized bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
Transforms Involving Change in Bounding Boxes¶

class
data_aug.data_aug.
RandomHorizontalFlip
(p=0.5)¶ Randomly horizontally flips the Image with the probability p
Parameters: p (float) – The probability with which the image is flipped Returns:  numpy.ndaaray – Flipped image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
RandomRotate
(angle=10)¶ Randomly rotates an image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: angle (float or tuple(float)) – if float, the image is rotated by a factor drawn randomly from a range (angle, angle). If tuple, the angle is drawn randomly from values specified by the tuple Returns:  numpy.ndaaray – Rotated image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
RandomScale
(scale=0.2, diff=False)¶ Randomly scales an image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: scale (float or tuple(float)) – if float, the image is scaled by a factor drawn randomly from a range (1  scale , 1 + scale). If tuple, the scale is drawn randomly from values specified by the tuple Returns:  numpy.ndaaray – Scaled image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
RandomShear
(shear_factor=0.2)¶ Randomly shears an image in horizontal direction
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: shear_factor (float or tuple(float)) – if float, the image is sheared horizontally by a factor drawn randomly from a range (shear_factor, shear_factor). If tuple, the shear_factor is drawn randomly from values specified by the tuple Returns:  numpy.ndaaray – Sheared image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
RandomTranslate
(translate=0.2, diff=False)¶ Randomly Translates the image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: translate (float or tuple(float)) – if float, the image is translated by a factor drawn randomly from a range (1  translate , 1 + translate). If tuple, translate is drawn randomly from values specified by the tuple Returns:  numpy.ndaaray – Translated image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
HorizontalFlip
¶ Randomly horizontally flips the Image with the probability p
Parameters: p (float) – The probability with which the image is flipped Returns:  numpy.ndaaray – Flipped image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
Rotate
(angle)¶ Rotates an image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: angle (float) – The angle by which the image is to be rotated Returns:  numpy.ndaaray – Rotated image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
Scale
(scale_x=0.2, scale_y=0.2)¶ Scales the image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters:  scale_x (float) – The factor by which the image is scaled horizontally
 scale_y (float) – The factor by which the image is scaled vertically
Returns:  numpy.ndaaray – Scaled image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
Shear
(shear_factor=0.2)¶ Shears an image in horizontal direction
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: shear_factor (float) – Factor by which the image is sheared in the xdirection Returns:  numpy.ndaaray – Sheared image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box

class
data_aug.data_aug.
Translate
(translate_x=0.2, translate_y=0.2, diff=False)¶ Randomly Translates the image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: translate (float or tuple(float)) – if float, the image is translated by a factor drawn randomly from a range (1  translate , 1 + translate). If tuple, translate is drawn randomly from values specified by the tuple Returns:  numpy.ndaaray – Translated image in the numpy format of shape HxWxC
 numpy.ndarray – Tranformed bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
Input Preprocessing based Transforms¶

class
data_aug.data_aug.
Resize
(inp_dim)¶ Resize the image in accordance to image_letter_box function in darknet
The aspect ratio is maintained. The longer side is resized to the input size of the network, while the remaining space on the shorter side is filled with black color. This should be the last transform
Parameters: inp_dim (tuple(int)) – tuple containing the size to which the image will be resized. Returns:  numpy.ndaaray – Sheared image in the numpy format of shape HxWxC
 numpy.ndarray – Resized bounding box coordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box