|
import datasets |
|
import numpy as np |
|
import pandas as pd |
|
import hickle as hkl |
|
from pathlib import Path |
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {rsna-atd}, |
|
author = {Yeow Zi Qin}, |
|
year = {2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The dataset is the processed version of Kaggle Competition: RSNA 2023 Abdominal Trauma Detection. |
|
It comprises of segmentation of 205 series of CT scans with 5 classes (liver, spleen, right_kidney, |
|
left_kidney, bowel). |
|
""" |
|
|
|
_NAME = "rsna-atd" |
|
|
|
_HOMEPAGE = f"https://huggingface.co/datasets/ziq/{_NAME}" |
|
|
|
_LICENSE = "MIT" |
|
|
|
_DATA = f"https://huggingface.co/datasets/ziq/{_NAME}/resolve/main/data/" |
|
|
|
|
|
class RSNAATD(datasets.GeneratorBasedBuilder): |
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
|
|
"patient_id": datasets.Value("int64"), |
|
"series_id": datasets.Value("int64"), |
|
"image_path": datasets.Value("string"), |
|
"mask_path": datasets.Value("string"), |
|
|
|
|
|
"aortic_hu": datasets.Value("float64"), |
|
"incomplete_organ": datasets.Value("int64"), |
|
"bowel_healthy": datasets.Value("int64"), |
|
"bowel_injury": datasets.Value("int64"), |
|
"extravasation_healthy": datasets.Value("int64"), |
|
"extravasation_injury": datasets.Value("int64"), |
|
"kidney_healthy": datasets.Value("int64"), |
|
"kidney_low": datasets.Value("int64"), |
|
"kidney_high": datasets.Value("int64"), |
|
"liver_healthy": datasets.Value("int64"), |
|
"liver_low": datasets.Value("int64"), |
|
"liver_high": datasets.Value("int64"), |
|
"spleen_healthy": datasets.Value("int64"), |
|
"spleen_low": datasets.Value("int64"), |
|
"spleen_high": datasets.Value("int64"), |
|
"any_injury": datasets.Value("int64"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
train_images = dl_manager.download_and_extract(f"{_DATA}images.zip") |
|
train_masks = dl_manager.download_and_extract(f"{_DATA}masks.zip") |
|
|
|
metadata = dl_manager.download(f"{_DATA}metadata.csv") |
|
train_images = dl_manager.iter_files(train_images) |
|
train_masks = dl_manager.iter_files(train_masks) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"images": train_images, |
|
"masks": train_masks, |
|
"metadata": metadata, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, images, masks, metadata): |
|
df = pd.read_csv(metadata) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for idx, (image_path, mask_path) in enumerate(zip(sorted(images), sorted(masks))): |
|
data = df.loc[df["path"] == Path(image_path).name].to_numpy()[0] |
|
|
|
( |
|
patient_id, |
|
series_id, |
|
aortic_hu, |
|
incomplete_organ, |
|
bowel_healthy, |
|
bowel_injury, |
|
extravasation_healthy, |
|
extravasation_injury, |
|
kidney_healthy, |
|
kidney_low, |
|
kidney_high, |
|
liver_healthy, |
|
liver_low, |
|
liver_high, |
|
spleen_healthy, |
|
spleen_low, |
|
spleen_high, |
|
any_injury, |
|
) = data[1:] |
|
|
|
yield idx, { |
|
"patient_id": patient_id, |
|
"series_id": series_id, |
|
"image_path": image_path, |
|
"mask_path": mask_path, |
|
"aortic_hu": aortic_hu, |
|
"incomplete_organ": incomplete_organ, |
|
"bowel_healthy": bowel_healthy, |
|
"bowel_injury": bowel_injury, |
|
"extravasation_healthy": extravasation_healthy, |
|
"extravasation_injury": extravasation_injury, |
|
"kidney_healthy": kidney_healthy, |
|
"kidney_low": kidney_low, |
|
"kidney_high": kidney_high, |
|
"liver_healthy": liver_healthy, |
|
"liver_low": liver_low, |
|
"liver_high": liver_high, |
|
"spleen_healthy": spleen_healthy, |
|
"spleen_low": spleen_low, |
|
"spleen_high": spleen_high, |
|
"any_injury": any_injury, |
|
} |
|
|