lisawen commited on
Commit
22ad09b
1 Parent(s): 57efcc7

Update soybean_dataset.py

Browse files
Files changed (1) hide show
  1. 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
- # 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
 
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