alkzar90 commited on
Commit
8b7ba21
1 Parent(s): 16efcee

Read csv file and get the label for each image id

Browse files
Files changed (1) hide show
  1. NIH-Chest-X-ray-dataset.py +6 -1
NIH-Chest-X-ray-dataset.py CHANGED
@@ -143,15 +143,20 @@ class XChest(datasets.GeneratorBasedBuilder):
143
  ]
144
 
145
  def _generate_examples(self, files):
 
 
146
  for i, path in enumerate(files):
147
  file_name = os.path.basename(path)
 
 
148
  if file_name.endswith(".png"):
149
  yield i, {
150
  "image_file_path": path,
151
  "image": path,
152
  #"labels": ["Mass", "Hernia"]
153
  #"labels": [5, 14]
154
- "labels": "Mass"
 
155
  #"multi-labels": list(map(int, [_LABEL2IDX[x] for x in ["Mass", "Hernia"]))
156
  }
157
 
 
143
  ]
144
 
145
  def _generate_examples(self, files):
146
+ # Read csv with image labels
147
+ label_csv = read_csv(_URLS['labels'])
148
  for i, path in enumerate(files):
149
  file_name = os.path.basename(path)
150
+ # Get image id to filter the respective row of the csv
151
+ image_id = file_name.split('/')[-1]
152
  if file_name.endswith(".png"):
153
  yield i, {
154
  "image_file_path": path,
155
  "image": path,
156
  #"labels": ["Mass", "Hernia"]
157
  #"labels": [5, 14]
158
+ #"labels": "Mass"
159
+ "labels": label_csv[label_csv['Image Index'] == image_id, 'Finding labels'].str.split('|')[0]
160
  #"multi-labels": list(map(int, [_LABEL2IDX[x] for x in ["Mass", "Hernia"]))
161
  }
162