Datasets:
Update fruits30.py
#1
by
VinayHajare
- opened
- fruits30.py +12 -11
fruits30.py
CHANGED
@@ -35,16 +35,17 @@ class fruits30(datasets.GeneratorBasedBuilder):
|
|
35 |
)
|
36 |
]
|
37 |
|
38 |
-
def _generate_examples(self,
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
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
|