|
import datasets |
|
import pandas as pd |
|
|
|
_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( |
|
{ |
|
"image_path": datasets.Value("string"), |
|
"mask_path": datasets.Value("string") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
train_images = dl_manager.download(f"{_DATA}images.tar.gz") |
|
train_masks = dl_manager.download(f"{_DATA}masks.tar.gz") |
|
|
|
metadata = dl_manager.download(f"{_DATA}metadata.csv") |
|
train_images = dl_manager.iter_archive(train_images) |
|
train_masks = dl_manager.iter_archive(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(images, masks)): |
|
|
|
|
|
yield idx, { |
|
"image_path": image_path, |
|
"mask_path": mask_path |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|