Fix coco style bounding box annotations (#116)
Browse files* Fix coco style bounding box annotations
* Fix top right corner
- yolo/tools/data_loader.py +4 -2
- yolo/utils/dataset_utils.py +8 -1
yolo/tools/data_loader.py
CHANGED
@@ -126,10 +126,12 @@ class YoloDataset(Dataset):
|
|
126 |
|
127 |
def load_valid_labels(self, label_path: str, seg_data_one_img: list) -> Union[Tensor, None]:
|
128 |
"""
|
129 |
-
Loads
|
|
|
130 |
|
131 |
Parameters:
|
132 |
-
label_path (str): The filepath to the label file containing
|
|
|
133 |
|
134 |
Returns:
|
135 |
Tensor or None: A tensor of all valid bounding boxes if any are found; otherwise, None.
|
|
|
126 |
|
127 |
def load_valid_labels(self, label_path: str, seg_data_one_img: list) -> Union[Tensor, None]:
|
128 |
"""
|
129 |
+
Loads valid COCO style segmentation data (values between [0, 1]) and converts it to bounding box coordinates
|
130 |
+
by finding the minimum and maximum x and y values.
|
131 |
|
132 |
Parameters:
|
133 |
+
label_path (str): The filepath to the label file containing annotation data.
|
134 |
+
seg_data_one_img (list): The actual list of annotations (in segmentation format)
|
135 |
|
136 |
Returns:
|
137 |
Tensor or None: A tensor of all valid bounding boxes if any are found; otherwise, None.
|
yolo/utils/dataset_utils.py
CHANGED
@@ -104,7 +104,14 @@ def scale_segmentation(
|
|
104 |
if "segmentation" in anno:
|
105 |
seg_list = [item for sublist in anno["segmentation"] for item in sublist]
|
106 |
elif "bbox" in anno:
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
scaled_seg_data = (
|
109 |
np.array(seg_list).reshape(-1, 2) / [w, h]
|
110 |
).tolist() # make the list group in x, y pairs and scaled with image width, height
|
|
|
104 |
if "segmentation" in anno:
|
105 |
seg_list = [item for sublist in anno["segmentation"] for item in sublist]
|
106 |
elif "bbox" in anno:
|
107 |
+
x,y,width,height = anno["bbox"]
|
108 |
+
seg_list = [
|
109 |
+
x, y, # Top-left corner
|
110 |
+
x + width, y, # Top-right corner
|
111 |
+
x + width, y + height, # Bottom-right corner
|
112 |
+
x, y + height # Bottom-left corner
|
113 |
+
]
|
114 |
+
|
115 |
scaled_seg_data = (
|
116 |
np.array(seg_list).reshape(-1, 2) / [w, h]
|
117 |
).tolist() # make the list group in x, y pairs and scaled with image width, height
|