pytorch / pytorch/vision

Generalized IOU loss doesn't handle 0-length and -width boxes correctly, expected 0.0 but got 1.0

Open
#7,746 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.