XintongHe commited on
Commit
a64e957
1 Parent(s): 8314360

Update Stomatal_Images_Datasets.py

Browse files
Files changed (1) hide show
  1. Stomatal_Images_Datasets.py +41 -37
Stomatal_Images_Datasets.py CHANGED
@@ -88,43 +88,47 @@ class NewDataset(datasets.GeneratorBasedBuilder):
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):
@@ -151,7 +155,7 @@ class NewDataset(datasets.GeneratorBasedBuilder):
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, {
 
88
  )]
89
 
90
 
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):
 
155
  width = 1024
156
  height = 768
157
 
158
+ annotations = self._parse_yolo_labels(label_path, width, height)
159
 
160
  # Yield the dataset example
161
  yield image_id, {