Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]Fix horizontal boxes #9140

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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