Euniceyeee
commited on
Commit
•
db08881
1
Parent(s):
d205907
Upload kidney-ct-abnormality.py
Browse files- kidney-ct-abnormality.py +101 -0
kidney-ct-abnormality.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
from pathlib import Path
|
5 |
+
import os
|
6 |
+
|
7 |
+
_CITATION = """\
|
8 |
+
Alves, N., & Boulogne, L. (2023). Kidney CT Abnormality [Data set]. Zenodo. https://doi.org/10.5281/zenodo.8043408
|
9 |
+
"""
|
10 |
+
|
11 |
+
_DESCRIPTION = """\
|
12 |
+
This dataset in total is comprised of 986 .mha (medical high-resolution image) files. Each of these files contains multiple layers of CT scans of the kidney.
|
13 |
+
The dataset has been speparated into train and test set by initial processing.
|
14 |
+
|
15 |
+
"""
|
16 |
+
|
17 |
+
_HOMEPAGE = "https://zenodo.org/records/8043408"
|
18 |
+
|
19 |
+
_LICENSE = "CC BY-NC-SA 4.0"
|
20 |
+
|
21 |
+
_URL = "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality"
|
22 |
+
|
23 |
+
_URLS = {
|
24 |
+
'train': "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/train.zip",
|
25 |
+
'test': "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/test.zip"
|
26 |
+
}
|
27 |
+
|
28 |
+
_METADATA_URL = {
|
29 |
+
"meta": "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/dataset.csv"
|
30 |
+
}
|
31 |
+
|
32 |
+
LABELS = [
|
33 |
+
'Normal',
|
34 |
+
'Abnormal'
|
35 |
+
]
|
36 |
+
|
37 |
+
|
38 |
+
class KidneyCTAbnormality(datasets.GeneratorBasedBuilder):
|
39 |
+
"""Collection of brain xray images for fine-grain classification."""
|
40 |
+
|
41 |
+
VERSION = datasets.Version("1.0")
|
42 |
+
|
43 |
+
def _info(self):
|
44 |
+
return datasets.DatasetInfo(
|
45 |
+
description=_DESCRIPTION,
|
46 |
+
features=datasets.Features(
|
47 |
+
{
|
48 |
+
"image": datasets.Image(),
|
49 |
+
"label": datasets.ClassLabel(num_classes=2, names=LABELS),
|
50 |
+
}
|
51 |
+
),
|
52 |
+
supervised_keys=("image", "label"),
|
53 |
+
homepage=_HOMEPAGE,
|
54 |
+
citation=_CITATION,
|
55 |
+
license=_LICENSE,
|
56 |
+
citation=_CITATION
|
57 |
+
)
|
58 |
+
|
59 |
+
def _split_generators(self, dl_manager):
|
60 |
+
metadata_url = dl_manager.download(_METADATA_URL)
|
61 |
+
df_metadata = pd.read_csv(metadata_url)
|
62 |
+
files_metadata = {}
|
63 |
+
for _, row in df_metadata.iterrows():
|
64 |
+
split_value = row['split']
|
65 |
+
files_metadata.setdefault(split_value, [])
|
66 |
+
files_metadata[split_value].append(row.to_dict())
|
67 |
+
|
68 |
+
img_url = self._URLS
|
69 |
+
data_dir = dl_manager.download_and_extract(img_url)
|
70 |
+
print("Test"+data_dir)
|
71 |
+
|
72 |
+
return [
|
73 |
+
datasets.SplitGenerator(
|
74 |
+
name=datasets.Split.TRAIN,
|
75 |
+
gen_kwargs={
|
76 |
+
"filepath": data_dir['train'],
|
77 |
+
"meta": files_metadata["train"]
|
78 |
+
},
|
79 |
+
),
|
80 |
+
datasets.SplitGenerator(
|
81 |
+
name=datasets.Split.TEST,
|
82 |
+
gen_kwargs={
|
83 |
+
"filepath": data_dir['train'],
|
84 |
+
"meta": files_metadata["test"]
|
85 |
+
},
|
86 |
+
),
|
87 |
+
]
|
88 |
+
|
89 |
+
def _generate_examples(self, download_path, metadata):
|
90 |
+
"""Generate images and labels for splits."""
|
91 |
+
for i, meta in enumerate(metadata):
|
92 |
+
img_path = os.path.join(
|
93 |
+
download_path,
|
94 |
+
meta["split"],
|
95 |
+
meta["abnormality"],
|
96 |
+
meta["file_name"],
|
97 |
+
)
|
98 |
+
yield i, {
|
99 |
+
"image": img_path,
|
100 |
+
"label": meta["abnormality"],
|
101 |
+
}
|