Detr: Data connectors

Pytorch Lightning Data Module connector between dataset and model. Load train/val/test sets and make the preprocessing required for use by the Detr-based architectures.

Data2Detr

LightningDataModule base to use dataset in Detr trainer models.

See Also

LightningDataModule for more information about to create data modules from Dataset and Dataloader

class alonet.detr.data_modules.data2detr.Data2Detr(args=None, **kwargs)

Bases: pytorch_lightning.core.datamodule.LightningDataModule

Parameters
batch_sizeint, optional

Batch size to use

train_on_valbool, optional

Use train on validation

num_workersint, optional

Nummer of workers to use

no_augmentationbool, optional

Do not use augmentation to train the model

sizetuple, optional

If no augmentation (–no_augmentation) is used, –size can be used to resize all the frame.

samplebool, optional

Use Sample instead of all dataset, by default False

argsNamespace, optional

Attributes stored in specific Namespace, by default None

Raises
Exception

Size argument must be one or two elements

Notes

Arguments entered by the user (kwargs) will replace those stored in args attribute

static add_argparse_args(parent_parser)

Append the respect arguments to parser object

Parameters
parent_parserArgumentParser

Object with previous arguments to append

Returns
ArgumentParser

Arguments updated

setup(stage=None)

Called at the beginning of fit (train + validate), validate, test, and predict. This is a good hook when you need to build models dynamically or adjust something about them. This hook is called on every process when using DDP.

Parameters
stagestr, optional

Stage either fit, validate, test or predict, by default None

Raises
Exception

This class must be inhert and set train_dataset and val_dataset attributes

train_dataloader()

Get train dataloader

Returns
torch.utils.data.DataLoader

Dataloader for training process

train_transform(frame, same_on_sequence=True, same_on_frames=False)

Transorm requered to train on each frame

Parameters
frameframe

Input frame to transform

same_on_sequencebool, optional

Use same data augmentation size of each sequence, by default True

same_on_framesbool, optional

Use same data augmentation size of each frame, by default False

Returns
frame

Frame with respective changes by transform function

val_dataloader(sampler=None)

Get val dataloader

Parameters
samplertorch.utils.data, optional

Sampler to load batches, by default None

Returns
torch.utils.data.DataLoader

Dataloader for validation process

val_transform(frame, same_on_sequence=True, same_on_frames=False)

Transform requered to valid on each frame

Parameters
frameframe

Input frame to transform

same_on_sequencebool, optional

Use same data augmentation size of each sequence, by default True

same_on_framesbool, optional

Use same data augmentation size of each frame, by default False

Returns
frame

Frame with respective changes by transform function

CocoDetection2Detr

LightningDataModule that make the connection between CocoBaseDataset and LitDetr modules. See Data2Detr to more information about the methods and configurations.

Examples

from alonet.detr import CocoDetection2Detr
from aloscene import Frame

datamodule = CocoDetection2Detr(sample = True)

train_frame = next(iter(datamodule.train_dataloader()))
train_frame = Frame.batch_list(train_frame).get_view().render()

val_frame = next(iter(datamodule.val_dataloader()))
val_frame = Frame.batch_list(val_frame).get_view().render()
class alonet.detr.data_modules.coco_detection2detr.CocoDetection2Detr(args=None, name='coco', classes=None, train_folder='train2017', train_ann='annotations/instances_train2017.json', val_folder='val2017', val_ann='annotations/instances_val2017.json', return_masks=False, **kwargs)

Bases: alonet.detr.data_modules.data2detr.Data2Detr

LightningDataModule to use coco dataset in Detr models

Parameters
classeslist, optional

List to classes to be filtered in dataset, by default None

namestr, optional

Database name, by default “coco”

train_folderstr, optional

Image folder to train, by default “train2017”

train_annstr, optional

Json annotation file to train, by default “annotations/instances_train2017.json”

val_folderstr, optional

Image folder to valid, by default “val2017”

val_annstr, optional

Json annotation file to valid, by default “annotations/instances_val2017.json”

return_masksbool, optional

For each frame return masks in segmentation attribute, by default False

argsNamespace, optional

Attributes stored in specific Namespace, by default None

**kwargs

Data2Detr additional parameters

Attributes
label_nameslist

List of labels names use to encode the classes by index

setup(stage=None)

train_dataset and val_dataset datasets setup, follow the parameters used in class declaration. Also, set label_names attribute.

Parameters
stagestr, optional

Stage either fit, validate, test or predict, by default None

CocoPanoptic2Detr

LightningDataModule that make the connection between CocoPanopticDataset and LitPanopticDetr modules. See Data2Detr to more information about the methods and configurations.

Examples

from alonet.detr import CocoPanoptic2Detr
from aloscene import Frame

datamodule = CocoPanoptic2Detr(sample = True)

train_frame = next(iter(datamodule.train_dataloader()))
train_frame = Frame.batch_list(train_frame).get_view().render()

val_frame = next(iter(datamodule.val_dataloader()))
val_frame = Frame.batch_list(val_frame).get_view().render()
class alonet.detr.data_modules.coco_panoptic2detr.CocoPanoptic2Detr(args=None, **kwargs)

Bases: alonet.detr.data_modules.data2detr.Data2Detr

setup(stage=None, fix_classes_len=250)

train_dataset and val_dataset datasets setup, follow the parameters used in class declaration. Also, set label_names attribute.

Parameters
stagestr, optional

Stage either fit, validate, test or predict, by default None

fix_classes_lenint, optional

Fix datasets to a specific number the number of classes, filling the rest with “N/A” value.