Data

Lightnet Data Module
This module contains everything related to pre- and post-processing of your data. It also has functionality to create datasets from images and annotations that are parseable with brambox.

Check out the tutorial to learn how to use these operators.


Preprocessing

All pre-processing operators can work with PIL/Pillow images, OpenCV Numpy arrays or PyTorch Tensors (should be normalized float tensors between 0-1). The pre-processing that works with annotations, expects brambox dataframes.

In order to simplify the process of adding new transformation, a few base classes have been created. Each pre-processing function in lightnet is a subclass of one of these 3 classes:

lightnet.data.transform.ImageTransform

Base transform class for the pre-processing on images.

lightnet.data.transform.ImageAnnoTransform

Base transform class that for the joint pre-processing of images and annotations.

lightnet.data.transform.AnnoTransform

Base transform class for the pre-processing on annotations.

Fit

These transformation modify the image and annotation data to fit a certain input dimension and as such are all ImageAnnoTransform.
You can pass the required dimensions directly to these classes, or you can pass a dataset object which will be used to get the dimensions from. The latter only works with Dataset and allows to change the required dimensions per batch.

lightnet.data.transform.Crop

Rescale and crop images/annotations to the right network dimensions.

lightnet.data.transform.Letterbox

Rescale images/annotations and add top/bottom borders to get to the right network dimensions.

lightnet.data.transform.Pad

Pad images/annotations to a certain dimension.

lightnet.data.transform.Rescale

Rescale images/annotations to the right network dimensions.

lightnet.data.transform.FitAnno

Crop and filter annotations to fit inside of the image boundaries.

Augmentation

These transformations allow you to augment your data, allowing you to train on more varied data without needing to fetch more. Some of these transformations only modify the image data (usually color modifiers), others also need to modify the annotations and are thus multi-transforms.

lightnet.data.transform.RandomFlip

Randomly flip image.

lightnet.data.transform.RandomHSV

Perform random HSV shift on the RGB data.

lightnet.data.transform.RandomJitter

Add random jitter to an image, by randomly cropping (or adding borders) to each side.

lightnet.data.transform.RandomRotate

Randomly rotate the image/annotations.


Postprocessing

GetBoxes

These operators allow you to convert various network output to one of the common bounding box tensor formats:

\[ \begin{align}\begin{aligned}\begin{split}HBB_{<num\_boxes \, \times \, 7>} &= \begin{bmatrix} batch\_num, x_{c}, y_{c}, width, height, confidence, class\_id \\ batch\_num, x_{c}, y_{c}, width, height, confidence, class\_id \\ batch\_num, x_{c}, y_{c}, width, height, confidence, class\_id \\ ... \end{bmatrix}\end{split}\\\begin{split}OBB_{<num\_boxes \, \times \, 8>} &= \begin{bmatrix} batch\_num, x_{c}, y_{c}, width, height, angle, confidence, class\_id \\ batch\_num, x_{c}, y_{c}, width, height, angle, confidence, class\_id \\ batch\_num, x_{c}, y_{c}, width, height, angle, confidence, class\_id \\ ... \end{bmatrix}\end{split}\\\begin{split}Mask_{<num\_boxes \, \times \, (7+M)>} &= \begin{bmatrix} batch\_num, x_{c}, y_{c}, width, height, mask_coef_0, mask_coef_1, ..., mask_coef_M, confidence, class\_id \\ batch\_num, x_{c}, y_{c}, width, height, mask_coef_0, mask_coef_1, ..., mask_coef_M, confidence, class\_id \\ batch\_num, x_{c}, y_{c}, width, height, mask_coef_0, mask_coef_1, ..., mask_coef_M, confidence, class\_id \\ ... \end{bmatrix}\end{split}\end{aligned}\end{align} \]

lightnet.data.transform.GetCornerBoxes

Convert the output from corner detection networks to an HBB tensor.

lightnet.data.transform.GetAnchorBoxes

Convert the output from anchor detection networks to an HBB tensor.

lightnet.data.transform.GetMultiScaleAnchorBoxes

Convert the output from multiscale anchor detection networks to an HBB tensor.

lightnet.data.transform.GetOrientedAnchorBoxes

Convert the output from oriented anchor detection networks to an OBB tensor.

lightnet.data.transform.GetMultiScaleOrientedAnchorBoxes

Convert the output from multiscale anchor detection networks to an OBB tensor.

lightnet.data.transform.GetMaskedAnchorBoxes

Convert the output from masked anchor detection networks to an HBB tensor with mask coefficients.

lightnet.data.transform.GetMultiScaleMaskedAnchorBoxes

Convert the output from multiscale anchor detection networks to an HBB tensor with mask.

lightnet.data.transform.GetMasks

Compute masks from prototype masks and coefficients.

Filtering

The following classes allow you to filter output bounding boxes based on some criteria.
They can work on the lightnet common bounding box tensor format or on a brambox dataframe.

lightnet.data.transform.NMS

Performs non-maximal suppression on the bounding boxes, filtering boxes with a high overlap.

lightnet.data.transform.NMSSoft

Performs soft NMS with exponential decaying on the bounding boxes, as explained in [1].

lightnet.data.transform.NMSSoftFast

Faster version of SoftNMS which filters boxes with a high overlap, using exponential decay.

Reverse Fit

These operations cancel the fit pre-processing operators and can only work on brambox dataframes.

lightnet.data.transform.ReverseCrop

Performs a reverse Crop operation on the bounding boxes, so that the bounding box coordinates are relative to the original image dimensions.

lightnet.data.transform.ReverseLetterbox

Performs a reverse Letterbox operation on the bounding boxes, so that the bounding box coordinates are relative to the original image dimensions.

lightnet.data.transform.ReversePad

Performs a reverse Pad operation on the bounding boxes, so that the bounding box coordinates are relative to the original image dimensions.

lightnet.data.transform.ReverseRescale

Performs a reverse Rescale operation on the bounding boxes, so that the bounding box coordinates are relative to the original image dimensions.

Brambox

Brambox related post-processing operators.

lightnet.data.transform.TensorToBrambox

Converts a tensor to a list of brambox objects.

lightnet.data.transform.PolygonizeMask

Transforms pizelwise segmentation masks to PyGEOS polygons.


Others

Some random classes and functions that are used in the data subpackage.

lightnet.data.transform.Compose

This is lightnet's own version of torchvision.transforms.Compose, which has some extra bells and whistles.

lightnet.data.Dataset

This class is a subclass of the base torch.utils.data.Dataset, that enables on the fly resizing of the input_dim with a lightnet.data.DataLoader.

lightnet.data.DataLoader

Lightnet dataloader that enables on the fly resizing of the images.

lightnet.data.brambox_collate

Function that collates dataframes by concatenating them.