speed
Browse files- soybean_dataset.py +22 -48
soybean_dataset.py
CHANGED
|
@@ -117,69 +117,43 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
| 117 |
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
| 118 |
]
|
| 119 |
|
| 120 |
-
def process_image(self,
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
# Open the image from the downloaded bytes and return the PIL Image
|
| 125 |
-
img = Image.open(BytesIO(response.content))
|
| 126 |
-
return img
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
def _generate_examples(self, filepath):
|
| 131 |
-
#"""Yields examples as (key, example) tuples."""
|
| 132 |
logging.info("generating examples from = %s", filepath)
|
| 133 |
|
| 134 |
with open(filepath, encoding="utf-8") as f:
|
| 135 |
data = csv.DictReader(f)
|
| 136 |
|
| 137 |
-
|
| 138 |
for row in data:
|
| 139 |
-
# Assuming the 'original_image' column has the full path to the image file
|
| 140 |
unique_id = row['unique_id']
|
| 141 |
-
original_image_path = row['original_image']
|
| 142 |
-
segmentation_image_path = row['segmentation_image']
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
"unique_id": unique_id,
|
| 153 |
-
"sets": sets,
|
| 154 |
"original_image": original_image,
|
| 155 |
"segmentation_image": segmentation_image,
|
| 156 |
# ... add other features if necessary
|
| 157 |
}
|
| 158 |
|
| 159 |
-
# for row in data:
|
| 160 |
-
# # Assuming the 'original_image' column has the full path to the image file
|
| 161 |
-
# unique_id = row['unique_id']
|
| 162 |
-
# original_image_path = row['original_image']
|
| 163 |
-
# segmentation_image_path = row['segmentation_image']
|
| 164 |
-
# sets = row['sets']
|
| 165 |
-
|
| 166 |
-
# original_image_array = self.process_image(original_image_path)
|
| 167 |
-
# segmentation_image_array = self.process_image(segmentation_image_path)
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
# # Here you need to replace 'initial_radius', 'final_radius', 'initial_angle', 'final_angle', 'target'
|
| 171 |
-
# # with actual columns from your CSV or additional processing you need to do
|
| 172 |
-
# yield row['unique_id'], {
|
| 173 |
-
# "unique_id": unique_id,
|
| 174 |
-
# "sets": sets,
|
| 175 |
-
# "original_image": original_image_array,
|
| 176 |
-
# "segmentation_image": segmentation_image_array,
|
| 177 |
-
# # ... add other features if necessary
|
| 178 |
-
# }
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
|
| 184 |
|
| 185 |
|
|
|
|
| 117 |
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
| 118 |
]
|
| 119 |
|
| 120 |
+
def process_image(self, image_path):
|
| 121 |
+
# Load the image from the local filesystem
|
| 122 |
+
img = Image.open(image_path)
|
| 123 |
+
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def _generate_examples(self, filepath):
|
|
|
|
| 126 |
logging.info("generating examples from = %s", filepath)
|
| 127 |
|
| 128 |
with open(filepath, encoding="utf-8") as f:
|
| 129 |
data = csv.DictReader(f)
|
| 130 |
|
|
|
|
| 131 |
for row in data:
|
|
|
|
| 132 |
unique_id = row['unique_id']
|
| 133 |
+
original_image_path = row['original_image'] # Adjust this path if necessary
|
| 134 |
+
segmentation_image_path = row['segmentation_image'] # Adjust this path if necessary
|
| 135 |
+
|
| 136 |
+
# Check if image exists locally before loading
|
| 137 |
+
if os.path.exists(original_image_path):
|
| 138 |
+
original_image = self.process_image(original_image_path)
|
| 139 |
+
else:
|
| 140 |
+
logging.error(f"Original image not found: {original_image_path}")
|
| 141 |
+
continue # or handle missing image appropriately
|
| 142 |
+
|
| 143 |
+
if os.path.exists(segmentation_image_path):
|
| 144 |
+
segmentation_image = self.process_image(segmentation_image_path)
|
| 145 |
+
else:
|
| 146 |
+
logging.error(f"Segmentation image not found: {segmentation_image_path}")
|
| 147 |
+
continue # or handle missing image appropriately
|
| 148 |
+
|
| 149 |
+
yield unique_id, {
|
| 150 |
"unique_id": unique_id,
|
| 151 |
+
"sets": row['sets'],
|
| 152 |
"original_image": original_image,
|
| 153 |
"segmentation_image": segmentation_image,
|
| 154 |
# ... add other features if necessary
|
| 155 |
}
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
|
| 159 |
|