File size: 3,541 Bytes
db08881 4d0199a 429652c db08881 0953b46 db08881 72de623 db08881 dbbdc21 db08881 dca1d91 db08881 105172e db08881 4c55b42 dbbdc21 db08881 fba824b db08881 bbb7264 7309162 db08881 bbb7264 7309162 db08881 0b4c22c db08881 72de623 db08881 f659003 bba4e00 92cfc82 064ce07 db08881 429652c a952f1c db08881 9d93645 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 99 100 101 102 103 104 105 106 |
import datasets
import numpy as np
import pandas as pd
from pathlib import Path
import os
import json
import SimpleITK as sitk
_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"
# }
_URLS = {
'kidney_CT': 'https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/kidney_ct/kidney_CT.zip'
}
_METADATA_URL = {
"metadata": "https://huggingface.co/datasets/Euniceyeee/kidney-ct-abnormality/resolve/main/dataset_m.json"
}
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)
files_metadata = {}
with open(metadata_url["metadata"], encoding="utf-8") as f:
for lines in f.read().splitlines():
file_json_metdata = json.loads(lines)
files_metadata.setdefault(file_json_metdata["split"], []).append(file_json_metdata)
# data_dir = dl_manager.download(_URLS)
downloaded_files = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": downloaded_files['kidney_CT'],
"metadata": files_metadata["train"]
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": downloaded_files['kidney_CT'],
"metadata": files_metadata["test"]
},
),
]
def _generate_examples(self, filepath, metadata):
"""Generate images and labels for splits."""
print(filepath)
for i, meta in enumerate(metadata):
img_path = os.path.join(
filepath,
'kidney_CT',
meta['split'],
meta["image"]
)
img = sitk.ReadImage(img_path)
img_array = sitk.GetArrayFromImage(img)
img_array_c = img_array.astype('uint8')
yield i, {
"image": img_array_c,
"label": meta["abnormality"],
} |