Update Populus_Stomatal_Images_Datasets.py
Browse files
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
|
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 |
-
#
|
120 |
-
|
121 |
|
122 |
-
#
|
123 |
-
extracted_config_path =
|
124 |
-
|
125 |
-
#
|
126 |
-
|
127 |
-
|
128 |
-
#
|
129 |
-
|
130 |
-
|
|
|
|
|
131 |
|
|
|
132 |
return [
|
133 |
datasets.SplitGenerator(
|
134 |
name=datasets.Split.TRAIN,
|
135 |
gen_kwargs={
|
136 |
-
"filepaths":
|
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 |
|