ssds.dataset

ssds.dataset.dataset_factory

ssds.dataset.dataset_factory.detection_collate(batch)[source]

Custom collate fn for dealing with batches of images that have a different number of associated object annotations (bounding boxes). :param batch: (tuple) A tuple of tensor images and lists of annotations

Returns

  1. (tensor) batch of images stacked on their 0 dim

  2. (tensors) annotations for a given image are stacked on 0 dim

Return type

A tuple containing

ssds.dataset.dataset_factory.load_data(cfg, phase)[source]

create the dataloader based on the config file.

  • If the phase == “train”,

    it returns the dataloader in cfg.DATASET.TRAIN_SETS and fetch the randomly;

  • If the phase == “test”,

    it returns the dataloader in cfg.DATASET.TEST_SETS and fetch the squentially;

Parameters
  • cfg – the configs defined by cfg.DATASET

  • phase (str) – “train” or “test”

Returns

dataloader

ssds.dataset.detection_dataset

class ssds.dataset.detection_dataset.DetectionDataset(cfg, is_train, transform=None)[source]

Bases: torch.utils.data.dataset.Dataset

The base class for the detection 2d dataset.

It contains the data pipeline which is defined by _init_transform().

DetectionDataset is the base class and does not contain the actual data, the derivative class need to fill the annotation to the self.db.

__getitem__(index)[source]

fetch the image and annotation from self.db[index]

The data in the self.db can be discribed as:

db[index] = {

‘image’: ‘Absolute Path’,

‘boxes’: np.ndarray,

‘labels’: np.adarray}

Parameters

index – index for db,

Returns

‘image’, torch(c,h,w),

’target’, np.ndarray(n,5)

0~4 is the bounding box in AbsoluteCoords with format x,y,w,h

5 is the bounding box label

ssds.dataset.coco

class ssds.dataset.coco.COCODataset(dataset_dir, image_sets)[source]

Bases: object

COCO Dataset, used to extract the data from annotation file only.

For the dataset defined in the cfg.DATASET.DATASET, please refer to COCODetection.

Saved the image path and the relative annotation to the self.img_paths and self.anno

Parameters
  • dataset_dir (str) – the directory of coco dataset

  • image_sets (list) – list folders that

annotation_from_index(index, _COCO, toPercent=True)[source]

Loads COCO bounding-box instance annotations. Crowd instances are handled by marking their overlaps (with all categories) to -1. This overlap value means that crowd “instances” are excluded from training. Return result with Percent Coords

image_path_from_index(name, index)[source]

Construct an image path from the image’s “index” identifier. Example image path for index=119993: images/train2014/COCO_train2014_000000119993.jpg

class ssds.dataset.coco.COCODetection(cfg, dataset_dir, image_sets, training=False, transform=None)[source]

Bases: ssds.dataset.coco.COCODataset, ssds.dataset.detection_dataset.DetectionDataset

COCO Object Detection Dataset

The derivative class for COCODataset and DetectionDataset.

load the image path and the relative annotation from COCODataset and save them to the annotation database. Then fetch the data by the data pipeline in the ssds.dataset.detection_dataset.DetectionDataset.

Parameters
  • dataset_dir (str) – the directory of coco dataset

  • image_sets (list) – list folders that

ssds.dataset.dali_dataiterator

class ssds.dataset.dali_dataiterator.DaliDataset(cfg, dataset_dir, image_sets, batch_size, training=False)[source]

Bases: object

Data loader for data parallel using Dali

class ssds.dataset.dali_dataiterator.DaliPipeline(target_size, preproc_param, training=False)[source]

Bases: object

The data pipeline for the Dali dataset

predefined_graph(images, bboxes, labels)[source]

ssds.dataset.dali_coco

class ssds.dataset.dali_coco.COCOPipeline(image_dir, annotations_file, cache_path, batch_size, target_size, preproc_param, num_threads, num_shards, device_ids, training=False)[source]

Bases: nvidia.dali.pipeline.Pipeline, ssds.dataset.dali_dataiterator.DaliPipeline

Dali pipeline for COCO

define_graph()[source]

This function is defined by the user to construct the graph of operations for their pipeline.

It returns a list of outputs created by calling DALI Operators.

class ssds.dataset.dali_coco.DaliCOCO(cfg, dataset_dir, image_sets, batch_size, training=False)[source]

Bases: ssds.dataset.dali_dataiterator.DaliDataset

Data loader for data parallel using Dali for TFRecord files

ssds.dataset.dali_tfrecord

class ssds.dataset.dali_tfrecord.DaliTFRecord(cfg, dataset_dir, image_sets, batch_size, training=False)[source]

Bases: ssds.dataset.dali_dataiterator.DaliDataset

Data loader for data parallel using Dali for TFRecord files

class ssds.dataset.dali_tfrecord.TFRecordPipeline(tfrecords, batch_size, target_size, preproc_param, num_threads, num_shards, device_ids, training=False)[source]

Bases: nvidia.dali.pipeline.Pipeline, ssds.dataset.dali_dataiterator.DaliPipeline

Currently the easiest way for using dali to process the dataset is using TFRecord Files

define_graph()[source]

This function is defined by the user to construct the graph of operations for their pipeline.

It returns a list of outputs created by calling DALI Operators.

ssds.dataset.transforms

class ssds.dataset.transforms.Compose(transforms)[source]

Bases: object

Composes several augmentations together. :param transforms: list of transforms to compose. :type transforms: List[Transform]

Example

>>> augmentations.Compose([
>>>     transforms.CenterCrop(10),
>>>     transforms.ToTensor(),
>>> ])
class ssds.dataset.transforms.ConvertColor(current='BGR', transform='HSV')[source]

Bases: object

class ssds.dataset.transforms.ConvertFromInts[source]

Bases: object

class ssds.dataset.transforms.Expand(mean=0, max_expand_ratio=2)[source]

Bases: object

class ssds.dataset.transforms.Lambda(lambd)[source]

Bases: object

Applies a lambda as a transform.

class ssds.dataset.transforms.Normalize(mean=0, std=255)[source]

Bases: object

class ssds.dataset.transforms.PhotometricDistort(hue_delta=18.0, bri_delta=32, contrast_range=0.5, 1.5, saturation_range=0.5, 1.5)[source]

Bases: object

class ssds.dataset.transforms.RandomBrightness(delta=32)[source]

Bases: object

class ssds.dataset.transforms.RandomContrast(lower=0.5, upper=1.5)[source]

Bases: object

class ssds.dataset.transforms.RandomHue(delta=18.0)[source]

Bases: object

class ssds.dataset.transforms.RandomLightingNoise[source]

Bases: object

class ssds.dataset.transforms.RandomMirror[source]

Bases: object

class ssds.dataset.transforms.RandomSampleCrop(scale=0.3, 1.0, ratio=0.5, 2, num_attempts=50)[source]

Bases: object

Crop :param img: the image being input during training :type img: Image :param boxes: the original bounding boxes in pt form :type boxes: Tensor :param labels: the class labels for each bbox :type labels: Tensor :param mode: the min and max jaccard overlaps :type mode: float tuple

Returns

(img, boxes, classes)

img (Image): the cropped image boxes (Tensor): the adjusted bounding boxes in pt form labels (Tensor): the class labels for each bbox

class ssds.dataset.transforms.RandomSaturation(lower=0.5, upper=1.5)[source]

Bases: object

class ssds.dataset.transforms.Resize(size: tuple)[source]

Bases: object

class ssds.dataset.transforms.SwapChannels(swaps)[source]

Bases: object

Transforms a tensorized image by swapping the channels in the order specified in the swap tuple. :param swaps: final order of channels, (2, 1, 0) :type swaps: int triple

class ssds.dataset.transforms.ToAbsoluteCoords[source]

Bases: object

class ssds.dataset.transforms.ToCV2Image[source]

Bases: object

class ssds.dataset.transforms.ToGPU[source]

Bases: object

class ssds.dataset.transforms.ToPercentCoords[source]

Bases: object

class ssds.dataset.transforms.ToTensor[source]

Bases: object

class ssds.dataset.transforms.ToXYWH[source]

Bases: object

ssds.dataset.transforms.intersect(box_a, box_b)[source]
ssds.dataset.transforms.jaccard_numpy(box_a, box_b)[source]

Compute the jaccard overlap of two sets of boxes. The jaccard overlap is simply the intersection over union of two boxes.

E.g.: A ∩ B / A ∪ B = A ∩ B / (area(A) + area(B) - A ∩ B)

Parameters
  • box_a – Multiple bounding boxes, Shape: [num_boxes,4]

  • box_b – Single bounding box, Shape: [4]

Returns

Shape: [box_a.shape[0], box_a.shape[1]]

Return type

jaccard overlap