ShixuanAn commited on
Commit
ed6358d
1 Parent(s): f7d33c1

Update hugging_face.py

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