Update Populus_Stomatal_Images_Datasets.py
Browse files
Populus_Stomatal_Images_Datasets.py
CHANGED
|
@@ -109,30 +109,37 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
| 109 |
)
|
| 110 |
|
| 111 |
def _split_generators(self, dl_manager):
|
| 112 |
-
#
|
| 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 |
-
"
|
|
|
|
| 116 |
})
|
| 117 |
-
extracted_images_path = 'https://huggingface.co/datasets/XintongHe/Populus_Stomatal_Images_Datasets/resolve/main/data/Labeled Stomatal Images_config.zip'
|
| 118 |
-
|
| 119 |
-
# Load the CSV file containing species and scientific names
|
| 120 |
-
species_info = pd.read_csv(os.path.join(extracted_images_path, 'Labeled Stomatal Images.csv'))
|
| 121 |
-
|
| 122 |
-
# Get all image filenames from the new configuration directory
|
| 123 |
-
all_image_filenames = [f for f in os.listdir(extracted_images_path) if f.endswith('.jpg')]
|
| 124 |
-
|
| 125 |
|
|
|
|
|
|
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
def _parse_yolo_labels(self, label_path, width, height):
|
|
|
|
| 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 |
|
| 145 |
def _parse_yolo_labels(self, label_path, width, height):
|