Update RDD_2020.py
Browse files- RDD_2020.py +35 -42
RDD_2020.py
CHANGED
@@ -57,7 +57,7 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
57 |
"height": datasets.Value("int32"),
|
58 |
"depth": datasets.Value("int32"),
|
59 |
}),
|
60 |
-
|
61 |
"image_path": datasets.Value("string"),
|
62 |
#"pics_array": datasets.Array3D(shape=(None, None, 3), dtype="uint8"),
|
63 |
"crack_type": datasets.Sequence(datasets.Value("string")),
|
@@ -87,11 +87,6 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
87 |
# print( downloaded_files['train'])
|
88 |
|
89 |
|
90 |
-
# ls /root/.cache/huggingface/datasets/downloads/extracted/da17428e8597064d3819cfa1c73686f8876572f681a1b577a2fe8a68c885806a
|
91 |
-
#ls /root/.cache/huggingface/datasets/downloads/extracted/8391428f7cc3295c41551812c745861c0fa9ffe588cccef4cd4f618f92e6333f
|
92 |
-
# ls /root/.cache/huggingface/datasets/downloads/extracted/037a5dd551ee4ecb710b7ea376f03a5a3031aa9555aff200c7b758b066b1981d
|
93 |
-
# directory_path = '/root/.cache/huggingface/datasets/downloads/extracted/da17428e8597064d3819cfa1c73686f8876572f681a1b577a2fe8a68c885806a'
|
94 |
-
|
95 |
# files_and_directories = os.listdir(directory_path)
|
96 |
# print(files_and_directories)
|
97 |
|
@@ -140,39 +135,37 @@ 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 |
-
bndbox
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
"crack_coordinates": crack_coordinates,
|
178 |
-
}
|
|
|
57 |
"height": datasets.Value("int32"),
|
58 |
"depth": datasets.Value("int32"),
|
59 |
}),
|
60 |
+
# "image": datasets.Value("string"),
|
61 |
"image_path": datasets.Value("string"),
|
62 |
#"pics_array": datasets.Array3D(shape=(None, None, 3), dtype="uint8"),
|
63 |
"crack_type": datasets.Sequence(datasets.Value("string")),
|
|
|
87 |
# print( downloaded_files['train'])
|
88 |
|
89 |
|
|
|
|
|
|
|
|
|
|
|
90 |
# files_and_directories = os.listdir(directory_path)
|
91 |
# print(files_and_directories)
|
92 |
|
|
|
135 |
image_id = f"{image_file.split('.')[0]}"
|
136 |
|
137 |
image_path = os.path.join(images_dir, image_file)
|
138 |
+
# img = Image.open(image_path)
|
139 |
+
|
140 |
+
if annotations_dir:
|
141 |
+
annotation_file = image_id + '.xml'
|
142 |
+
annotation_path = os.path.join(annotations_dir, annotation_file)
|
143 |
+
if not os.path.exists(annotation_path):
|
144 |
+
continue
|
145 |
+
tree = ET.parse(annotation_path)
|
146 |
+
root = tree.getroot()
|
147 |
+
crack_type = []
|
148 |
+
crack_coordinates = []
|
149 |
+
for obj in root.findall('object'):
|
150 |
+
crack_type.append(obj.find('name').text)
|
151 |
+
bndbox = obj.find('bndbox')
|
152 |
+
coordinates = {
|
153 |
+
"x_min": int(bndbox.find('xmin').text),
|
154 |
+
"x_max": int(bndbox.find('xmax').text),
|
155 |
+
"y_min": int(bndbox.find('ymin').text),
|
156 |
+
"y_max": int(bndbox.find('ymax').text),
|
157 |
+
}
|
158 |
+
crack_coordinates.append(coordinates)
|
159 |
+
else:
|
160 |
+
crack_type = []
|
161 |
+
crack_coordinates = []
|
162 |
+
|
163 |
+
yield image_id, {
|
164 |
+
"image_id": image_id,
|
165 |
+
"country": country_dir,
|
166 |
+
"type": split,
|
167 |
+
"image_path": image_path,
|
168 |
+
# "image": img,
|
169 |
+
"crack_type": crack_type,
|
170 |
+
"crack_coordinates": crack_coordinates,
|
171 |
+
}
|
|
|
|