Skip to content

Commit

Permalink
[Fix] Fix horizontal boxes (#9140)
Browse files Browse the repository at this point in the history
* Fix corner2hbox of HorizontalBoxes for supporting empty bboxes.

* Test empty boxes for HorizontalBoxes
  • Loading branch information
Czm369 committed Nov 2, 2022
1 parent 3221ecf commit 5897b32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mmdet/structures/bbox/horizontal_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def corner2hbox(corners: Tensor) -> Tensor:
Returns:
Tensor: Horizontal box tensor with shape of (..., 4).
"""
if corners.numel() == 0:
return corners.new_zeros((0, 4))
min_xy = corners.min(dim=-2)[0]
max_xy = corners.max(dim=-2)[0]
return torch.cat([min_xy, max_xy], dim=-1)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_structures/test_bbox/test_horizontal_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def test_project(self):
boxes2.translate_([x_translate, y_translate])
boxes2.rescale_([scale_factor, scale_factor])
assert_allclose(boxes1.tensor, boxes2.tensor)
# test empty boxes
empty_boxes = HorizontalBoxes(torch.zeros((0, 4)))
empty_boxes.project_(matrix)

def test_rescale(self):
scale_factor = [0.4, 0.8]
Expand Down

0 comments on commit 5897b32

Please sign in to comment.