Update Stomatal_Images_Datasets.py
Browse files- Stomatal_Images_Datasets.py +35 -35
Stomatal_Images_Datasets.py
CHANGED
@@ -45,14 +45,14 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
45 |
"annotations": datasets.Sequence({
|
46 |
"category_id": datasets.Value("int32"),
|
47 |
"bounding_box": {
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
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 |
})
|
@@ -91,44 +91,44 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
91 |
|
92 |
|
93 |
|
94 |
-
|
95 |
-
# annotations = []
|
96 |
-
# with open(label_path, 'r') as file:
|
97 |
-
# yolo_data = file.readlines()
|
98 |
-
|
99 |
-
# for line in yolo_data:
|
100 |
-
# class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
101 |
-
# x_min = (x_center_rel - width_rel / 2) * width
|
102 |
-
# y_min = (y_center_rel - height_rel / 2) * height
|
103 |
-
# x_max = (x_center_rel + width_rel / 2) * width
|
104 |
-
# y_max = (y_center_rel + height_rel / 2) * height
|
105 |
-
# annotations.append({
|
106 |
-
# "category_id": int(class_id),
|
107 |
-
# "bounding_box": {
|
108 |
-
# "x_min": x_min,
|
109 |
-
# "y_min": y_min,
|
110 |
-
# "x_max": x_max,
|
111 |
-
# "y_max": y_max
|
112 |
-
# }
|
113 |
-
# })
|
114 |
-
# return annotations
|
115 |
-
|
116 |
-
def _parse_yolo_labels(self, label_path, width, height):
|
117 |
annotations = []
|
118 |
with open(label_path, 'r') as file:
|
119 |
yolo_data = file.readlines()
|
120 |
|
121 |
for line in yolo_data:
|
122 |
class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
|
|
|
|
|
|
|
|
123 |
annotations.append({
|
124 |
"category_id": int(class_id),
|
125 |
-
"
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
129 |
})
|
130 |
return annotations
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
|
134 |
def _generate_examples(self, filepaths, species_info, data_dir):
|
|
|
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 |
})
|
|
|
91 |
|
92 |
|
93 |
|
94 |
+
def _parse_yolo_labels(self, label_path, width, height):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
annotations = []
|
96 |
with open(label_path, 'r') as file:
|
97 |
yolo_data = file.readlines()
|
98 |
|
99 |
for line in yolo_data:
|
100 |
class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
101 |
+
x_min = (x_center_rel - width_rel / 2) * width
|
102 |
+
y_min = (y_center_rel - height_rel / 2) * height
|
103 |
+
x_max = (x_center_rel + width_rel / 2) * width
|
104 |
+
y_max = (y_center_rel + height_rel / 2) * height
|
105 |
annotations.append({
|
106 |
"category_id": int(class_id),
|
107 |
+
"bounding_box": {
|
108 |
+
"x_min": x_min,
|
109 |
+
"y_min": y_min,
|
110 |
+
"x_max": x_max,
|
111 |
+
"y_max": y_max
|
112 |
+
}
|
113 |
})
|
114 |
return annotations
|
115 |
|
116 |
+
# def _parse_yolo_labels(self, label_path, width, height):
|
117 |
+
# annotations = []
|
118 |
+
# with open(label_path, 'r') as file:
|
119 |
+
# yolo_data = file.readlines()
|
120 |
+
|
121 |
+
# for line in yolo_data:
|
122 |
+
# class_id, x_center_rel, y_center_rel, width_rel, height_rel = map(float, line.split())
|
123 |
+
# annotations.append({
|
124 |
+
# "category_id": int(class_id),
|
125 |
+
# "x_center_rel": x_center_rel,
|
126 |
+
# "y_center_rel": y_center_rel,
|
127 |
+
# "width_rel": width_rel,
|
128 |
+
# "height_rel": height_rel,
|
129 |
+
# })
|
130 |
+
# return annotations
|
131 |
+
|
132 |
|
133 |
|
134 |
def _generate_examples(self, filepaths, species_info, data_dir):
|