XintongHe commited on
Commit
ee683e8
1 Parent(s): 8906b34

Update Populus_Stomatal_Images_Datasets.py

Browse files
Files changed (1) hide show
  1. Populus_Stomatal_Images_Datasets.py +17 -14
Populus_Stomatal_Images_Datasets.py CHANGED
@@ -109,36 +109,39 @@ class NewDataset(datasets.GeneratorBasedBuilder):
109
  )
110
 
111
  def _split_generators(self, dl_manager):
112
- # Download the CSV file and both ZIP files
113
  data_files = dl_manager.download_and_extract({
114
  "csv": "https://huggingface.co/datasets/XintongHe/Populus_Stomatal_Images_Datasets/resolve/main/data/Labeled Stomatal Images.csv",
115
- "zip_all": "https://huggingface.co/datasets/XintongHe/Populus_Stomatal_Images_Datasets/resolve/main/data/Labeled Stomatal Images.zip",
116
  "zip_config": "https://huggingface.co/datasets/XintongHe/Populus_Stomatal_Images_Datasets/resolve/main/data/Labeled Stomatal Images_config.zip"
117
  })
118
 
119
- # Load the CSV file containing species and scientific names
120
- species_info_full = pd.read_csv(data_files["csv"])
121
 
122
- # Assume the config ZIP is extracted to 'Labeled Stomatal Images_config' folder
123
- extracted_config_path = os.path.join(dl_manager._cache_dir, "Labeled Stomatal Images_config")
124
-
125
- # List all image filenames in the extracted config directory
126
- all_image_filenames_config = [f for f in os.listdir(extracted_config_path) if f.endswith('.jpg')]
127
-
128
- # Filter the species_info dataframe to only include the rows with filenames that are in the new configuration
129
- # Here, we're extracting the filename without the extension to match with the 'FileName' column in the CSV
130
- species_info = species_info_full[species_info_full['FileName'].isin([os.path.splitext(f)[0] for f in all_image_filenames_config])]
 
 
131
 
 
132
  return [
133
  datasets.SplitGenerator(
134
  name=datasets.Split.TRAIN,
135
  gen_kwargs={
136
- "filepaths": all_image_filenames_config,
137
  "species_info": species_info,
138
  "data_dir": extracted_config_path
139
  },
140
  )
141
  ]
 
142
 
143
 
144
 
 
109
  )
110
 
111
  def _split_generators(self, dl_manager):
112
+ # Download and extract the data files
113
  data_files = dl_manager.download_and_extract({
114
  "csv": "https://huggingface.co/datasets/XintongHe/Populus_Stomatal_Images_Datasets/resolve/main/data/Labeled Stomatal Images.csv",
 
115
  "zip_config": "https://huggingface.co/datasets/XintongHe/Populus_Stomatal_Images_Datasets/resolve/main/data/Labeled Stomatal Images_config.zip"
116
  })
117
 
118
+ # The path to the CSV file
119
+ csv_path = data_files["csv"]
120
 
121
+ # The path to the folder where the config ZIP was extracted
122
+ extracted_config_path = data_files["zip_config"]
123
+
124
+ # Read the CSV file to get the species information
125
+ species_info = pd.read_csv(csv_path)
126
+
127
+ # Get the list of image filenames from the CSV that are part of the config
128
+ image_filenames_config = species_info['FileName'].apply(lambda x: x + '.jpg').tolist()
129
+
130
+ # Filter the list to include only the images present in the config directory
131
+ image_filenames = [f for f in image_filenames_config if os.path.exists(os.path.join(extracted_config_path, f))]
132
 
133
+ # Use the filtered list of filenames to create the dataset split
134
  return [
135
  datasets.SplitGenerator(
136
  name=datasets.Split.TRAIN,
137
  gen_kwargs={
138
+ "filepaths": image_filenames,
139
  "species_info": species_info,
140
  "data_dir": extracted_config_path
141
  },
142
  )
143
  ]
144
+
145
 
146
 
147