Update Stomatal_Images_Datasets.py
Browse files- Stomatal_Images_Datasets.py +37 -16
Stomatal_Images_Datasets.py
CHANGED
@@ -45,10 +45,14 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
45 |
"annotations": datasets.Sequence({
|
46 |
"category_id": datasets.Value("int32"),
|
47 |
"bounding_box": {
|
48 |
-
"x_min": datasets.Value("float32"),
|
49 |
-
"y_min": datasets.Value("float32"),
|
50 |
-
"x_max": datasets.Value("float32"),
|
51 |
-
"y_max": datasets.Value("float32"),
|
|
|
|
|
|
|
|
|
52 |
},
|
53 |
}),
|
54 |
})
|
@@ -84,27 +88,44 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
84 |
)]
|
85 |
|
86 |
|
87 |
-
def _parse_yolo_labels(self, label_path, width, height):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
annotations = []
|
89 |
with open(label_path, 'r') as file:
|
90 |
yolo_data = file.readlines()
|
91 |
|
92 |
for line in yolo_data:
|
93 |
class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
94 |
-
x_min = (x_center_rel - width_rel / 2) * width
|
95 |
-
y_min = (y_center_rel - height_rel / 2) * height
|
96 |
-
x_max = (x_center_rel + width_rel / 2) * width
|
97 |
-
y_max = (y_center_rel + height_rel / 2) * height
|
98 |
annotations.append({
|
99 |
"category_id": int(class_id),
|
100 |
-
"
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
"y_max": y_max
|
105 |
-
}
|
106 |
})
|
107 |
return annotations
|
|
|
108 |
|
109 |
def _generate_examples(self, filepaths, species_info, data_dir):
|
110 |
"""Yields examples as (key, example) tuples."""
|
@@ -130,7 +151,7 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
130 |
width = 1024
|
131 |
height = 768
|
132 |
|
133 |
-
annotations = self._parse_yolo_labels(label_path
|
134 |
|
135 |
# Yield the dataset example
|
136 |
yield image_id, {
|
|
|
45 |
"annotations": datasets.Sequence({
|
46 |
"category_id": datasets.Value("int32"),
|
47 |
"bounding_box": {
|
48 |
+
# "x_min": datasets.Value("float32"),
|
49 |
+
# "y_min": datasets.Value("float32"),
|
50 |
+
# "x_max": datasets.Value("float32"),
|
51 |
+
# "y_max": datasets.Value("float32"),
|
52 |
+
"x_center_rel": datasets.Value("float32"),
|
53 |
+
"y_center_rel": datasets.Value("float32"),
|
54 |
+
"width_rel": datasets.Value("float32"),
|
55 |
+
"height_rel": datasets.Value("float32"),
|
56 |
},
|
57 |
}),
|
58 |
})
|
|
|
88 |
)]
|
89 |
|
90 |
|
91 |
+
# def _parse_yolo_labels(self, label_path, width, height):
|
92 |
+
# annotations = []
|
93 |
+
# with open(label_path, 'r') as file:
|
94 |
+
# yolo_data = file.readlines()
|
95 |
+
|
96 |
+
# for line in yolo_data:
|
97 |
+
# class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
98 |
+
# x_min = (x_center_rel - width_rel / 2) * width
|
99 |
+
# y_min = (y_center_rel - height_rel / 2) * height
|
100 |
+
# x_max = (x_center_rel + width_rel / 2) * width
|
101 |
+
# y_max = (y_center_rel + height_rel / 2) * height
|
102 |
+
# annotations.append({
|
103 |
+
# "category_id": int(class_id),
|
104 |
+
# "bounding_box": {
|
105 |
+
# "x_min": x_min,
|
106 |
+
# "y_min": y_min,
|
107 |
+
# "x_max": x_max,
|
108 |
+
# "y_max": y_max
|
109 |
+
# }
|
110 |
+
# })
|
111 |
+
# return annotations
|
112 |
+
|
113 |
+
def _parse_yolo_labels(self, label_path):
|
114 |
annotations = []
|
115 |
with open(label_path, 'r') as file:
|
116 |
yolo_data = file.readlines()
|
117 |
|
118 |
for line in yolo_data:
|
119 |
class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
|
|
|
|
|
|
|
|
120 |
annotations.append({
|
121 |
"category_id": int(class_id),
|
122 |
+
"x_center_rel": x_center_rel,
|
123 |
+
"y_center_rel": y_center_rel,
|
124 |
+
"width_rel": width_rel,
|
125 |
+
"height_rel": height_rel,
|
|
|
|
|
126 |
})
|
127 |
return annotations
|
128 |
+
|
129 |
|
130 |
def _generate_examples(self, filepaths, species_info, data_dir):
|
131 |
"""Yields examples as (key, example) tuples."""
|
|
|
151 |
width = 1024
|
152 |
height = 768
|
153 |
|
154 |
+
annotations = self._parse_yolo_labels(label_path)
|
155 |
|
156 |
# Yield the dataset example
|
157 |
yield image_id, {
|