"""LyNoS: Mediastinal lymph nodes segmentation using 3D convolutional neural network ensembles and anatomical priors guiding.""" import os import csv import json import datasets _DESCRIPTION = """\ LyNoS: Mediastinal lymph nodes segmentation using 3D convolutional neural network ensembles and anatomical priors guiding. """ _HOMEPAGE = "https://github.com/raidionics/LyNoS" _LICENSE = "MIT" _CITATION = """\ @article{bouget2023mediastinal, title={Mediastinal lymph nodes segmentation using 3D convolutional neural network ensembles and anatomical priors guiding}, author={Bouget, David and Pedersen, Andr{\'e} and Vanel, Johanna and Leira, Haakon O and Lang{\o}, Thomas}, journal={Computer Methods in Biomechanics and Biomedical Engineering: Imaging \& Visualization}, volume={11}, number={1}, pages={44--58}, year={2023}, publisher={Taylor \& Francis} } """ _URLS = {"zenodo": "https://zenodo.org/records/10102261/files/LyNoS.zip?download=1"} class LyNoS(datasets.GeneratorBasedBuilder): """A segmentation benchmark dataset for enlarged lymph nodes in patients with primary lung cancer.""" VERSION = datasets.Version("1.0.0") DEFAULT_CONFIG_NAME = "zenodo" BUILDER_CONFIGS = [ datasets.BuilderConfig(name="zenodo", version=VERSION, description="This includes all 15 CTs stored as a single zip on Zenodo"), ] DEFAULT_CONFIG_NAME = "zenodo" # It's not mandatory to have a default configuration. Just use one if it make sense. def __init__(self, **kwargs): super().__init__(**kwargs) self.DATA_DIR = None def get_patient(self, patient_id): if (patient_id < 1) or (patiend_id > 15): raise ValueError("patient_id should be an integer in range [1, 15].") def _info(self): # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset if self.config.name == "zenodo": # This is the name of the configuration selected in BUILDER_CONFIGS above features = datasets.Features( { "ct": datasets.Value("string"), "lymphnodes": datasets.Value("string"), "azygos": datasets.Value("string"), "brachiocephalicveins": datasets.Value("string"), "esophagus": datasets.Value("string"), "subclaviancarotidarteries": datasets.Value("string") } ) else: raise ValueError("Only 'zenodo' is supported.")# This is an example to show how to have different features for "first_domain" and "second_domain" return datasets.DatasetInfo( # This is the description that will appear on the datasets page. description=_DESCRIPTION, # This defines the different columns of the dataset and their types features=features, # Here we define them above because they are different between the two configurations # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and # specify them. They'll be used if as_supervised=True in builder.as_dataset. # supervised_keys=("sentence", "label"), # Homepage of the dataset for documentation homepage=_HOMEPAGE, # License for the dataset if available license=_LICENSE, # Citation for the dataset citation=_CITATION, ) def get_data_dir(self): return self.DATA_DIR def _split_generators(self, dl_manager): # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files. # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive urls = _URLS[self.config.name] self.DATA_DIR = dl_manager.download_and_extract(urls) # append AeroPath self.DATA_DIR = os.path.join(self.DATA_DIR, "Benchmark") print("data is downloaded to:", self.DATA_DIR) return [ datasets.SplitGenerator( name=datasets.Split.TEST, # These kwargs will be passed to _generate_examples gen_kwargs={ "split": "test", }, ), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, split): # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset. # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. for patient_id in os.listdir(self.DATA_DIR): curr_path = os.path.join(self.DATA_DIR, patient_id) if patient_id in ["README.md", "license.md", "stations_sto.csv"]: continue yield patient_id, { "ct": os.path.join(curr_path, patient_id.lower() + "_data.nii.gz"), "lymphnodes": os.path.join(curr_path, patient_id.lower() + "_labels_LymphNodes.nii.gz"), "azygos": os.path.join(curr_path, patient_id.lower() + "_labels_Azygos.nii.gz"), "brachiocephalicveins": os.path.join(curr_path, patient_id.lower() + "_labels_BrachiocephalicVeins.nii.gz"), "esophagus": os.path.join(curr_path, patient_id.lower() + "_labels_Esophagus.nii.gz"), "subclaviancarotidarteries": os.path.join(curr_path, patient_id.lower() + "_labels_SubCarArt.nii.gz") }