diff --git a/CHANGELOG.md b/CHANGELOG.md index d6a0eba02f..398fd16f2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Released on December, XX, 2022. - New Features: - Added YOLOv5 as an inference-only tool ([#360](https://github.com/opendr-eu/opendr/pull/360)). - Added Continual Transformer Encoders ([#317](https://github.com/opendr-eu/opendr/pull/317)). + - Bug Fixes: + - Fixed `BoundingBoxList`, `TrackingAnnotationList`, `BoundingBoxList3D` and `TrackingAnnotationList3D` confidence warnings ([#365](https://github.com/opendr-eu/opendr/pull/365)). + - Fixed undefined `image_id` and `segmentation` for COCO `BoundingBoxList` ([#365](https://github.com/opendr-eu/opendr/pull/365)). ## Version 1.1.1 Released on June, 30th, 2022. diff --git a/src/opendr/engine/target.py b/src/opendr/engine/target.py index 4b44543731..652cba01a0 100644 --- a/src/opendr/engine/target.py +++ b/src/opendr/engine/target.py @@ -437,11 +437,13 @@ class BoundingBoxList(Target): """ def __init__( self, - boxes, + boxes=None, + image_id=-1, ): super().__init__() - self.data = boxes - self.confidence = np.mean([box.confidence for box in self.data]) + self.data = [] if boxes is None else boxes + self.image_id = image_id + self.__compute_confidence() @staticmethod def from_coco(boxes_coco, image_id=0): @@ -451,6 +453,8 @@ def from_coco(boxes_coco, image_id=0): for i in range(count): if 'segmentation' in boxes_coco[i]: segmentation = boxes_coco[i]['segmentation'] + else: + segmentation = [] if 'iscrowd' in boxes_coco[i]: iscrowd = boxes_coco[i]['iscrowd'] else: @@ -481,10 +485,17 @@ def mot(self, with_confidence=True): return result + def add_box(self, box: BoundingBox): + self.data.append(box) + self.__compute_confidence() + @property def boxes(self): return self.data + def __compute_confidence(self): + self.confidence = sum([box.confidence for box in self.data], 0) / max(1, len(self.data)) + def __getitem__(self, idx): return self.boxes[idx] @@ -578,11 +589,11 @@ class TrackingAnnotationList(Target): """ def __init__( self, - boxes, + annotations=None, ): super().__init__() - self.data = boxes - self.confidence = np.mean([box.confidence for box in self.data]) + self.data = [] if annotations is None else annotations + self.__compute_confidence() @staticmethod def from_mot(data): @@ -603,10 +614,17 @@ def mot(self, with_confidence=True): def bounding_box_list(self): return BoundingBoxList([box.bounding_box() for box in self.data]) + def add_annotation(self, annotation: TrackingAnnotation): + self.data.append(annotation) + self.__compute_confidence() + @property def boxes(self): return self.data + def __compute_confidence(self): + self.confidence = sum([box.confidence for box in self.data], 0) / max(1, len(self.data)) + def __getitem__(self, idx): return self.boxes[idx] @@ -723,12 +741,12 @@ class BoundingBox3DList(Target): """ def __init__( - self, - bounding_boxes_3d + self, + bounding_boxes_3d=None ): super().__init__() - self.data = bounding_boxes_3d - self.confidence = None if len(self.data) == 0 else np.mean([box.confidence for box in self.data]) + self.data = [] if bounding_boxes_3d is None else bounding_boxes_3d + self.__compute_confidence() @staticmethod def from_kitti(boxes_kitti): @@ -803,10 +821,17 @@ def kitti(self): return result + def add_box(self, box: BoundingBox3D): + self.data.append(box) + self.__compute_confidence() + @property def boxes(self): return self.data + def __compute_confidence(self): + self.confidence = sum([box.confidence for box in self.data], 0) / max(1, len(self.data)) + def __getitem__(self, idx): return self.boxes[idx] @@ -910,11 +935,11 @@ class TrackingAnnotation3DList(Target): """ def __init__( self, - tracking_bounding_boxes_3d + annotations_3d=None ): super().__init__() - self.data = tracking_bounding_boxes_3d - self.confidence = None if len(self.data) == 0 else np.mean([box.confidence for box in self.data]) + self.data = [] if annotations_3d is None else annotations_3d + self.__compute_confidence() @staticmethod def from_kitti(boxes_kitti, ids, frames=None): @@ -1004,9 +1029,16 @@ def kitti(self, with_tracking_info=True): def boxes(self): return self.data + def add_annotation(self, annotation: TrackingAnnotation3D): + self.data.append(annotation) + self.__compute_confidence() + def bounding_box_3d_list(self): return BoundingBox3DList([box.bounding_box_3d() for box in self.data]) + def __compute_confidence(self): + self.confidence = sum([box.confidence for box in self.data], 0) / max(1, len(self.data)) + def __getitem__(self, idx): return self.boxes[idx]