File size: 3,953 Bytes
331d34f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa1e405
331d34f
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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,
            }