Dataset Classes

class datamint.dataset.dataset.DatamintDataset(project_name, root=None, auto_update=True, api_key=None, server_url=None, return_dicom=False, return_metainfo=True, return_frame_by_frame=False, return_annotations=True, return_segmentations=True, return_as_semantic_segmentation=False, image_transform=None, mask_transform=None, alb_transform=None, semantic_seg_merge_strategy=None, include_unannotated=True, include_annotators=None, exclude_annotators=None, include_segmentation_names=None, exclude_segmentation_names=None, include_image_label_names=None, exclude_image_label_names=None, include_frame_label_names=None, exclude_frame_label_names=None, all_annotations=False)

Bases: DatamintBaseDataset

This Dataset class extends the DatamintBaseDataset class to be easily used with PyTorch. In addition to that, it has functionality to better process annotations and segmentations.

Note

Import using from datamint import Dataset.

Parameters:
  • root (str | None) – Root directory of dataset where data already exists or will be downloaded.

  • project_name (str) – Name of the project to download.

  • auto_update (bool) – If True, the dataset will be checked for updates and downloaded if necessary.

  • api_key (str | None) – API key to access the Datamint API. If not provided, it will look for the environment variable ‘DATAMINT_API_KEY’. Not necessary if you don’t want to download/update the dataset.

  • return_dicom (bool) – If True, the DICOM object will be returned, if the image is a DICOM file.

  • return_metainfo (bool) – If True, the metainfo of the image will be returned.

  • return_annotations (bool) – If True, the annotations of the image will be returned.

  • return_frame_by_frame (bool) – If True, each frame of a video/DICOM/3d-image will be returned separately.

  • include_unannotated (bool) – If True, images without annotations will be included. If False, images without annotations will be discarded.

  • all_annotations (bool) – If True, all annotations will be downloaded, including the ones that are not set as closed/done.

  • server_url (str | None) – URL of the Datamint server. If not provided, it will use the default server.

  • return_segmentations (bool) – If True (default), the segmentations of the image will be returned in the ‘segmentations’ key.

  • return_as_semantic_segmentation (bool) – If True, the segmentations will be returned as semantic segmentation.

  • image_transform (Callable[[Tensor], Any] | None) – A function to transform the image.

  • mask_transform (Callable[[Tensor], Any] | None) – A function to transform the mask.

  • semantic_seg_merge_strategy (Literal['union', 'intersection', 'mode'] | None) – If not None, the segmentations will be merged using this strategy. Possible values are ‘union’, ‘intersection’, ‘mode’.

  • include_annotators (list[str] | None) – List of annotators to include. If None, all annotators will be included. See parameter exclude_annotators.

  • exclude_annotators (list[str] | None) – List of annotators to exclude. If None, no annotators will be excluded. See parameter include_annotators.

  • include_segmentation_names (list[str] | None) – List of segmentation names to include. If None, all segmentations will be included.

  • exclude_segmentation_names (list[str] | None) – List of segmentation names to exclude. If None, no segmentations will be excluded.

  • include_image_label_names (list[str] | None) – List of image label names to include. If None, all image labels will be included.

  • exclude_image_label_names (list[str] | None) – List of image label names to exclude. If None, no image labels will be excluded.

  • include_frame_label_names (list[str] | None) – List of frame label names to include. If None, all frame labels will be included.

  • exclude_frame_label_names (list[str] | None) – List of frame label names to exclude. If None, no frame labels will be excluded.

  • all_annotations – If True, all annotations will be downloaded, including the ones that are not set as closed/done.

  • alb_transform (BasicTransform | None)

__add__(other)

Concatenate datasets.

__getitem__(index)

Get the item at the given index.

Parameters:

index (int) – Index of the item to return.

Returns:

A dictionary with the following keys:

  • ’image’ (Tensor): Tensor of shape (C, H, W) or (N, C, H, W), depending on self.return_frame_by_frame. If self.return_as_semantic_segmentation is True, the image is a tensor of shape (N, L, H, W) or (L, H, W), where L is the number of segmentation labels + 1 (background): L=len(self.segmentation_labels_set)+1.

  • ’metainfo’ (dict): Dictionary with metadata information.

  • ’segmentations’ (dict[str, list[Tensor]] or dict[str,Tensor] or Tensor): Segmentation masks, depending on the configuration of parameters self.return_segmentations, self.return_as_semantic_segmentation, self.return_frame_by_frame, self.semantic_seg_merge_strategy.

  • ’seg_labels’ (dict[str, list[Tensor]] or Tensor): Segmentation labels with the same length as segmentations.

  • ’frame_labels’ (dict[str, Tensor]): Frame-level labels.

  • ’image_labels’ (dict[str, Tensor]): Image-level labels.

Return type:

dict[str, Any]

__iter__()

Iterate over dataset items.

__len__()

Return dataset length.

Return type:

int

download_project()

Download project data from API.

Return type:

None

property frame_categories_set: list[tuple[str, str]]

Returns the set of categories in the dataset (multi-class tasks).

property frame_labels_set: list[str]

Returns the set of independent labels in the dataset (multi-label tasks).

get_annotations(index, type='all', scope='all')

Returns the annotations of the image at the given index.

Parameters:
  • index (int) – Index of the image.

  • type (Literal['label', 'category', 'segmentation', 'all']) – The type of the annotations. Can be ‘label’, ‘category’, ‘segmentation’ or ‘all’.

  • scope (Literal['frame', 'image', 'all']) – The scope of the annotations. Can be ‘frame’, ‘image’ or ‘all’.

Return type:

list[Annotation]

Returns:

The annotations of the image.

get_collate_fn()

Get collate function for DataLoader.

Return type:

Callable

get_dataloader(*args, **kwargs)

Returns a DataLoader for the dataset with proper collate function.

Parameters:
  • *args – Positional arguments for the DataLoader.

  • **kwargs – Keyword arguments for the DataLoader.

Return type:

DataLoader

Returns:

DataLoader instance with custom collate function.

get_framelabel_distribution(normalize=False)

Returns the distribution of frame labels in the dataset.

Parameters:

normalize (bool)

Return type:

dict[str, float]

get_info()

Get project information from API.

Return type:

dict

get_resources_ids()

Get list of resource IDs.

Return type:

list[str]

get_segmentationlabel_distribution(normalize=False)

Returns the distribution of segmentation labels in the dataset.

Parameters:

normalize (bool)

Return type:

dict[str, float]

property image_categories_set: list[tuple[str, str]]

Returns the set of categories in the dataset (multi-class tasks).

property image_labels_set: list[str]

Returns the set of independent labels in the dataset (multi-label tasks).

static read_number_of_frames(filepath)

Read the number of frames in a file.

Parameters:

filepath (str)

Return type:

int

property segmentation_labels_set: list[str]

Returns the set of segmentation labels in the dataset.

subset(indices)

Create a subset of the dataset.

Parameters:

indices (list[int]) – List of indices to include in the subset.

Return type:

DatamintBaseDataset

Returns:

Self with updated subset indices.

class datamint.dataset.base_dataset.DatamintBaseDataset(project_name, root=None, auto_update=True, api_key=None, server_url=None, return_dicom=False, return_metainfo=True, return_annotations=True, return_frame_by_frame=False, include_unannotated=True, all_annotations=False, include_annotators=None, exclude_annotators=None, include_segmentation_names=None, exclude_segmentation_names=None, include_image_label_names=None, exclude_image_label_names=None, include_frame_label_names=None, exclude_frame_label_names=None)

Class to download and load datasets from the Datamint API.

Parameters:
  • project_name (str) – Name of the project to download.

  • root (str | None) – Root directory of dataset where data already exists or will be downloaded.

  • auto_update (bool) – If True, the dataset will be checked for updates and downloaded if necessary.

  • api_key (str | None) – API key to access the Datamint API. If not provided, it will look for the environment variable ‘DATAMINT_API_KEY’. Not necessary if you don’t want to download/update the dataset.

  • return_dicom (bool) – If True, the DICOM object will be returned, if the image is a DICOM file.

  • return_metainfo (bool) – If True, the metainfo of the image will be returned.

  • return_annotations (bool) – If True, the annotations of the image will be returned.

  • return_frame_by_frame (bool) – If True, each frame of a video/DICOM/3d-image will be returned separately.

  • include_unannotated (bool) – If True, images without annotations will be included.

  • all_annotations (bool) – If True, all annotations will be downloaded, including the ones that are not set as closed/done.

  • server_url (str | None) – URL of the Datamint server. If not provided, it will use the default server.

  • include_annotators (list[str] | None) – List of annotators to include. If None, all annotators will be included.

  • exclude_annotators (list[str] | None) – List of annotators to exclude. If None, no annotators will be excluded.

  • include_segmentation_names (list[str] | None) – List of segmentation names to include. If None, all segmentations will be included.

  • exclude_segmentation_names (list[str] | None) – List of segmentation names to exclude. If None, no segmentations will be excluded.

  • include_image_label_names (list[str] | None) – List of image label names to include. If None, all image labels will be included.

  • exclude_image_label_names (list[str] | None) – List of image label names to exclude. If None, no image labels will be excluded.

  • include_frame_label_names (list[str] | None) – List of frame label names to include. If None, all frame labels will be included.

  • exclude_frame_label_names (list[str] | None) – List of frame label names to exclude. If None, no frame labels will be excluded.

__add__(other)

Concatenate datasets.

__getitem__(index)

Get item at index.

Parameters:

index (int) – Index

Return type:

dict[str, Tensor | FileDataset | dict | list]

Returns:

A dictionary containing ‘image’, ‘metainfo’ and ‘annotations’ keys.

__iter__()

Iterate over dataset items.

__len__()

Return dataset length.

Return type:

int

__repr__()

String representation of the dataset.

Return type:

str

download_project()

Download project data from API.

Return type:

None

property frame_categories_set: list[tuple[str, str]]

Returns the set of categories in the dataset (multi-class tasks).

property frame_labels_set: list[str]

Returns the set of independent labels in the dataset (multi-label tasks).

get_annotations(index, type='all', scope='all')

Returns the annotations of the image at the given index.

Parameters:
  • index (int) – Index of the image.

  • type (Literal['label', 'category', 'segmentation', 'all']) – The type of the annotations. Can be ‘label’, ‘category’, ‘segmentation’ or ‘all’.

  • scope (Literal['frame', 'image', 'all']) – The scope of the annotations. Can be ‘frame’, ‘image’ or ‘all’.

Return type:

list[Annotation]

Returns:

The annotations of the image.

get_collate_fn()

Get collate function for DataLoader.

Return type:

Callable

get_dataloader(*args, **kwargs)

Returns a DataLoader for the dataset with proper collate function.

Parameters:
  • *args – Positional arguments for the DataLoader.

  • **kwargs – Keyword arguments for the DataLoader.

Return type:

DataLoader

Returns:

DataLoader instance with custom collate function.

get_framelabel_distribution(normalize=False)

Returns the distribution of frame labels in the dataset.

Parameters:

normalize (bool)

Return type:

dict[str, float]

get_info()

Get project information from API.

Return type:

dict

get_resources_ids()

Get list of resource IDs.

Return type:

list[str]

get_segmentationlabel_distribution(normalize=False)

Returns the distribution of segmentation labels in the dataset.

Parameters:

normalize (bool)

Return type:

dict[str, float]

property image_categories_set: list[tuple[str, str]]

Returns the set of categories in the dataset (multi-class tasks).

property image_labels_set: list[str]

Returns the set of independent labels in the dataset (multi-label tasks).

static read_number_of_frames(filepath)

Read the number of frames in a file.

Parameters:

filepath (str)

Return type:

int

property segmentation_labels_set: list[str]

Returns the set of segmentation labels in the dataset.

subset(indices)

Create a subset of the dataset.

Parameters:

indices (list[int]) – List of indices to include in the subset.

Return type:

DatamintBaseDataset

Returns:

Self with updated subset indices.

exception datamint.dataset.base_dataset.DatamintDatasetException