Datasets:
Update plantsdataset.py
Browse files- plantsdataset.py +16 -17
plantsdataset.py
CHANGED
@@ -52,23 +52,22 @@ class PlantsDataset(GeneratorBasedBuilder):
|
|
52 |
]
|
53 |
|
54 |
def _generate_examples(self, data_folder):
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
}
|
72 |
|
73 |
def _display_image(self, image_path, label):
|
74 |
with Image.open(image_path) as img:
|
|
|
52 |
]
|
53 |
|
54 |
def _generate_examples(self, data_folder):
|
55 |
+
label_names = self.info.features['label'].names
|
56 |
+
for label, subfolder in enumerate(label_names):
|
57 |
+
subfolder_path = os.path.join(data_folder, subfolder)
|
58 |
+
for root, _, files in os.walk(subfolder_path):
|
59 |
+
for file_name in files:
|
60 |
+
file_path = os.path.join(root, file_name)
|
61 |
+
if os.path.isfile(file_path):
|
62 |
+
# Open the image using Pillow and convert it to an array
|
63 |
+
with Image.open(file_path) as image:
|
64 |
+
image_array = np.array(image)
|
65 |
+
|
66 |
+
# Yield the example with the image data and label
|
67 |
+
yield file_path, {
|
68 |
+
"image": image_array.tolist(), # Convert array to list
|
69 |
+
"label": label,
|
70 |
+
}
|
|
|
71 |
|
72 |
def _display_image(self, image_path, label):
|
73 |
with Image.open(image_path) as img:
|