ParticleDetection.modelling.datasets
Functions to prepare datasets for the use by the Detectron2 framework, as well as functions to get basic information about a dataset, i.e. size and thing classes.
Author: Adrian Niemann (adrian.niemann@ovgu.de)
Date: 31.10.2022
- extract_polygon(annotation: dict)[source]
Extract a polygon and its bounds from annotation data.
This function extracts object segmentations as polygons from different shapes annotated with the VGG Image Annotator (VIA). Currently this function supports rectangular, circlular, elliptical, and polyonal/polyline annotations from VIA.
- Parameters:
annotation (dict) – Contents of the
"shape_attributes"field of an object’s segmentation data saved from VIA.- Returns:
tuple(list, list) – [0] : list of polygon point coordinates
[1] : bounding box of object as [min_x, min_y, max_x, max_y]
- Raises:
ValueError – Is raised, in case an unknown annotation type is encountered, i.e. none of the ones mentioned above.
- get_dataset_classes(dataset: DataSet) Set[int][source]
Retrieve the number and IDs of thing classes in the dataset.
- get_dataset_size(dataset: DataSet) int[source]
Compute the number of annotated images in a
DataSet(excluding augmentation).
- load_custom_data(dataset: DataSet) List[dict][source]
Loads a (training/testing) dataset into the Detectron2 format.
- Parameters:
dataset (DataSet) – Dataset that will be transferred to the Detectron2 dataset format for training a model.
- Returns:
List[dict] – Dataset in the Detectron2 format.
Note
For more information see: https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html#standard-dataset-dicts
- register_dataset(dataset: DataSet, generation_function: Callable = load_custom_data, classes: List[str] | None = None)[source]
Register a custom dataset to the Detectron2 framework.
- Parameters:
dataset (DataSet) –
generation_function (Callable, optional) –
Function, that transforms a given
DataSetinto a Detectron2 readable format.By default
load_custom_data().classes (List[str], optional) –
Names of the classes present in the loaded dataset.
By default
None, which results in class names like0, 1, 2, ....