XintongHe commited on
Commit
78737b1
·
verified ·
1 Parent(s): ee683e8

Update Populus_Stomatal_Images_Datasets.py

Browse files
Files changed (1) hide show
  1. Populus_Stomatal_Images_Datasets.py +8 -11
Populus_Stomatal_Images_Datasets.py CHANGED
@@ -168,7 +168,7 @@ class NewDataset(datasets.GeneratorBasedBuilder):
168
  return annotations
169
 
170
  def _generate_examples(self, filepaths, species_info, data_dir):
171
- """Yields examples as (key, example) tuples."""
172
  for file_name in filepaths:
173
  image_id = os.path.splitext(file_name)[0] # Extract the base name without the file extension
174
  image_path = os.path.join(data_dir, f"{image_id}.jpg")
@@ -179,19 +179,15 @@ class NewDataset(datasets.GeneratorBasedBuilder):
179
  if not species_row.empty:
180
  species = species_row['Species'].values[0]
181
  scientific_name = species_row['ScientificName'].values[0]
182
- width = species_row['Witdh'].values[0]
183
- height = species_row['Heigth'].values[0]
184
  else:
185
- # Default values if not found
186
- species = None
187
- scientific_name = None
188
- width = 1024 # Default value
189
- height = 768 # Default value
190
-
191
- pics_array = None
192
  with Image.open(image_path) as img:
193
  pics_array = np.array(img).tolist() # Convert the PIL image to a numpy array and then to a list
194
-
195
  annotations = self._parse_yolo_labels(label_path, width, height)
196
 
197
  # Yield the dataset example
@@ -203,3 +199,4 @@ class NewDataset(datasets.GeneratorBasedBuilder):
203
  "image_resolution": {"width": width, "height": height},
204
  "annotations": annotations
205
  }
 
 
168
  return annotations
169
 
170
  def _generate_examples(self, filepaths, species_info, data_dir):
171
+ """Yields examples as (key, example) tuples."""
172
  for file_name in filepaths:
173
  image_id = os.path.splitext(file_name)[0] # Extract the base name without the file extension
174
  image_path = os.path.join(data_dir, f"{image_id}.jpg")
 
179
  if not species_row.empty:
180
  species = species_row['Species'].values[0]
181
  scientific_name = species_row['ScientificName'].values[0]
182
+ width = species_row['Width'].values[0]
183
+ height = species_row['Height'].values[0]
184
  else:
185
+ # If the species info is not found, continue to the next file
186
+ continue
187
+
 
 
 
 
188
  with Image.open(image_path) as img:
189
  pics_array = np.array(img).tolist() # Convert the PIL image to a numpy array and then to a list
190
+
191
  annotations = self._parse_yolo_labels(label_path, width, height)
192
 
193
  # Yield the dataset example
 
199
  "image_resolution": {"width": width, "height": height},
200
  "annotations": annotations
201
  }
202
+