ShixuanAn commited on
Commit
a38cb50
1 Parent(s): 231bbd7

Update RDD_2020.py

Browse files
Files changed (1) hide show
  1. RDD_2020.py +8 -9
RDD_2020.py CHANGED
@@ -106,31 +106,30 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
106
 
107
 
108
  def _generate_examples(self, images_dir, annotations_dir, split):
109
- """Yields examples as (key, example) tuples."""
110
-
111
- # Loop over each country directory in the images_dir
112
  for country_dir in os.listdir(images_dir):
113
  country_images_dir = os.path.join(images_dir, country_dir)
114
  country_annotations_dir = os.path.join(annotations_dir, country_dir, "xmls")
115
 
116
- # Now loop over each image in the country's image directory
117
  for image_file in os.listdir(country_images_dir):
118
  if not image_file.endswith('.jpg'):
119
  continue
120
  image_id = image_file.split('.')[0]
121
  annotation_file = image_id + '.xml'
122
  annotation_path = os.path.join(country_annotations_dir, annotation_file)
123
-
124
  if not os.path.exists(annotation_path):
125
  continue
126
-
127
  tree = ET.parse(annotation_path)
128
  root = tree.getroot()
129
-
130
  image_path = os.path.join(country_images_dir, image_file)
131
  crack_type = []
132
  crack_coordinates = []
133
-
134
  for obj in root.findall('object'):
135
  crack_type.append(obj.find('name').text)
136
  bndbox = obj.find('bndbox')
@@ -142,7 +141,7 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
142
  }
143
  crack_coordinates.append(coordinates)
144
 
145
- # Assuming images are of uniform size, you might want to adjust this or extract from image directly
146
  image_resolution = {"width": 600, "height": 600, "depth": 3} if country_dir != "India" else {"width": 720, "height": 720, "depth": 3}
147
 
148
  yield image_id, {
 
106
 
107
 
108
  def _generate_examples(self, images_dir, annotations_dir, split):
109
+ """Yields examples as (key, example) tuples."""
110
+ # Loop over each country directory in the images_dir
 
111
  for country_dir in os.listdir(images_dir):
112
  country_images_dir = os.path.join(images_dir, country_dir)
113
  country_annotations_dir = os.path.join(annotations_dir, country_dir, "xmls")
114
 
115
+ # Now loop over each image in the country's image directory
116
  for image_file in os.listdir(country_images_dir):
117
  if not image_file.endswith('.jpg'):
118
  continue
119
  image_id = image_file.split('.')[0]
120
  annotation_file = image_id + '.xml'
121
  annotation_path = os.path.join(country_annotations_dir, annotation_file)
122
+
123
  if not os.path.exists(annotation_path):
124
  continue
125
+
126
  tree = ET.parse(annotation_path)
127
  root = tree.getroot()
128
+
129
  image_path = os.path.join(country_images_dir, image_file)
130
  crack_type = []
131
  crack_coordinates = []
132
+
133
  for obj in root.findall('object'):
134
  crack_type.append(obj.find('name').text)
135
  bndbox = obj.find('bndbox')
 
141
  }
142
  crack_coordinates.append(coordinates)
143
 
144
+ # Assuming images are of uniform size, you might want to adjust this or extract from image directly
145
  image_resolution = {"width": 600, "height": 600, "depth": 3} if country_dir != "India" else {"width": 720, "height": 720, "depth": 3}
146
 
147
  yield image_id, {