import pathlib import datasets _DL_URL = "https://zenodo.org/record/1214456/files/" _BASE_URLS = { "CRC_VAL_HE_7K": f"{_DL_URL}/CRC-VAL-HE-7K.zip", "NCT_CRC_HE_100K": f"{_DL_URL}/NCT-CRC-HE-100K.zip", "NCT_CRC_HE_100K_NONORM": f"{_DL_URL}/NCT-CRC-HE-100K-NONORM.zip", } # _MD5_CHECKSUMS = { # "CRC_VAL_HE_7K": "2fd1651b4f94ebd818ebf90ad2b6ce06", # "NCT_CRC_HE_100K": "035777cf327776a71a05c95da6d6325f", # "NCT_CRC_HE_100K_NONORM": "6fd702d11df6292bc054397ae038a464", # } _HOMEPAGE = "https://zenodo.org/record/1214456" _DESCRIPTION = """ This is a set of non-overlapping image patches from hematoxylin & eosin (H&E) stained histological images of human colorectal cancer (CRC) and normal tissue. All images are 224x224 pixels (px) at 0.5 microns per pixel (MPP). All images are color-normalized using Macenko's method (http://ieeexplore.ieee.org/abstract/document/5193250/, DOI 10.1109/ISBI.2009.5193250). Tissue classes are: Adipose (ADI), background (BACK), debris (DEB), lymphocytes (LYM), mucus (MUC), smooth muscle (MUS), normal colon mucosa (NORM), cancer-associated stroma (STR), colorectal adenocarcinoma epithelium (TUM). These images were manually extracted from N=86 H&E stained human cancer tissue slides from formalin-fixed paraffin-embedded (FFPE) samples from the NCT Biobank (National Center for Tumor Diseases, Heidelberg, Germany) and the UMM pathology archive (University Medical Center Mannheim, Mannheim, Germany). Tissue samples contained CRC primary tumor slides and tumor tissue from CRC liver metastases; normal tissue classes were augmented with non-tumorous regions from gastrectomy specimen to increase variability. """ _LICENSE = "CC BY 4.0" _VERSION = datasets.Version("0.1.0") _CITATION = """ @dataset{kather_jakob_nikolas_2018_1214456, author = {Kather, Jakob Nikolas and Halama, Niels and Marx, Alexander}, title = {{100,000 histological images of human colorectal cancer and healthy tissue}}, month = apr, year = 2018, publisher = {Zenodo}, version = {v0.1}, doi = {10.5281/zenodo.1214456}, url = {https://doi.org/10.5281/zenodo.1214456} } """ _NAMES = [ "ADI", # Adipose "BACK", # Background "DEB", # Debris "LYM", # Lymphocytes "MUC", # Mucus "MUS", # Smooth muscle "NORM", # Normal colon mucosa "STR", # Cancer-associated stroma "TUM", # Colorectal adenocarcinoma epithelium ] class NCT_CRC_HE(datasets.GeneratorBasedBuilder): """NCT-CRC-HE (7k, 100k, 100k_nonorm) dataset.""" def _info(self): return datasets.DatasetInfo( homepage=_HOMEPAGE, description=_DESCRIPTION, citation=_CITATION, license=_LICENSE, version=_VERSION, features=datasets.Features( { "image": datasets.Image(), "label": datasets.ClassLabel(names=_NAMES), } ), supervised_keys=( "image", "label", ), task_templates=[ datasets.tasks.ImageClassification( image_column="image", label_column="label", ), ], ) def _split_generators(self, dl_manager): return [ datasets.SplitGenerator( name=datasets.NamedSplit(name), gen_kwargs={ "data_dir": dl_manager.download_and_extract(url) }, ) for name, url in _BASE_URLS.items() ] def _generate_examples(self, data_dir): """Generate images and labels for splits.""" tif_images = pathlib.Path(data_dir).rglob("*.tif") for index, filepath in enumerate(tif_images): yield index, { "image": str(filepath), "label": filepath.parent.name, }