torch_em.data.datasets.medical.dap_atlas

The DAP Atlas dataset contains annotations for 142 anatomical structures in whole-body CT scans.

The dataset consists of automatically generated (and post-processed with anatomical guidelines) dense anatomical label volumes for 533 CT scans of the AutoPET dataset. The label volumes are distributed via the DAP Atlas repository, the CT scans are the (original resolution) 'CT.nii.gz' volumes of the AutoPET dataset, which is downloaded via torch_em.data.datasets.medical.autopet. The names of the label volumes ('AutoPET__') uniquely identify the matching AutoPET CT. NOTE: The AutoPET download is ~300 GB, but it is shared with the AutoPET dataset (see autopet_path).

The label id of each structure is given in CLASS_IDS (see also the table in the appendix of the publication). The label ids are: 1: left to annotate (unlabeled placeholder), 2: muscles, 3: fat, 4: abdominal tissue, 5: mediastinal tissue, 6: esophagus, 7: stomach, 8: small bowel, 9: duodenum, 10: colon, 11: rectum, 12: gallbladder, 13: liver, 14: pancreas, 15: kidney left, 16: kidney right, 17: bladder, 18: gonads, 19: prostate, 20: uterocervix, 21: uterus, 22: breast left, 23: breast right, 24: spinal canal, 25: brain, 26: spleen, 27: adrenal gland left, 28: adrenal gland right, 29: thyroid left, 30: thyroid right, 31: thymus, 32-37: gluteus maximus / medius / minimus (left, right), 38-39: iliopsoas (left, right), 40-41: autochthon (left, right), 42: skin, 43-66: vertebrae C1-L5, 67-90: costa 1-12 (left, right), 91: rib cartilage, 92: sternum corpus, 93-94: clavicula (left, right), 95-96: scapula (left, right), 97-98: humerus (left, right), 99: skull, 100-101: hip (left, right), 102: sacrum, 103-104: femur (left, right), 105: heart, 106: heart atrium left, 107: heart tissue, 108: heart atrium right, 109: heart myocardium, 110: heart ventricle left, 111: heart ventricle right, 112-113: iliac artery (left, right), 114: aorta, 115-116: iliac vena (left, right), 117: inferior vena cava, 118: portal vein and splenic vein, 119: celiac trunk, 120-124: lung lobes, 125: bronchus, 126: trachea, 127: pulmonary artery, 128-129: cheek (left, right), 130-131: eyeball (left, right), 132: nasal cavity, 133-134: common carotid artery (right, left), 135: sternum manubrium, 136-137: internal carotid artery (right, left), 138-139: internal jugular vein (right, left), 140: brachiocephalic artery, 141-142: brachiocephalic vein (right, left), 143-144: subclavian artery (right, left).

The dataset is located at https://github.com/alexanderjaus/AtlasDataset.

This dataset is from the publication https://doi.org/10.48550/arXiv.2307.13375. Please cite it (and the AutoPET publication https://doi.org/10.1038/s41597-022-01718-3) if you use this dataset in your research.

  1"""The DAP Atlas dataset contains annotations for 142 anatomical structures in whole-body CT scans.
  2
  3The dataset consists of automatically generated (and post-processed with anatomical guidelines) dense anatomical
  4label volumes for 533 CT scans of the AutoPET dataset. The label volumes are distributed via the DAP Atlas repository,
  5the CT scans are the (original resolution) 'CT.nii.gz' volumes of the AutoPET dataset, which is downloaded via
  6`torch_em.data.datasets.medical.autopet`. The names of the label volumes ('AutoPET_<subject id>_<last 5 digits of
  7the study uid>') uniquely identify the matching AutoPET CT.
  8NOTE: The AutoPET download is ~300 GB, but it is shared with the AutoPET dataset (see `autopet_path`).
  9
 10The label id of each structure is given in `CLASS_IDS` (see also the table in the appendix of the publication).
 11The label ids are: 1: left to annotate (unlabeled placeholder), 2: muscles, 3: fat, 4: abdominal tissue,
 125: mediastinal tissue, 6: esophagus, 7: stomach, 8: small bowel, 9: duodenum, 10: colon, 11: rectum, 12: gallbladder,
 1313: liver, 14: pancreas, 15: kidney left, 16: kidney right, 17: bladder, 18: gonads, 19: prostate, 20: uterocervix,
 1421: uterus, 22: breast left, 23: breast right, 24: spinal canal, 25: brain, 26: spleen, 27: adrenal gland left,
 1528: adrenal gland right, 29: thyroid left, 30: thyroid right, 31: thymus, 32-37: gluteus maximus / medius / minimus
 16(left, right), 38-39: iliopsoas (left, right), 40-41: autochthon (left, right), 42: skin, 43-66: vertebrae C1-L5,
 1767-90: costa 1-12 (left, right), 91: rib cartilage, 92: sternum corpus, 93-94: clavicula (left, right),
 1895-96: scapula (left, right), 97-98: humerus (left, right), 99: skull, 100-101: hip (left, right), 102: sacrum,
 19103-104: femur (left, right), 105: heart, 106: heart atrium left, 107: heart tissue, 108: heart atrium right,
 20109: heart myocardium, 110: heart ventricle left, 111: heart ventricle right, 112-113: iliac artery (left, right),
 21114: aorta, 115-116: iliac vena (left, right), 117: inferior vena cava, 118: portal vein and splenic vein,
 22119: celiac trunk, 120-124: lung lobes, 125: bronchus, 126: trachea, 127: pulmonary artery,
 23128-129: cheek (left, right),
 24130-131: eyeball (left, right), 132: nasal cavity, 133-134: common carotid artery (right, left),
 25135: sternum manubrium, 136-137: internal carotid artery (right, left), 138-139: internal jugular vein (right, left),
 26140: brachiocephalic artery, 141-142: brachiocephalic vein (right, left), 143-144: subclavian artery (right, left).
 27
 28The dataset is located at https://github.com/alexanderjaus/AtlasDataset.
 29
 30This dataset is from the publication https://doi.org/10.48550/arXiv.2307.13375.
 31Please cite it (and the AutoPET publication https://doi.org/10.1038/s41597-022-01718-3) if you use this dataset
 32in your research.
 33"""
 34
 35import os
 36from glob import glob
 37from warnings import warn
 38from natsort import natsorted
 39from typing import Union, Tuple, List, Optional
 40
 41from torch.utils.data import Dataset, DataLoader
 42
 43import torch_em
 44
 45from .. import util
 46from .autopet import get_autopet_data
 47
 48
 49URL = "https://drive.google.com/uc?id=1ex0a9eQULLvKPDwijmijX2h49A-ockNy"
 50CHECKSUM = "eea8b7bf2378a5085bc4ef7014bb4d764c9e276a6d8c8a55add19e9bb2b80622"
 51
 52CLASS_NAMES = [
 53    "left_to_annotate", "muscles", "fat", "abdominal_tissue", "mediastinal_tissue", "esophagus", "stomach",
 54    "small_bowel", "duodenum", "colon", "rectum", "gallbladder", "liver", "pancreas", "kidney_left", "kidney_right",
 55    "bladder", "gonads", "prostate", "uterocervix", "uterus", "breast_left", "breast_right", "spinal_canal", "brain",
 56    "spleen", "adrenal_gland_left", "adrenal_gland_right", "thyroid_left", "thyroid_right", "thymus",
 57    "gluteus_maximus_left", "gluteus_maximus_right", "gluteus_medius_left", "gluteus_medius_right",
 58    "gluteus_minimus_left", "gluteus_minimus_right", "iliopsoas_left", "iliopsoas_right", "autochthon_left",
 59    "autochthon_right", "skin", "vertebrae_C1", "vertebrae_C2", "vertebrae_C3", "vertebrae_C4", "vertebrae_C5",
 60    "vertebrae_C6", "vertebrae_C7", "vertebrae_T1", "vertebrae_T2", "vertebrae_T3", "vertebrae_T4", "vertebrae_T5",
 61    "vertebrae_T6", "vertebrae_T7", "vertebrae_T8", "vertebrae_T9", "vertebrae_T10", "vertebrae_T11", "vertebrae_T12",
 62    "vertebrae_L1", "vertebrae_L2", "vertebrae_L3", "vertebrae_L4", "vertebrae_L5", "costa_1_left", "costa_1_right",
 63    "costa_2_left", "costa_2_right", "costa_3_left", "costa_3_right", "costa_4_left", "costa_4_right", "costa_5_left",
 64    "costa_5_right", "costa_6_left", "costa_6_right", "costa_7_left", "costa_7_right", "costa_8_left", "costa_8_right",
 65    "costa_9_left", "costa_9_right", "costa_10_left", "costa_10_right", "costa_11_left", "costa_11_right",
 66    "costa_12_left", "costa_12_right", "rib_cartilage", "sternum_corpus", "clavicula_left", "clavicula_right",
 67    "scapula_left", "scapula_right", "humerus_left", "humerus_right", "skull", "hip_left", "hip_right", "sacrum",
 68    "femur_left", "femur_right", "heart", "heart_atrium_left", "heart_tissue", "heart_atrium_right",
 69    "heart_myocardium", "heart_ventricle_left", "heart_ventricle_right", "iliac_artery_left", "iliac_artery_right",
 70    "aorta", "iliac_vena_left", "iliac_vena_right", "inferior_vena_cava", "portal_vein_and_splenic_vein",
 71    "celiac_trunk", "lung_lower_lobe_left", "lung_upper_lobe_left", "lung_lower_lobe_right", "lung_middle_lobe_right",
 72    "lung_upper_lobe_right", "bronchus", "trachea", "pulmonary_artery", "cheek_left", "cheek_right", "eyeball_left",
 73    "eyeball_right", "nasal_cavity", "common_carotid_artery_right", "common_carotid_artery_left", "sternum_manubrium",
 74    "internal_carotid_artery_right", "internal_carotid_artery_left", "internal_jugular_vein_right",
 75    "internal_jugular_vein_left", "brachiocephalic_artery", "brachiocephalic_vein_right", "brachiocephalic_vein_left",
 76    "subclavian_artery_right", "subclavian_artery_left",
 77]
 78"""The classes of the DAP Atlas dataset. The label id of a class is its 1-based index."""
 79
 80CLASS_IDS = {name: i + 1 for i, name in enumerate(CLASS_NAMES)}
 81"""Mapping from the class name to its label id in the label volumes."""
 82
 83
 84def get_dap_atlas_data(
 85    path: Union[os.PathLike, str], autopet_path: Optional[Union[os.PathLike, str]] = None, download: bool = False
 86) -> Tuple[str, str]:
 87    """Download the DAP Atlas dataset.
 88
 89    Args:
 90        path: Filepath to a folder where the data is downloaded for further processing.
 91        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
 92            By default, it is downloaded to the 'autopet' sub-folder of `path`.
 93        download: Whether to download the data if it is not present.
 94
 95    Returns:
 96        Filepath where the label volumes are downloaded.
 97        Filepath where the AutoPET data is downloaded.
 98    """
 99    if autopet_path is None:
100        autopet_path = os.path.join(path, "autopet")
101    get_autopet_data(autopet_path, download)
102
103    label_dir = os.path.join(path, "Atlas_final_dataset_V1_533")
104    if not os.path.exists(label_dir):
105        os.makedirs(path, exist_ok=True)
106        zip_path = os.path.join(path, "dap_atlas_masks.zip")
107        util.download_source_gdrive(path=zip_path, url=URL, download=download, checksum=CHECKSUM)
108        util.unzip(zip_path=zip_path, dst=path, remove=False)
109
110    return label_dir, autopet_path
111
112
113def get_dap_atlas_paths(
114    path: Union[os.PathLike, str], autopet_path: Optional[Union[os.PathLike, str]] = None, download: bool = False
115) -> Tuple[List[str], List[str]]:
116    """Get paths to the DAP Atlas data.
117
118    Args:
119        path: Filepath to a folder where the data is downloaded for further processing.
120        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
121            By default, it is downloaded to the 'autopet' sub-folder of `path`.
122        download: Whether to download the data if it is not present.
123
124    Returns:
125        List of filepaths for the image data.
126        List of filepaths for the label data.
127    """
128    label_dir, autopet_path = get_dap_atlas_data(path, autopet_path, download)
129
130    # Match each label volume 'AutoPET_<subject id>_<study suffix>.nii.gz' to the CT in the AutoPET study folder
131    # 'PETCT_<subject id>/<study description>-<study suffix>/CT.nii.gz'.
132    autopet_dir = os.path.join(autopet_path, "AutoPET-II", "FDG-PET-CT-Lesions")
133    raw_paths, label_paths, missing = [], [], []
134    for label_path in natsorted(glob(os.path.join(label_dir, "AutoPET_*.nii.gz"))):
135        _, subject_id, study_suffix = os.path.basename(label_path)[:-len(".nii.gz")].split("_")
136        ct_paths = glob(os.path.join(autopet_dir, f"PETCT_{subject_id}", f"*-{study_suffix}", "CT.nii.gz"))
137        if len(ct_paths) > 1:
138            raise RuntimeError(f"Found multiple AutoPET CTs for '{label_path}': {ct_paths}.")
139        if not ct_paths:  # The AutoPET download is incomplete, so this case is skipped.
140            missing.append(os.path.basename(label_path))
141            continue
142        raw_paths.append(ct_paths[0])
143        label_paths.append(label_path)
144
145    if missing:
146        warn(f"Could not find the AutoPET CT for {len(missing)} of {len(missing) + len(raw_paths)} label volumes. "
147             f"These cases are skipped. Is the AutoPET data in '{autopet_path}' complete?")
148
149    if not raw_paths:
150        raise RuntimeError(f"Could not match any DAP Atlas label volume to an AutoPET CT in '{autopet_path}'.")
151
152    assert len(raw_paths) == len(label_paths)
153    return raw_paths, label_paths
154
155
156def get_dap_atlas_dataset(
157    path: Union[os.PathLike, str],
158    patch_shape: Tuple[int, ...],
159    autopet_path: Optional[Union[os.PathLike, str]] = None,
160    resize_inputs: bool = False,
161    download: bool = False,
162    **kwargs
163) -> Dataset:
164    """Get the DAP Atlas dataset for anatomical structure segmentation in whole-body CT.
165
166    Args:
167        path: Filepath to a folder where the data is downloaded for further processing.
168        patch_shape: The patch shape to use for training.
169        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
170            By default, it is downloaded to the 'autopet' sub-folder of `path`.
171        resize_inputs: Whether to resize inputs to the desired patch shape.
172        download: Whether to download the data if it is not present.
173        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`.
174
175    Returns:
176        The segmentation dataset.
177    """
178    raw_paths, label_paths = get_dap_atlas_paths(path, autopet_path, download)
179
180    if resize_inputs:
181        resize_kwargs = {"patch_shape": patch_shape, "is_rgb": False}
182        kwargs, patch_shape = util.update_kwargs_for_resize_trafo(
183            kwargs=kwargs, patch_shape=patch_shape, resize_inputs=resize_inputs, resize_kwargs=resize_kwargs
184        )
185
186    return torch_em.default_segmentation_dataset(
187        raw_paths=raw_paths,
188        raw_key="data",
189        label_paths=label_paths,
190        label_key="data",
191        patch_shape=patch_shape,
192        is_seg_dataset=True,
193        **kwargs
194    )
195
196
197def get_dap_atlas_loader(
198    path: Union[os.PathLike, str],
199    batch_size: int,
200    patch_shape: Tuple[int, ...],
201    autopet_path: Optional[Union[os.PathLike, str]] = None,
202    resize_inputs: bool = False,
203    download: bool = False,
204    **kwargs
205) -> DataLoader:
206    """Get the DAP Atlas dataloader for anatomical structure segmentation in whole-body CT.
207
208    Args:
209        path: Filepath to a folder where the data is downloaded for further processing.
210        batch_size: The batch size for training.
211        patch_shape: The patch shape to use for training.
212        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
213            By default, it is downloaded to the 'autopet' sub-folder of `path`.
214        resize_inputs: Whether to resize inputs to the desired patch shape.
215        download: Whether to download the data if it is not present.
216        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader.
217
218    Returns:
219        The DataLoader.
220    """
221    ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs)
222    dataset = get_dap_atlas_dataset(path, patch_shape, autopet_path, resize_inputs, download, **ds_kwargs)
223    return torch_em.get_data_loader(dataset, batch_size, **loader_kwargs)
URL = 'https://drive.google.com/uc?id=1ex0a9eQULLvKPDwijmijX2h49A-ockNy'
CHECKSUM = 'eea8b7bf2378a5085bc4ef7014bb4d764c9e276a6d8c8a55add19e9bb2b80622'
CLASS_NAMES = ['left_to_annotate', 'muscles', 'fat', 'abdominal_tissue', 'mediastinal_tissue', 'esophagus', 'stomach', 'small_bowel', 'duodenum', 'colon', 'rectum', 'gallbladder', 'liver', 'pancreas', 'kidney_left', 'kidney_right', 'bladder', 'gonads', 'prostate', 'uterocervix', 'uterus', 'breast_left', 'breast_right', 'spinal_canal', 'brain', 'spleen', 'adrenal_gland_left', 'adrenal_gland_right', 'thyroid_left', 'thyroid_right', 'thymus', 'gluteus_maximus_left', 'gluteus_maximus_right', 'gluteus_medius_left', 'gluteus_medius_right', 'gluteus_minimus_left', 'gluteus_minimus_right', 'iliopsoas_left', 'iliopsoas_right', 'autochthon_left', 'autochthon_right', 'skin', 'vertebrae_C1', 'vertebrae_C2', 'vertebrae_C3', 'vertebrae_C4', 'vertebrae_C5', 'vertebrae_C6', 'vertebrae_C7', 'vertebrae_T1', 'vertebrae_T2', 'vertebrae_T3', 'vertebrae_T4', 'vertebrae_T5', 'vertebrae_T6', 'vertebrae_T7', 'vertebrae_T8', 'vertebrae_T9', 'vertebrae_T10', 'vertebrae_T11', 'vertebrae_T12', 'vertebrae_L1', 'vertebrae_L2', 'vertebrae_L3', 'vertebrae_L4', 'vertebrae_L5', 'costa_1_left', 'costa_1_right', 'costa_2_left', 'costa_2_right', 'costa_3_left', 'costa_3_right', 'costa_4_left', 'costa_4_right', 'costa_5_left', 'costa_5_right', 'costa_6_left', 'costa_6_right', 'costa_7_left', 'costa_7_right', 'costa_8_left', 'costa_8_right', 'costa_9_left', 'costa_9_right', 'costa_10_left', 'costa_10_right', 'costa_11_left', 'costa_11_right', 'costa_12_left', 'costa_12_right', 'rib_cartilage', 'sternum_corpus', 'clavicula_left', 'clavicula_right', 'scapula_left', 'scapula_right', 'humerus_left', 'humerus_right', 'skull', 'hip_left', 'hip_right', 'sacrum', 'femur_left', 'femur_right', 'heart', 'heart_atrium_left', 'heart_tissue', 'heart_atrium_right', 'heart_myocardium', 'heart_ventricle_left', 'heart_ventricle_right', 'iliac_artery_left', 'iliac_artery_right', 'aorta', 'iliac_vena_left', 'iliac_vena_right', 'inferior_vena_cava', 'portal_vein_and_splenic_vein', 'celiac_trunk', 'lung_lower_lobe_left', 'lung_upper_lobe_left', 'lung_lower_lobe_right', 'lung_middle_lobe_right', 'lung_upper_lobe_right', 'bronchus', 'trachea', 'pulmonary_artery', 'cheek_left', 'cheek_right', 'eyeball_left', 'eyeball_right', 'nasal_cavity', 'common_carotid_artery_right', 'common_carotid_artery_left', 'sternum_manubrium', 'internal_carotid_artery_right', 'internal_carotid_artery_left', 'internal_jugular_vein_right', 'internal_jugular_vein_left', 'brachiocephalic_artery', 'brachiocephalic_vein_right', 'brachiocephalic_vein_left', 'subclavian_artery_right', 'subclavian_artery_left']

The classes of the DAP Atlas dataset. The label id of a class is its 1-based index.

CLASS_IDS = {'left_to_annotate': 1, 'muscles': 2, 'fat': 3, 'abdominal_tissue': 4, 'mediastinal_tissue': 5, 'esophagus': 6, 'stomach': 7, 'small_bowel': 8, 'duodenum': 9, 'colon': 10, 'rectum': 11, 'gallbladder': 12, 'liver': 13, 'pancreas': 14, 'kidney_left': 15, 'kidney_right': 16, 'bladder': 17, 'gonads': 18, 'prostate': 19, 'uterocervix': 20, 'uterus': 21, 'breast_left': 22, 'breast_right': 23, 'spinal_canal': 24, 'brain': 25, 'spleen': 26, 'adrenal_gland_left': 27, 'adrenal_gland_right': 28, 'thyroid_left': 29, 'thyroid_right': 30, 'thymus': 31, 'gluteus_maximus_left': 32, 'gluteus_maximus_right': 33, 'gluteus_medius_left': 34, 'gluteus_medius_right': 35, 'gluteus_minimus_left': 36, 'gluteus_minimus_right': 37, 'iliopsoas_left': 38, 'iliopsoas_right': 39, 'autochthon_left': 40, 'autochthon_right': 41, 'skin': 42, 'vertebrae_C1': 43, 'vertebrae_C2': 44, 'vertebrae_C3': 45, 'vertebrae_C4': 46, 'vertebrae_C5': 47, 'vertebrae_C6': 48, 'vertebrae_C7': 49, 'vertebrae_T1': 50, 'vertebrae_T2': 51, 'vertebrae_T3': 52, 'vertebrae_T4': 53, 'vertebrae_T5': 54, 'vertebrae_T6': 55, 'vertebrae_T7': 56, 'vertebrae_T8': 57, 'vertebrae_T9': 58, 'vertebrae_T10': 59, 'vertebrae_T11': 60, 'vertebrae_T12': 61, 'vertebrae_L1': 62, 'vertebrae_L2': 63, 'vertebrae_L3': 64, 'vertebrae_L4': 65, 'vertebrae_L5': 66, 'costa_1_left': 67, 'costa_1_right': 68, 'costa_2_left': 69, 'costa_2_right': 70, 'costa_3_left': 71, 'costa_3_right': 72, 'costa_4_left': 73, 'costa_4_right': 74, 'costa_5_left': 75, 'costa_5_right': 76, 'costa_6_left': 77, 'costa_6_right': 78, 'costa_7_left': 79, 'costa_7_right': 80, 'costa_8_left': 81, 'costa_8_right': 82, 'costa_9_left': 83, 'costa_9_right': 84, 'costa_10_left': 85, 'costa_10_right': 86, 'costa_11_left': 87, 'costa_11_right': 88, 'costa_12_left': 89, 'costa_12_right': 90, 'rib_cartilage': 91, 'sternum_corpus': 92, 'clavicula_left': 93, 'clavicula_right': 94, 'scapula_left': 95, 'scapula_right': 96, 'humerus_left': 97, 'humerus_right': 98, 'skull': 99, 'hip_left': 100, 'hip_right': 101, 'sacrum': 102, 'femur_left': 103, 'femur_right': 104, 'heart': 105, 'heart_atrium_left': 106, 'heart_tissue': 107, 'heart_atrium_right': 108, 'heart_myocardium': 109, 'heart_ventricle_left': 110, 'heart_ventricle_right': 111, 'iliac_artery_left': 112, 'iliac_artery_right': 113, 'aorta': 114, 'iliac_vena_left': 115, 'iliac_vena_right': 116, 'inferior_vena_cava': 117, 'portal_vein_and_splenic_vein': 118, 'celiac_trunk': 119, 'lung_lower_lobe_left': 120, 'lung_upper_lobe_left': 121, 'lung_lower_lobe_right': 122, 'lung_middle_lobe_right': 123, 'lung_upper_lobe_right': 124, 'bronchus': 125, 'trachea': 126, 'pulmonary_artery': 127, 'cheek_left': 128, 'cheek_right': 129, 'eyeball_left': 130, 'eyeball_right': 131, 'nasal_cavity': 132, 'common_carotid_artery_right': 133, 'common_carotid_artery_left': 134, 'sternum_manubrium': 135, 'internal_carotid_artery_right': 136, 'internal_carotid_artery_left': 137, 'internal_jugular_vein_right': 138, 'internal_jugular_vein_left': 139, 'brachiocephalic_artery': 140, 'brachiocephalic_vein_right': 141, 'brachiocephalic_vein_left': 142, 'subclavian_artery_right': 143, 'subclavian_artery_left': 144}

Mapping from the class name to its label id in the label volumes.

def get_dap_atlas_data( path: Union[os.PathLike, str], autopet_path: Union[os.PathLike, str, NoneType] = None, download: bool = False) -> Tuple[str, str]:
 85def get_dap_atlas_data(
 86    path: Union[os.PathLike, str], autopet_path: Optional[Union[os.PathLike, str]] = None, download: bool = False
 87) -> Tuple[str, str]:
 88    """Download the DAP Atlas dataset.
 89
 90    Args:
 91        path: Filepath to a folder where the data is downloaded for further processing.
 92        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
 93            By default, it is downloaded to the 'autopet' sub-folder of `path`.
 94        download: Whether to download the data if it is not present.
 95
 96    Returns:
 97        Filepath where the label volumes are downloaded.
 98        Filepath where the AutoPET data is downloaded.
 99    """
100    if autopet_path is None:
101        autopet_path = os.path.join(path, "autopet")
102    get_autopet_data(autopet_path, download)
103
104    label_dir = os.path.join(path, "Atlas_final_dataset_V1_533")
105    if not os.path.exists(label_dir):
106        os.makedirs(path, exist_ok=True)
107        zip_path = os.path.join(path, "dap_atlas_masks.zip")
108        util.download_source_gdrive(path=zip_path, url=URL, download=download, checksum=CHECKSUM)
109        util.unzip(zip_path=zip_path, dst=path, remove=False)
110
111    return label_dir, autopet_path

Download the DAP Atlas dataset.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded. By default, it is downloaded to the 'autopet' sub-folder of path.
  • download: Whether to download the data if it is not present.
Returns:

Filepath where the label volumes are downloaded. Filepath where the AutoPET data is downloaded.

def get_dap_atlas_paths( path: Union[os.PathLike, str], autopet_path: Union[os.PathLike, str, NoneType] = None, download: bool = False) -> Tuple[List[str], List[str]]:
114def get_dap_atlas_paths(
115    path: Union[os.PathLike, str], autopet_path: Optional[Union[os.PathLike, str]] = None, download: bool = False
116) -> Tuple[List[str], List[str]]:
117    """Get paths to the DAP Atlas data.
118
119    Args:
120        path: Filepath to a folder where the data is downloaded for further processing.
121        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
122            By default, it is downloaded to the 'autopet' sub-folder of `path`.
123        download: Whether to download the data if it is not present.
124
125    Returns:
126        List of filepaths for the image data.
127        List of filepaths for the label data.
128    """
129    label_dir, autopet_path = get_dap_atlas_data(path, autopet_path, download)
130
131    # Match each label volume 'AutoPET_<subject id>_<study suffix>.nii.gz' to the CT in the AutoPET study folder
132    # 'PETCT_<subject id>/<study description>-<study suffix>/CT.nii.gz'.
133    autopet_dir = os.path.join(autopet_path, "AutoPET-II", "FDG-PET-CT-Lesions")
134    raw_paths, label_paths, missing = [], [], []
135    for label_path in natsorted(glob(os.path.join(label_dir, "AutoPET_*.nii.gz"))):
136        _, subject_id, study_suffix = os.path.basename(label_path)[:-len(".nii.gz")].split("_")
137        ct_paths = glob(os.path.join(autopet_dir, f"PETCT_{subject_id}", f"*-{study_suffix}", "CT.nii.gz"))
138        if len(ct_paths) > 1:
139            raise RuntimeError(f"Found multiple AutoPET CTs for '{label_path}': {ct_paths}.")
140        if not ct_paths:  # The AutoPET download is incomplete, so this case is skipped.
141            missing.append(os.path.basename(label_path))
142            continue
143        raw_paths.append(ct_paths[0])
144        label_paths.append(label_path)
145
146    if missing:
147        warn(f"Could not find the AutoPET CT for {len(missing)} of {len(missing) + len(raw_paths)} label volumes. "
148             f"These cases are skipped. Is the AutoPET data in '{autopet_path}' complete?")
149
150    if not raw_paths:
151        raise RuntimeError(f"Could not match any DAP Atlas label volume to an AutoPET CT in '{autopet_path}'.")
152
153    assert len(raw_paths) == len(label_paths)
154    return raw_paths, label_paths

Get paths to the DAP Atlas data.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded. By default, it is downloaded to the 'autopet' sub-folder of path.
  • download: Whether to download the data if it is not present.
Returns:

List of filepaths for the image data. List of filepaths for the label data.

def get_dap_atlas_dataset( path: Union[os.PathLike, str], patch_shape: Tuple[int, ...], autopet_path: Union[os.PathLike, str, NoneType] = None, resize_inputs: bool = False, download: bool = False, **kwargs) -> torch.utils.data.dataset.Dataset:
157def get_dap_atlas_dataset(
158    path: Union[os.PathLike, str],
159    patch_shape: Tuple[int, ...],
160    autopet_path: Optional[Union[os.PathLike, str]] = None,
161    resize_inputs: bool = False,
162    download: bool = False,
163    **kwargs
164) -> Dataset:
165    """Get the DAP Atlas dataset for anatomical structure segmentation in whole-body CT.
166
167    Args:
168        path: Filepath to a folder where the data is downloaded for further processing.
169        patch_shape: The patch shape to use for training.
170        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
171            By default, it is downloaded to the 'autopet' sub-folder of `path`.
172        resize_inputs: Whether to resize inputs to the desired patch shape.
173        download: Whether to download the data if it is not present.
174        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset`.
175
176    Returns:
177        The segmentation dataset.
178    """
179    raw_paths, label_paths = get_dap_atlas_paths(path, autopet_path, download)
180
181    if resize_inputs:
182        resize_kwargs = {"patch_shape": patch_shape, "is_rgb": False}
183        kwargs, patch_shape = util.update_kwargs_for_resize_trafo(
184            kwargs=kwargs, patch_shape=patch_shape, resize_inputs=resize_inputs, resize_kwargs=resize_kwargs
185        )
186
187    return torch_em.default_segmentation_dataset(
188        raw_paths=raw_paths,
189        raw_key="data",
190        label_paths=label_paths,
191        label_key="data",
192        patch_shape=patch_shape,
193        is_seg_dataset=True,
194        **kwargs
195    )

Get the DAP Atlas dataset for anatomical structure segmentation in whole-body CT.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • patch_shape: The patch shape to use for training.
  • autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded. By default, it is downloaded to the 'autopet' sub-folder of path.
  • resize_inputs: Whether to resize inputs to the desired patch shape.
  • download: Whether to download the data if it is not present.
  • kwargs: Additional keyword arguments for torch_em.default_segmentation_dataset.
Returns:

The segmentation dataset.

def get_dap_atlas_loader( path: Union[os.PathLike, str], batch_size: int, patch_shape: Tuple[int, ...], autopet_path: Union[os.PathLike, str, NoneType] = None, resize_inputs: bool = False, download: bool = False, **kwargs) -> torch.utils.data.dataloader.DataLoader:
198def get_dap_atlas_loader(
199    path: Union[os.PathLike, str],
200    batch_size: int,
201    patch_shape: Tuple[int, ...],
202    autopet_path: Optional[Union[os.PathLike, str]] = None,
203    resize_inputs: bool = False,
204    download: bool = False,
205    **kwargs
206) -> DataLoader:
207    """Get the DAP Atlas dataloader for anatomical structure segmentation in whole-body CT.
208
209    Args:
210        path: Filepath to a folder where the data is downloaded for further processing.
211        batch_size: The batch size for training.
212        patch_shape: The patch shape to use for training.
213        autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded.
214            By default, it is downloaded to the 'autopet' sub-folder of `path`.
215        resize_inputs: Whether to resize inputs to the desired patch shape.
216        download: Whether to download the data if it is not present.
217        kwargs: Additional keyword arguments for `torch_em.default_segmentation_dataset` or for the PyTorch DataLoader.
218
219    Returns:
220        The DataLoader.
221    """
222    ds_kwargs, loader_kwargs = util.split_kwargs(torch_em.default_segmentation_dataset, **kwargs)
223    dataset = get_dap_atlas_dataset(path, patch_shape, autopet_path, resize_inputs, download, **ds_kwargs)
224    return torch_em.get_data_loader(dataset, batch_size, **loader_kwargs)

Get the DAP Atlas dataloader for anatomical structure segmentation in whole-body CT.

Arguments:
  • path: Filepath to a folder where the data is downloaded for further processing.
  • batch_size: The batch size for training.
  • patch_shape: The patch shape to use for training.
  • autopet_path: Filepath to the folder where the AutoPET dataset is (or will be) downloaded. By default, it is downloaded to the 'autopet' sub-folder of path.
  • resize_inputs: Whether to resize inputs to the desired patch shape.
  • download: Whether to download the data if it is not present.
  • kwargs: Additional keyword arguments for torch_em.default_segmentation_dataset or for the PyTorch DataLoader.
Returns:

The DataLoader.