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
(tensor) batch of images stacked on their 0 dim
(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
-
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 thessds.dataset.detection_dataset.DetectionDataset
.- Parameters
dataset_dir (str) – the directory of coco dataset
image_sets (list) – list folders that
ssds.dataset.dali_dataiterator¶
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
-
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
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.
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.
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.
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
-
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