kidney-ct-abnormality / kidney-ct-abnormality.py
Euniceyeee's picture
Update kidney-ct-abnormality.py
dca1d91 verified
raw
history blame
3.16 kB
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 = {
"meta": "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)
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 = self._URLS
data_dir = dl_manager.download_and_extract(img_url)
print("Test"+data_dir)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_dir['train'],
"meta": files_metadata["train"]
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": data_dir['train'],
"meta": 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"],
}