lhoestq HF staff commited on
Commit
be82797
1 Parent(s): e7ec57d

Fix the way it reads the file name

Browse files

On unix, you can indeed split the '/' to get the filename as the last item in the list.
On Windows, the separator may be a '\' so this doesn't work.
In streaming mode, URLs may look like 'zip://data/file.txt::https://foo.bar.data.zip' so this doesn't work either.

I fixed it by using `os.path.basename`, which works on Unix and Windows, and which `datasets` extends to also work with chained URLs.

Files changed (1) hide show
  1. NIH-Chest-X-ray-dataset.py +2 -2
NIH-Chest-X-ray-dataset.py CHANGED
@@ -186,7 +186,7 @@ class ChestXray14(datasets.GeneratorBasedBuilder):
186
  logger.info(f"Batch for data_files: {batch}")
187
  path_files = dl_manager.iter_files(batch)
188
  for img in path_files:
189
- if img.split('/')[-1] in train_val_list:
190
  train_files.append(img)
191
  else:
192
  test_files.append(img)
@@ -215,7 +215,7 @@ class ChestXray14(datasets.GeneratorBasedBuilder):
215
  for i, path in enumerate(files):
216
  file_name = os.path.basename(path)
217
  # Get image id to filter the respective row of the csv
218
- image_id = file_name.split('/')[-1]
219
  image_labels = label_csv[label_csv["Image Index"] == image_id]["Finding Labels"].values[0].split("|")
220
  if file_name.endswith(".png"):
221
  yield i, {
 
186
  logger.info(f"Batch for data_files: {batch}")
187
  path_files = dl_manager.iter_files(batch)
188
  for img in path_files:
189
+ if os.path.basename(img) in train_val_list:
190
  train_files.append(img)
191
  else:
192
  test_files.append(img)
 
215
  for i, path in enumerate(files):
216
  file_name = os.path.basename(path)
217
  # Get image id to filter the respective row of the csv
218
+ image_id = file_name
219
  image_labels = label_csv[label_csv["Image Index"] == image_id]["Finding Labels"].values[0].split("|")
220
  if file_name.endswith(".png"):
221
  yield i, {