alkzar90 commited on
Commit
7486ab9
1 Parent(s): 8419101

Add configurations

Browse files
Files changed (1) hide show
  1. 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 XChest(datasets.GeneratorBasedBuilder):
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  """NIH Image Chest X-ray dataset."""
94
 
95
- VERSION = datasets.Version("1.0.0")
 
 
 
 
 
96
 
97
  def _info(self):
98
- return datasets.DatasetInfo(
99
- description=_DESCRIPTION,
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
- supervised_keys=("image", "labels"),
 
 
 
 
 
111
  homepage=_HOMEPAGE,
112
  citation=_CITATION,
113
  )
@@ -156,17 +177,18 @@ class XChest(datasets.GeneratorBasedBuilder):
156
  ]
157
 
158
  def _generate_examples(self, files):
159
- # Read csv with image labels
160
- label_csv = read_csv(_URLS["labels"])
161
- for i, path in enumerate(files):
162
- file_name = os.path.basename(path)
163
- # Get image id to filter the respective row of the csv
164
- image_id = file_name.split('/')[-1]
165
- image_labels = label_csv[label_csv["Image Index"] == image_id]["Finding Labels"].values[0].split("|")
166
- if file_name.endswith(".png"):
167
- yield i, {
168
- "image_file_path": path,
169
- "image": path,
170
- "labels": image_labels,
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