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)

__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]

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

Returns the set of categories in the dataset. This is more related to multi-class tasks.

property frame_labels_set: list[str]

Returns the set of independent labels in the dataset. This is more related to 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 (str) – The type of the annotations. It can be ‘label’, ‘category’, ‘segmentation’ or ‘all’.

  • scope (str) – The scope of the annotations. It can be ‘frame’, ‘image’ or ‘all’.

Returns:

The annotations of the image.

Return type:

List[Dict]

get_dataloader(*args, **kwargs)

Returns a DataLoader for the dataset. This is a wrapper around the PyTorch DataLoader, with the convinience of using a nice collate_fn that properly handles the different types of data in this dataset.

Parameters:
Return type:

DataLoader

get_framelabel_distribution(normalize=False)

Returns the distribution of labels in the dataset.

Returns:

The distribution of labels in the dataset.

Return type:

Dict[str, int]

get_segmentationlabel_distribution(normalize=False)

Returns the distribution of segmentation labels in the dataset.

Returns:

The distribution of segmentation labels in the dataset.

Return type:

Dict[str, int]

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

Returns the set of categories in the dataset. This is more related to multi-class tasks.

property image_labels_set: list[str]

Returns the set of independent labels in the dataset. This is more related to multi-label tasks.

property segmentation_labels_set: list[str]

Returns the set of segmentation labels in the dataset.

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:
  • 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.

  • 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.

__getitem__(index)
Parameters:

index (int) – Index

Returns:

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

Return type:

dict

__repr__()
Return type:

str

Example

print(dataset)

Output:

Dataset DatamintDataset
    Number of datapoints: 3
    Root location: /home/user/.datamint/datasets
property frame_categories_set: list[tuple[str, str]]

Returns the set of categories in the dataset. This is more related to multi-class tasks.

property frame_labels_set: list[str]

Returns the set of independent labels in the dataset. This is more related to 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 (str) – The type of the annotations. It can be ‘label’, ‘category’, ‘segmentation’ or ‘all’.

  • scope (str) – The scope of the annotations. It can be ‘frame’, ‘image’ or ‘all’.

Returns:

The annotations of the image.

Return type:

List[Dict]

get_dataloader(*args, **kwargs)

Returns a DataLoader for the dataset. This is a wrapper around the PyTorch DataLoader, with the convinience of using a nice collate_fn that properly handles the different types of data in this dataset.

Parameters:
Return type:

DataLoader

get_framelabel_distribution(normalize=False)

Returns the distribution of labels in the dataset.

Returns:

The distribution of labels in the dataset.

Return type:

Dict[str, int]

get_segmentationlabel_distribution(normalize=False)

Returns the distribution of segmentation labels in the dataset.

Returns:

The distribution of segmentation labels in the dataset.

Return type:

Dict[str, int]

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

Returns the set of categories in the dataset. This is more related to multi-class tasks.

property image_labels_set: list[str]

Returns the set of independent labels in the dataset. This is more related to multi-label tasks.

property segmentation_labels_set: list[str]

Returns the set of segmentation labels in the dataset.

exception datamint.dataset.base_dataset.DatamintDatasetException