Generalized IOU loss doesn't handle 0-length and -width boxes correctly, expected 0.0 but got 1.0
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🐛 Describe the bug
Generalized IOU loss doesn't handle boxes that are parametrized as 0 length and 0 width correctly. The expectation is that with identical boxes, the GIOU loss is close to zero. This is true for non-trivial boxes with positive length and width. For trivial boxes [0, 0, 0, 0] compared against itself, the GIOU loss returns 1. where we expected the loss function to return 0. This is an edge case.
In the implementation, this is because iouk is 0 when iou=0 and union=0 due to the epsilon in the denominator. Can we catch situations where iou == union == 0, and return 1?
Hoping this behavior can be caught and aligned, so that GIOU returns 0 for trivial boxes too.
>>> boxes = torch.tensor([[0, 0, 0, 0]])
>>> torchvision.ops.generalized_box_iou_loss(boxes, boxes)
tensor([1.]) # this should be 0
>>> boxes = torch.tensor([[0, 0, 1, 1]])
>>> torchvision.ops.generalized_box_iou_loss(boxes, boxes)
tensor([1.1921e-07])
Versions
most recent version
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generalized_box_iou_loss implementation linked in the issue and inspect how zero-area boxes affect IoU, union, and the final loss. Reproduce the two examples, then add or update coverage for identical zero-length, zero-width boxes and verify that the loss is 0 while existing positive-area behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100