Update soybean_dataset.py
Browse files- soybean_dataset.py +22 -29
soybean_dataset.py
CHANGED
|
@@ -129,37 +129,30 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
| 129 |
def _generate_examples(self, filepath):
|
| 130 |
logging.info("Generating examples from = %s", filepath)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
unique_id = 0
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
|
| 154 |
-
yield unique_id, {
|
| 155 |
-
"original_image": original_image,
|
| 156 |
-
"segmentation_image": segmentation_image,
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
# Increment the unique ID for the next example
|
| 160 |
-
unique_id += 1
|
| 161 |
-
|
| 162 |
-
|
| 163 |
|
| 164 |
|
| 165 |
|
|
|
|
| 129 |
def _generate_examples(self, filepath):
|
| 130 |
logging.info("Generating examples from = %s", filepath)
|
| 131 |
|
| 132 |
+
|
|
|
|
| 133 |
|
| 134 |
+
for filename in os.listdir(filepath):
|
| 135 |
+
if filename.endswith('_original.jpg'):
|
| 136 |
+
# Construct the unique ID and the corresponding segmentation image name
|
| 137 |
+
unique_id = filename.split('_')[0]
|
| 138 |
+
segmentation_image_name = filename.replace('_original.jpg', '_segmentation.png')
|
| 139 |
+
|
| 140 |
+
# Construct full paths to the image files
|
| 141 |
+
original_image_path = os.path.join(filepath, filename)
|
| 142 |
+
segmentation_image_path = os.path.join(filepath, segmentation_image_name)
|
| 143 |
+
|
| 144 |
+
# Open and process the original image
|
| 145 |
+
original_image = Image.open(original_image_path)
|
| 146 |
+
|
| 147 |
+
# Open and process the segmentation image
|
| 148 |
+
segmentation_image = Image.open(segmentation_image_path)
|
| 149 |
+
|
| 150 |
+
yield unique_id, {
|
| 151 |
+
"original_image": original_image,
|
| 152 |
+
"segmentation_image": segmentation_image,
|
| 153 |
+
}
|
| 154 |
|
| 155 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
|
| 158 |
|