Files changed (1) hide show
  1. fruits30.py +12 -11
fruits30.py CHANGED
@@ -35,16 +35,17 @@ class fruits30(datasets.GeneratorBasedBuilder):
35
  )
36
  ]
37
 
38
- def _generate_examples(self, archives, split):
39
- """Yields examples."""
40
- idx = 0
41
- for archive in archives:
42
- for path, file in archive:
43
- if path.endswith(".JPG"):
44
- # image filepath format: <IMAGE_FILENAME>_<SYNSET_ID>.JPEG
45
- root, _ = os.path.splitext(path)
46
- _, synset_id = os.path.basename(root).rsplit("_", 1)
47
- label = FRUITS30_CLASSES[synset_id]
48
- ex = {"image": {"path": path, "bytes": file.read()}, "label": label}
 
49
  yield idx, ex
50
  idx += 1
 
35
  )
36
  ]
37
 
38
+ def _generate_examples(self, data_dir, split):
39
+ """Yields examples."""
40
+ idx = 0
41
+ for root, dirs, files in os.walk(data_dir):
42
+ for file in files:
43
+ if file.endswith(".JPG"):
44
+ # Image file path format: <IMAGE_FILENAME>_<SYNSET_ID>.JPEG
45
+ _, synset_id = os.path.splitext(file)[0].rsplit("_", 1)
46
+ label = FRUITS30_CLASSES[synset_id]
47
+ image_path = os.path.join(root, file)
48
+ with open(image_path, "rb") as image_file:
49
+ ex = {"image": {"path": image_path, "bytes": image_file.read()}, "label": label}
50
  yield idx, ex
51
  idx += 1