XintongHe commited on
Commit
97275fa
1 Parent(s): fc20259

Update new_dataset_script.py

Browse files
Files changed (1) hide show
  1. new_dataset_script.py +8 -5
new_dataset_script.py CHANGED
@@ -169,10 +169,10 @@ def _generate_examples(self, filepaths, species_info, data_dir, split):
169
  image_id = os.path.splitext(file_name)[0] # Extract the base name without the file extension
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
- json_path = os.path.join(data_dir, f"{image_id}.json") # JSON file path
173
 
174
  with Image.open(image_path) as img:
175
  width, height = img.size
 
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
@@ -180,10 +180,13 @@ def _generate_examples(self, filepaths, species_info, data_dir, split):
180
 
181
  annotations = self._parse_yolo_labels(label_path, width, height)
182
 
183
- # Save metadata to JSON
184
- save_metadata_as_json(image_id, annotations, species, scientific_name, json_path)
185
 
186
  yield image_id, {
187
- "image": img, # Return the PIL image
188
- "metadata_json": json_path # Return the path to the JSON file
 
 
 
 
 
189
  }
 
169
  image_id = os.path.splitext(file_name)[0] # Extract the base name without the file extension
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
 
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,
187
+ "scientific_name": scientific_name,
188
+ "pics_array": pics_array,
189
+ "image_resolution": {"width": width, "height": height},
190
+ "annotations": annotations,
191
+ "image": img # Return the PIL image
192
  }