Datasets:
Tasks:
Image Classification
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
100K<n<1M
ArXiv:
License:
Add configurations
Browse files- NIH-Chest-X-ray-dataset.py +43 -21
NIH-Chest-X-ray-dataset.py
CHANGED
@@ -89,25 +89,46 @@ _LABEL2IDX = {"No Finding": 0,
|
|
89 |
_NAMES = list(_LABEL2IDX.keys())
|
90 |
|
91 |
|
92 |
-
class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
"""NIH Image Chest X-ray dataset."""
|
94 |
|
95 |
-
VERSION = datasets.Version("1.0.0")
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
def _info(self):
|
98 |
-
|
99 |
-
|
100 |
-
features=datasets.Features(
|
101 |
{
|
102 |
-
"image_file_path": datasets.Value("string"),
|
103 |
"image": datasets.Image(),
|
104 |
"labels": datasets.features.Sequence(
|
105 |
datasets.features.ClassLabel(num_classes=len(_NAMES),
|
106 |
names=_NAMES)
|
107 |
)
|
108 |
}
|
109 |
-
)
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
111 |
homepage=_HOMEPAGE,
|
112 |
citation=_CITATION,
|
113 |
)
|
@@ -156,17 +177,18 @@ class XChest(datasets.GeneratorBasedBuilder):
|
|
156 |
]
|
157 |
|
158 |
def _generate_examples(self, files):
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
172 |
|
|
|
89 |
_NAMES = list(_LABEL2IDX.keys())
|
90 |
|
91 |
|
92 |
+
class ChestXray14Config(datasets.BuilderConfig):
|
93 |
+
"""allala"""
|
94 |
+
|
95 |
+
def __init__(self, name, **kwargs):
|
96 |
+
super(ChestXray14Config, self).__init__(
|
97 |
+
version=datasets.Version("1.0.0"),
|
98 |
+
name=name,
|
99 |
+
description="NIH ChestX-ray14",
|
100 |
+
**kwargs,
|
101 |
+
)
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
class ChestXray14(datasets.GeneratorBasedBuilder):
|
106 |
"""NIH Image Chest X-ray dataset."""
|
107 |
|
108 |
+
#VERSION = datasets.Version("1.0.0")
|
109 |
+
|
110 |
+
BUILDER_CONFIGS = [
|
111 |
+
ChestXray14Config("image-classification"),
|
112 |
+
ChestXray14Config("object-detection"),
|
113 |
+
]
|
114 |
|
115 |
def _info(self):
|
116 |
+
if self.config.name == "image-cllassification":
|
117 |
+
features = datasets.Features(
|
|
|
118 |
{
|
|
|
119 |
"image": datasets.Image(),
|
120 |
"labels": datasets.features.Sequence(
|
121 |
datasets.features.ClassLabel(num_classes=len(_NAMES),
|
122 |
names=_NAMES)
|
123 |
)
|
124 |
}
|
125 |
+
)
|
126 |
+
keys = ("image", "labels")
|
127 |
+
|
128 |
+
return datasets.DatasetInfo(
|
129 |
+
description=_DESCRIPTION,
|
130 |
+
features=features,
|
131 |
+
supervised_keys=keys,
|
132 |
homepage=_HOMEPAGE,
|
133 |
citation=_CITATION,
|
134 |
)
|
|
|
177 |
]
|
178 |
|
179 |
def _generate_examples(self, files):
|
180 |
+
|
181 |
+
if sef.config.name == "image-classification":
|
182 |
+
# Read csv with image labels
|
183 |
+
label_csv = read_csv(_URLS["labels"])
|
184 |
+
for i, path in enumerate(files):
|
185 |
+
file_name = os.path.basename(path)
|
186 |
+
# Get image id to filter the respective row of the csv
|
187 |
+
image_id = file_name.split('/')[-1]
|
188 |
+
image_labels = label_csv[label_csv["Image Index"] == image_id]["Finding Labels"].values[0].split("|")
|
189 |
+
if file_name.endswith(".png"):
|
190 |
+
yield i, {
|
191 |
+
"image": path,
|
192 |
+
"labels": image_labels,
|
193 |
+
}
|
194 |
|