File size: 3,644 Bytes
8f8e26e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b0b5f4
 
8f8e26e
9b0b5f4
 
784696a
8f8e26e
 
 
 
 
 
 
 
 
 
 
c52b098
346edb8
8f8e26e
 
 
 
99d504e
8f8e26e
 
 
 
 
ee635f1
 
 
 
 
 
8f8e26e
ee635f1
 
 
8f8e26e
 
 
 
 
 
 
aebe23b
 
8f8e26e
fa61cd4
cf9bea6
c49b949
8f8e26e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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