frgfm commited on
Commit
8553c95
1 Parent(s): 503071a

fix: Fixed preview

Browse files
Files changed (1) hide show
  1. imagenette.py +8 -9
imagenette.py CHANGED
@@ -112,26 +112,25 @@ class OpenFire(datasets.GeneratorBasedBuilder):
112
  def _split_generators(self, dl_manager):
113
  archive_path = dl_manager.download(self.config.data_url)
114
  local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
 
115
  return [
116
  datasets.SplitGenerator(
117
  name=datasets.Split.TRAIN,
118
  gen_kwargs={
119
- "image_folder": os.path.join(local_extracted_archive, "train"),
120
- "split": "train",
121
  },
122
  ),
123
  datasets.SplitGenerator(
124
  name=datasets.Split.VALIDATION,
125
  gen_kwargs={
126
- "image_folder": os.path.join(local_extracted_archive, "val"),
127
- "split": "validation",
128
  },
129
  ),
130
  ]
131
 
132
- def _generate_examples(self, image_folder, split):
133
  idx = 0
134
- for class_idx, class_folder in _LABEL_MAP:
135
- for filepath in os.listdir(class_folder):
136
- yield idx, {"image": os.path.join(image_folder, class_folder, filepath), "label": class_idx}
137
- idx += 1
 
112
  def _split_generators(self, dl_manager):
113
  archive_path = dl_manager.download(self.config.data_url)
114
  local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
115
+ archive_iters = {l: dl_manager.iter_archive(v) for l, v in archive_path.items()}
116
  return [
117
  datasets.SplitGenerator(
118
  name=datasets.Split.TRAIN,
119
  gen_kwargs={
120
+ "archive_iter": archive_iters["train"],
 
121
  },
122
  ),
123
  datasets.SplitGenerator(
124
  name=datasets.Split.VALIDATION,
125
  gen_kwargs={
126
+ "archive_iter": archive_iters["val"],
 
127
  },
128
  ),
129
  ]
130
 
131
+ def _generate_examples(self, archive_iter):
132
  idx = 0
133
+ for path, f in archive_iter:
134
+ class_idx = _LABEL_MAP.index(path.split("/")[-2])
135
+ yield idx, {"image": path, "label": class_idx}
136
+ idx += 1