Update RDD_2020.py
Browse files- RDD_2020.py +36 -34
RDD_2020.py
CHANGED
@@ -140,37 +140,39 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
140 |
image_id = f"{image_file.split('.')[0]}"
|
141 |
|
142 |
image_path = os.path.join(images_dir, image_file)
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
|
|
|
140 |
image_id = f"{image_file.split('.')[0]}"
|
141 |
|
142 |
image_path = os.path.join(images_dir, image_file)
|
143 |
+
# Load the image as a PIL Image object
|
144 |
+
with Image.open(image_path) as img:
|
145 |
+
img.load() # This is important to load the image data
|
146 |
+
|
147 |
+
if annotations_dir:
|
148 |
+
annotation_file = image_id + '.xml'
|
149 |
+
annotation_path = os.path.join(annotations_dir, annotation_file)
|
150 |
+
if not os.path.exists(annotation_path):
|
151 |
+
continue
|
152 |
+
tree = ET.parse(annotation_path)
|
153 |
+
root = tree.getroot()
|
154 |
+
crack_type = []
|
155 |
+
crack_coordinates = []
|
156 |
+
for obj in root.findall('object'):
|
157 |
+
crack_type.append(obj.find('name').text)
|
158 |
+
bndbox = obj.find('bndbox')
|
159 |
+
coordinates = {
|
160 |
+
"x_min": int(bndbox.find('xmin').text),
|
161 |
+
"x_max": int(bndbox.find('xmax').text),
|
162 |
+
"y_min": int(bndbox.find('ymin').text),
|
163 |
+
"y_max": int(bndbox.find('ymax').text),
|
164 |
+
}
|
165 |
+
crack_coordinates.append(coordinates)
|
166 |
+
else:
|
167 |
+
crack_type = []
|
168 |
+
crack_coordinates = []
|
169 |
+
|
170 |
+
# 将 PIL 图像对象添加到生成的字典中
|
171 |
+
yield image_id, {
|
172 |
+
"image_id": image_id,
|
173 |
+
"country": country_dir,
|
174 |
+
"type": split,
|
175 |
+
"image": img, # PIL 图像对象
|
176 |
+
"crack_type": crack_type,
|
177 |
+
"crack_coordinates": crack_coordinates,
|
178 |
+
}
|