NCTCRCHE100K / NCTCRCHE100K.py
DykeF's picture
Update NCTCRCHE100K.py
784696a
# coding=utf-8
# Lint as: python3
"""NCTCRCHE100K: ... """
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
Kather, Jakob Nikolas, Halama, Niels, & Marx, Alexander. (2018). 100,000 histological images of human colorectal cancer and healthy tissue (v0.1) [Data set]. Zenodo. https://doi.org/10.5281/zenodo.1214456"""
_DESCRIPTION = """\
This is a set of 100,000 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.
"""
_BASE = "https://huggingface.co/datasets/DykeF/NCTCRCHE100K/resolve/main/"
_URLS = {
"train": _BASE + "NCT-CRC-HE-100K.tar.gz",
"train_nonorm": _BASE + "NCT-CRC-HE-100K-NONORM.tar.gz",
"val": _BASE + "CRC-VAL-HE-7K.tar.gz",
}
class NCTCRCHE100K(datasets.GeneratorBasedBuilder):
"""NCTCRCHE100K: 100,000 histological images of human colorectal cancer and healthy tissue"""
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"image": datasets.Image(),
"label": datasets.Value("string"),
"file": datasets.Value("string"),
}
),
supervised_keys=None,
homepage="https://huggingface.co/datasets/DykeF/NCTCRCHE100K",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download(_URLS)
image_iters_train_norm = dl_manager.iter_archive(downloaded_files["train"])
image_iters_train_nonorm = dl_manager.iter_archive(downloaded_files["train_nonorm"])
image_iters_val = dl_manager.iter_archive(downloaded_files["val"])
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"images": image_iters_train_norm}),
datasets.SplitGenerator(name="train_nonorm", gen_kwargs={"images": image_iters_train_nonorm}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"images": image_iters_val}),
]
def _generate_examples(self, images):
"""This function returns the samples in (image, label) form"""
idx = 0
for filepath, image in images:
# extract text from each item
start_index = filepath.find('/') + 1
end_index = filepath.find('-', start_index)
yield idx, {
"image": {"path": filepath, "bytes": image.read()},
"label": filepath[start_index: end_index],
"file": filepath[start_index:]
}
idx += 1