Update hugging_face.py
Browse files- hugging_face.py +46 -1
hugging_face.py
CHANGED
@@ -72,7 +72,6 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
72 |
)
|
73 |
|
74 |
def _split_generators(self, dl_manager):
|
75 |
-
# The URL provided must be the direct link to the zip file
|
76 |
urls_to_download = {
|
77 |
"dataset": "https://huggingface.co/datasets/ShixuanAn/RDD2020/resolve/main/RDD2020.zip"
|
78 |
}
|
@@ -156,3 +155,49 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
156 |
"crack_type": crack_type,
|
157 |
"crack_coordinates": crack_coordinates,
|
158 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
)
|
73 |
|
74 |
def _split_generators(self, dl_manager):
|
|
|
75 |
urls_to_download = {
|
76 |
"dataset": "https://huggingface.co/datasets/ShixuanAn/RDD2020/resolve/main/RDD2020.zip"
|
77 |
}
|
|
|
155 |
"crack_type": crack_type,
|
156 |
"crack_coordinates": crack_coordinates,
|
157 |
}
|
158 |
+
def _generate_examples(self, base_path, split):
|
159 |
+
# Iterate over each country directory
|
160 |
+
for country_dir in ['Czech', 'India', 'Japan']:
|
161 |
+
images_dir = f"{base_path}/{country_dir}/images"
|
162 |
+
annotations_dir = f"{base_path}/{country_dir}/annotations/xmls" if split == "train" else None
|
163 |
+
|
164 |
+
for image_file in os.listdir(images_dir):
|
165 |
+
if image_file.endswith('.jpg'):
|
166 |
+
image_id = f"{country_dir}_{image_file.split('.')[0]}"
|
167 |
+
image_path = os.path.join(images_dir, image_file)
|
168 |
+
|
169 |
+
# Initialize the lists to store the parsed data
|
170 |
+
crack_types = []
|
171 |
+
crack_coordinates = []
|
172 |
+
|
173 |
+
if annotations_dir:
|
174 |
+
annotation_file = image_id + '.xml'
|
175 |
+
annotation_path = os.path.join(annotations_dir, annotation_file)
|
176 |
+
if os.path.exists(annotation_path):
|
177 |
+
# Parse the XML file
|
178 |
+
tree = ET.parse(annotation_path)
|
179 |
+
root = tree.getroot()
|
180 |
+
|
181 |
+
# Extract the information
|
182 |
+
for obj in root.findall('object'):
|
183 |
+
crack_type = obj.find('name').text
|
184 |
+
crack_types.append(crack_type)
|
185 |
+
bndbox = obj.find('bndbox')
|
186 |
+
coordinates = {
|
187 |
+
"x_min": int(bndbox.find('xmin').text),
|
188 |
+
"x_max": int(bndbox.find('xmax').text),
|
189 |
+
"y_min": int(bndbox.find('ymin').text),
|
190 |
+
"y_max": int(bndbox.find('ymax').text),
|
191 |
+
}
|
192 |
+
crack_coordinates.append(coordinates)
|
193 |
+
|
194 |
+
|
195 |
+
# Yield the example as a dictionary
|
196 |
+
yield image_id, {
|
197 |
+
"image_id": image_id,
|
198 |
+
"country": country_dir,
|
199 |
+
"type": split,
|
200 |
+
"image_path": image_path,
|
201 |
+
"crack_type": crack_types,
|
202 |
+
"crack_coordinates": crack_coordinates,
|
203 |
+
}
|