Skip to content

Commit

Permalink
Fix bbox/tracking 2D/3D list confidence (opendr-eu#365)
Browse files Browse the repository at this point in the history
* Fix bbox segmentation unbound

* Add bbox list image id

* Fix bbox and annotation list confidence computation

* Make immutable defaults for list targets

* Add changelog entry

Co-authored-by: ad-daniel <[email protected]>
Co-authored-by: ad-daniel <[email protected]>
  • Loading branch information
3 people authored and Luca Marchionni committed Dec 8, 2022
1 parent 28780a4 commit 5cdcd20
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
58 changes: 45 additions & 13 deletions src/opendr/engine/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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):
Expand All @@ -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]

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]

Expand Down

0 comments on commit 5cdcd20

Please sign in to comment.