Update RDD_2020.py
Browse files- RDD_2020.py +20 -23
RDD_2020.py
CHANGED
@@ -75,54 +75,51 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
75 |
)
|
76 |
|
77 |
def _split_generators(self, dl_manager):
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
return [
|
80 |
datasets.SplitGenerator(
|
81 |
name=datasets.Split.TRAIN,
|
82 |
gen_kwargs={
|
83 |
-
"
|
84 |
-
"annotations_dir": os.path.join(data_dir, "train", "annotations"),
|
85 |
"split": "train",
|
86 |
},
|
87 |
),
|
88 |
datasets.SplitGenerator(
|
89 |
name="test1",
|
90 |
gen_kwargs={
|
91 |
-
"
|
92 |
-
"annotations_dir": None, # No annotations for test1
|
93 |
"split": "test1",
|
94 |
},
|
95 |
),
|
96 |
datasets.SplitGenerator(
|
97 |
name="test2",
|
98 |
gen_kwargs={
|
99 |
-
"
|
100 |
-
"annotations_dir": None, # No annotations for test2
|
101 |
"split": "test2",
|
102 |
},
|
103 |
),
|
104 |
]
|
105 |
|
106 |
-
def _generate_examples(self,
|
107 |
-
|
108 |
-
for country_dir in
|
109 |
-
|
110 |
-
|
111 |
-
# Check if we are in a test split without annotations
|
112 |
-
if annotations_dir is None:
|
113 |
-
country_annotations_dir = None
|
114 |
-
else:
|
115 |
-
country_annotations_dir = os.path.join(annotations_dir, country_dir, "xmls")
|
116 |
|
117 |
-
|
|
|
118 |
if not image_file.endswith('.jpg'):
|
119 |
continue
|
120 |
|
121 |
image_id = f"{country_dir}_{image_file.split('.')[0]}"
|
122 |
-
image_path = os.path.join(
|
123 |
-
if
|
124 |
annotation_file = image_id + '.xml'
|
125 |
-
annotation_path = os.path.join(
|
126 |
if not os.path.exists(annotation_path):
|
127 |
continue
|
128 |
tree = ET.parse(annotation_path)
|
@@ -142,7 +139,7 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
142 |
else:
|
143 |
crack_type = []
|
144 |
crack_coordinates = []
|
145 |
-
|
146 |
image_resolution = {"width": 600, "height": 600, "depth": 3}
|
147 |
yield image_id, {
|
148 |
"image_id": image_id,
|
@@ -153,5 +150,5 @@ class RDD2020_Dataset(datasets.GeneratorBasedBuilder):
|
|
153 |
"crack_type": crack_type,
|
154 |
"crack_coordinates": crack_coordinates,
|
155 |
}
|
156 |
-
|
157 |
|
|
|
75 |
)
|
76 |
|
77 |
def _split_generators(self, dl_manager):
|
78 |
+
# Assuming the URLs are the GitHub raw URLs to the country directories within each split
|
79 |
+
train_dir = "https://github.com/ShixuanAn/RDD_2020/tree/main/train"
|
80 |
+
test1_dir = "https://github.com/ShixuanAn/RDD_2020/tree/main/test/test/test1"
|
81 |
+
test2_dir = "https://github.com/ShixuanAn/RDD_2020/tree/main/test/test/test2"
|
82 |
+
|
83 |
return [
|
84 |
datasets.SplitGenerator(
|
85 |
name=datasets.Split.TRAIN,
|
86 |
gen_kwargs={
|
87 |
+
"base_path": train_dir,
|
|
|
88 |
"split": "train",
|
89 |
},
|
90 |
),
|
91 |
datasets.SplitGenerator(
|
92 |
name="test1",
|
93 |
gen_kwargs={
|
94 |
+
"base_path": test1_dir,
|
|
|
95 |
"split": "test1",
|
96 |
},
|
97 |
),
|
98 |
datasets.SplitGenerator(
|
99 |
name="test2",
|
100 |
gen_kwargs={
|
101 |
+
"base_path": test2_dir,
|
|
|
102 |
"split": "test2",
|
103 |
},
|
104 |
),
|
105 |
]
|
106 |
|
107 |
+
def _generate_examples(self, base_path, split):
|
108 |
+
# Iterate over each country directory
|
109 |
+
for country_dir in ['Czech', 'India', 'Japan']:
|
110 |
+
images_dir = f"{base_path}/{country_dir}/images"
|
111 |
+
annotations_dir = f"{base_path}/{country_dir}/annotations/xmls" if split == "train" else None
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
+
# Iterate over each image in the country's image directory
|
114 |
+
for image_file in os.listdir(images_dir):
|
115 |
if not image_file.endswith('.jpg'):
|
116 |
continue
|
117 |
|
118 |
image_id = f"{country_dir}_{image_file.split('.')[0]}"
|
119 |
+
image_path = os.path.join(images_dir, image_file)
|
120 |
+
if annotations_dir:
|
121 |
annotation_file = image_id + '.xml'
|
122 |
+
annotation_path = os.path.join(annotations_dir, annotation_file)
|
123 |
if not os.path.exists(annotation_path):
|
124 |
continue
|
125 |
tree = ET.parse(annotation_path)
|
|
|
139 |
else:
|
140 |
crack_type = []
|
141 |
crack_coordinates = []
|
142 |
+
|
143 |
image_resolution = {"width": 600, "height": 600, "depth": 3}
|
144 |
yield image_id, {
|
145 |
"image_id": image_id,
|
|
|
150 |
"crack_type": crack_type,
|
151 |
"crack_coordinates": crack_coordinates,
|
152 |
}
|
153 |
+
|
154 |
|