File size: 3,147 Bytes
db08881 032959c db08881 dca1d91 db08881 105172e db08881 032959c db08881 f1def5e db08881 7309162 db08881 7309162 db08881 |
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 |
import datasets
import numpy as np
import pandas as pd
from pathlib import Path
import os
_CITATION = """\
Alves, N., & Boulogne, L. (2023). Kidney CT Abnormality [Data set]. Zenodo. https://doi.org/10.5281/zenodo.8043408
"""
_DESCRIPTION = """\
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.
The dataset has been speparated into train and test set by initial processing.
"""
_HOMEPAGE = "https://zenodo.org/records/8043408"
_LICENSE = "CC BY-NC-SA 4.0"
_URL = "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality"
_URLS = {
'train': "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/train.zip",
'test': "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/test.zip"
}
_METADATA_URL = {
"metadata": "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/dataset.csv"
}
LABELS = [
'Normal',
'Abnormal'
]
class KidneyCTAbnormality(datasets.GeneratorBasedBuilder):
"""Collection of brain xray images for fine-grain classification."""
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"image": datasets.Image(),
"label": datasets.ClassLabel(num_classes=2, names=LABELS),
}
),
supervised_keys=("image", "label"),
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE
)
def _split_generators(self, dl_manager):
metadata_url = dl_manager.download(_METADATA_URL)
df_metadata = pd.read_csv(metadata_url['metadata'])
files_metadata = {}
for _, row in df_metadata.iterrows():
split_value = row['split']
files_metadata.setdefault(split_value, [])
files_metadata[split_value].append(row.to_dict())
img_url = _URLS
data_dir = dl_manager.download_and_extract(img_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_dir['train'],
"metadata": files_metadata["train"]
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": data_dir['train'],
"metadata": files_metadata["test"]
},
),
]
def _generate_examples(self, download_path, metadata):
"""Generate images and labels for splits."""
for i, meta in enumerate(metadata):
img_path = os.path.join(
download_path,
meta["split"],
meta["abnormality"],
meta["file_name"],
)
yield i, {
"image": img_path,
"label": meta["abnormality"],
} |