Appearance
relai.datasets package
Submodules
relai.datasets.coco_format module
class relai.datasets.coco_format.CocoFormatDataset(dataset_path: str | Path, annFile: str | Path)
Bases: RELAIDataset
Load any object detection dataset that follows COCO data format (https://cocodataset.org/#format-data). It requires the COCO API (pycocotools) to be installed (https://github.com/cocodataset/cocoapi/tree/master).
- Parameters:
- dataset_path (Union *[*str , Path ]) – Root directory where images are stored.
- annFile (Union *[*str , Path ]) – Path to the corresponding json annotation file.
relai.datasets.image_folder module
class relai.datasets.image_folder.ImageFolderDataset(dataset_path: str | Path)
Bases: RELAIClassificationDataset
Dataset wrapper for the relai_algorithms classification pipeline.
Assumes that the dataset is organized as expected by torchvision.datasets.ImageFolder as follows:
```: root/dog/xxx.png root/dog/xxy.png root/dog/[…]/xxz.png
root/cat/123.png root/cat/nsdf3.png root/cat/[…]/
asd932_.png
```See here for more details: https://pytorch.org/vision/stable/generated/torchvision.datasets.ImageFolder.html
- Parameters:dataset_path (Union *[*str , Path ]) – Path to the root directory of the dataset.
property class_name_to_images : dict[str, list[int]]
Mapping from class name to image indices in dataset corresponding to that class.
property classes : list[str]
List of classes in dataset.
relai.datasets.image_folder.navigate_to_root(path: Path)
Navigates to the correct descendant with train/val/test folders. Assumes that there is only one descendant that is not a train/val/test folder.
relai.datasets.relai_dataset module
class relai.datasets.relai_dataset.RELAIClassificationDataset(*args, **kwargs)
Bases: RELAIDataset
property class_idx_to_images : dict[int, list[int]]
Mapping from class index to image indices in dataset corresponding to that class.
abstract property class_name_to_images : dict[str, list[int]]
Mapping from class name to image indices in dataset corresponding to that class.
property classes : list[str]
List of classes in dataset.
property num_classes : int
Number of classes in dataset.
class relai.datasets.relai_dataset.RELAIDataFormat(value, names=not given, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases: StrEnum
Enum for supported dataset formats.
COCOFORMAT = 'coco_format'
IMAGEFOLDER = 'imagefolder'
class relai.datasets.relai_dataset.RELAIDataset
Bases: Dataset
Base class for all RELAI datasets.
class relai.datasets.relai_dataset.Subset(dataset: RELAIClassificationDataset, indices: list[int])
Bases: RELAIClassificationDataset
Subset of a dataset at specified indices.
- Parameters:
- dataset (RELAIClassificationDataset) – The whole Dataset
- indices (list *[*int ]) – Indices in the whole set selected for subset
property class_name_to_images : dict[str, list[int]]
Mapping from class name to image indices in dataset corresponding to that class.
class relai.datasets.relai_dataset.TransformDataset(dataset: RELAIDataset, transform: Callable)
Bases: RELAIDataset
Dataset wrapper that applies a transform to each item in the dataset.
- Parameters:
- dataset (RELAIDataset) – Dataset to wrap.
- transform (Callable) – Transform to apply to each item in the dataset.
relai.datasets.segmentation_dataset module
class relai.datasets.segmentation_dataset.RELAISegmentationDataset(*args, **kwargs)
Bases: RELAIDataset
abstract get_dataset(batch_size: int)
Method to generate batches of dataset
Example
segmentation_dataset = RELAISegmentationDataset(…) for batch in segmentation_dataset.get_dataset(batch_size):
process_batch(batch)
abstract load_dataset()
Method to load the dataset
class relai.datasets.segmentation_dataset.RELAISegmentationDatasetCSV(dataset_path: str)
Bases: RELAISegmentationDataset
get_dataset(batch_size: int)
Method to generate batches of dataset
Example
segmentation_dataset = RELAISegmentationDataset(…) for batch in segmentation_dataset.get_dataset(batch_size):
process_batch(batch)
load_dataset()
Method to load the dataset
class relai.datasets.segmentation_dataset.SegmentationDataPair(input_image_path, input_image, ground_truth_path, ground_truth)
Bases: tuple
ground_truth
Alias for field number 3
ground_truth_path
Alias for field number 2
input_image
Alias for field number 1
input_image_path
Alias for field number 0
relai.datasets.utils module
relai.datasets.utils.coco_collate(batch)
relai.datasets.utils.get_dataset(data_format: RELAIDataFormat, dataset_path: str | Path, *dataset_args, **dataset_kwargs)
Returns a RELAIDataset object based on the specified format and path.
- Parameters:
- dataset_format (RELAIDataFormat) – Format of dataset.
- dataset_path (Union *[*str , Path ]) – Path to dataset.
- **dataset_args – Positional arguments to pass to dataset constructor.
- **dataset_kwargs – Keyword arguments to pass to dataset constructor.
- Returns: Dataset object.
- Return type:RELAIDataset