XintongHe commited on
Commit
1a9c71a
1 Parent(s): cf5f383

Update new_dataset_script.py

Browse files
Files changed (1) hide show
  1. new_dataset_script.py +14 -6
new_dataset_script.py CHANGED
@@ -170,17 +170,25 @@ def _generate_examples(self, filepaths, species_info, data_dir, split):
170
  image_path = os.path.join(data_dir, f"{image_id}.jpg")
171
  label_path = os.path.join(data_dir, f"{image_id}.txt")
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  with Image.open(image_path) as img:
174
- width, height = img.size
175
  pics_array = np.array(img) # Convert the PIL image to a numpy array
176
-
177
- species_row = species_info.loc[species_info['FileName'] == file_name]
178
- species = species_row['Species'].values[0] if not species_row.empty else None
179
- scientific_name = species_row['ScientificName'].values[0] if not species_row.empty else None
180
 
181
  annotations = self._parse_yolo_labels(label_path, width, height)
182
 
183
-
184
  yield image_id, {
185
  "image_id": image_id,
186
  "species": species,
 
170
  image_path = os.path.join(data_dir, f"{image_id}.jpg")
171
  label_path = os.path.join(data_dir, f"{image_id}.txt")
172
 
173
+ # Find the corresponding row in the CSV for the current image
174
+ species_row = species_info.loc[species_info['FileName'] == image_id]
175
+ if not species_row.empty:
176
+ species = species_row['Species'].values[0]
177
+ scientific_name = species_row['ScientificName'].values[0]
178
+ width = species_row['Width'].values[0]
179
+ height = species_row['Height'].values[0]
180
+ else:
181
+ # Default values if not found
182
+ species = None
183
+ scientific_name = None
184
+ width = 1024 # or some default value
185
+ height = 768 # or some default value
186
+
187
  with Image.open(image_path) as img:
 
188
  pics_array = np.array(img) # Convert the PIL image to a numpy array
 
 
 
 
189
 
190
  annotations = self._parse_yolo_labels(label_path, width, height)
191
 
 
192
  yield image_id, {
193
  "image_id": image_id,
194
  "species": species,