ziq commited on
Commit
21bfe6f
·
1 Parent(s): 9a182e7

Create rsna-atd.py

Browse files
Files changed (1) hide show
  1. rsna-atd.py +95 -0
rsna-atd.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pandas as pd
3
+
4
+ _CITATION = """\
5
+ @InProceedings{huggingface:dataset,
6
+ title = {rsna-atd},
7
+ author = {Yeow Zi Qin},
8
+ year = {2023}
9
+ }
10
+ """
11
+
12
+ _DESCRIPTION = """\
13
+ The dataset is the processed version of Kaggle Competition: RSNA 2023 Abdominal Trauma Detection.
14
+ It comprises of segmentation of 205 series of CT scans with 5 classes (liver, spleen, right_kidney,
15
+ left_kidney, bowel).
16
+ """
17
+
18
+ _NAME = "rsna-atd"
19
+
20
+ _HOMEPAGE = f"https://huggingface.co/datasets/ziq/{_NAME}"
21
+
22
+ _LICENSE = "MIT"
23
+
24
+ _DATA = f"https://huggingface.co/datasets/ziq/{_NAME}/resolve/main/data/"
25
+
26
+
27
+ class RSNAATD(datasets.GeneratorBasedBuilder):
28
+ def _info(self):
29
+ return datasets.DatasetInfo(
30
+ description=_DESCRIPTION,
31
+ features=datasets.Features(
32
+ {
33
+ "image_path": datasets.Value("string"),
34
+ "mask_path": datasets.Value("string")
35
+ # "patient_id": datasets.Value("int64"),
36
+ # "series_id": datasets.Value("int64"),
37
+ # "aortic_hu": datasets.Value("float64"),
38
+ # "incomplete_organ": datasets.Value("int64"),
39
+ # "bowel_healthy": datasets.Value("int64"),
40
+ # "bowel_injury": datasets.Value("int64"),
41
+ # "extravasation_healthy": datasets.Value("int64"),
42
+ # "extravasation_injury": datasets.Value("int64"),
43
+ # "kidney_healthy": datasets.Value("int64"),
44
+ # "kidney_low": datasets.Value("int64"),
45
+ # "kidney_high": datasets.Value("int64"),
46
+ # "liver_healthy": datasets.Value("int64"),
47
+ # "liver_low": datasets.Value("int64"),
48
+ # "liver_high": datasets.Value("int64"),
49
+ # "spleen_healthy": datasets.Value("int64"),
50
+ # "spleen_low": datasets.Value("int64"),
51
+ # "spleen_high": datasets.Value("int64"),
52
+ # "any_injury": datasets.Value("int64"),
53
+ # "image": datasets.Array3D(shape=(None, 512, 512)),
54
+ # "mask": datasets.Array3D(shape=(None, 512, 512)),
55
+ }
56
+ ),
57
+ supervised_keys=None,
58
+ homepage=_HOMEPAGE,
59
+ citation=_CITATION,
60
+ )
61
+
62
+ def _split_generators(self, dl_manager):
63
+ train_images = dl_manager.download(f"{_DATA}images.tar.gz")
64
+ train_masks = dl_manager.download(f"{_DATA}masks.tar.gz")
65
+
66
+ metadata = dl_manager.download(f"{_DATA}metadata.csv")
67
+ train_images = dl_manager.iter_archive(train_images)
68
+ train_masks = dl_manager.iter_archive(train_masks)
69
+
70
+ return [
71
+ datasets.SplitGenerator(
72
+ name=datasets.Split.TRAIN,
73
+ gen_kwargs={
74
+ "images": train_images,
75
+ "masks": train_masks,
76
+ "metadata": metadata,
77
+ },
78
+ ),
79
+ ]
80
+
81
+ def _generate_examples(self, images, masks, metadata):
82
+ df = pd.read_csv(metadata)
83
+
84
+ for idx, ((image_path), (mask_path)) in enumerate(zip(images, masks)):
85
+ row = df.loc[df["path"] == image_path.lower().replace("images/", "")]
86
+
87
+ yield idx, {
88
+ "image_path": image_path,
89
+ "mask_path": mask_path
90
+ # "patient_id": row["patient_id"].values[0],
91
+ # "series_id": row["series_id"].values[0],
92
+ # "frame_id": row["frame_id"].values[0],
93
+ # "image": {"path": image_path, "bytes": image.read()},
94
+ # "mask": {"path": mask_path, "bytes": mask.read()},
95
+ }