Ziyuan111 commited on
Commit
eb0a703
1 Parent(s): d33477c

Update plantsdataset.py

Browse files
Files changed (1) hide show
  1. plantsdataset.py +16 -17
plantsdataset.py CHANGED
@@ -52,23 +52,22 @@ class PlantsDataset(GeneratorBasedBuilder):
52
  ]
53
 
54
  def _generate_examples(self, data_folder):
55
- """Yields examples as (key, example) tuples."""
56
- label_names = self.info.features['label'].names
57
- for label, subfolder in enumerate(label_names):
58
- subfolder_path = os.path.join(data_folder, subfolder)
59
- for root, _, files in os.walk(subfolder_path):
60
- for file_name in files:
61
- file_path = os.path.join(root, file_name)
62
- if os.path.isfile(file_path):
63
- # Open the image using Pillow and convert it to an array
64
- with Image.open(file_path) as image:
65
- image_array = np.array(image)
66
-
67
- # Yield the example with the image data and label
68
- yield file_path, {
69
- "image": image_array.tolist(), # Convert array to list
70
- "label": label,
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: