Update soybean_dataset.py
Browse files- soybean_dataset.py +30 -26
soybean_dataset.py
CHANGED
@@ -21,7 +21,7 @@ import os
|
|
21 |
from typing import List
|
22 |
import datasets
|
23 |
import logging
|
24 |
-
|
25 |
import numpy as np
|
26 |
from PIL import Image
|
27 |
import os
|
@@ -127,33 +127,37 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
127 |
|
128 |
|
129 |
def _generate_examples(self, filepath):
|
130 |
-
logging.info("
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
-
#
|
137 |
-
|
138 |
|
139 |
-
#
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
segmentation_image = Image.open(segmentation_file)
|
151 |
-
|
152 |
-
yield unique_id, {
|
153 |
-
"original_image": original_image,
|
154 |
-
"segmentation_image": segmentation_image,
|
155 |
-
}
|
156 |
-
|
157 |
|
158 |
|
159 |
|
|
|
21 |
from typing import List
|
22 |
import datasets
|
23 |
import logging
|
24 |
+
|
25 |
import numpy as np
|
26 |
from PIL import Image
|
27 |
import os
|
|
|
127 |
|
128 |
|
129 |
def _generate_examples(self, filepath):
|
130 |
+
logging.info("Generating examples from = %s", filepath)
|
131 |
+
|
132 |
+
# Initialize a counter for unique ID
|
133 |
+
unique_id = 0
|
134 |
+
|
135 |
+
# Get the list of files in the directory
|
136 |
+
file_list = os.listdir(filepath)
|
137 |
+
|
138 |
+
# Create pairs of original and segmentation images
|
139 |
+
images_pairs = [(f, f.replace('_original.jpg', '_segmentation.png')) for f in file_list if '_original.jpg' in f]
|
140 |
+
|
141 |
+
# Iterate over the pairs and yield examples
|
142 |
+
for original_image_name, segmentation_image_name in images_pairs:
|
143 |
+
# Construct the full path to the original and segmentation images
|
144 |
+
original_image_path = os.path.join(filepath, original_image_name)
|
145 |
+
segmentation_image_path = os.path.join(filepath, segmentation_image_name)
|
146 |
|
147 |
+
# Open the original image
|
148 |
+
original_image = Image.open(original_image_path)
|
149 |
|
150 |
+
# Open the segmentation image
|
151 |
+
segmentation_image = Image.open(segmentation_image_path)
|
152 |
+
|
153 |
+
# Yield the current example
|
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 |
|