ShixuanAn commited on
Commit
622ccd5
1 Parent(s): de8e778

Update RDD_2020.py

Browse files
Files changed (1) hide show
  1. 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
- "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,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
- # 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
- }
 
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
+ }