Skip to content

Add box_area_center and box_iou_center functions for cxcywh format with tests #8992

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alperenunlu
Copy link

Related #8961

This pull request introduces new utility functions for handling bounding boxes and adds corresponding tests. The main changes include the addition of box_area_center and box_iou_center functions, as well as comprehensive tests to ensure their correctness.

New utility functions:

  • torchvision/ops/boxes.py: Added box_area_center function to compute the area of bounding boxes specified by their center coordinates.
  • torchvision/ops/boxes.py: Added box_iou_center function to compute the intersection-over-union (IoU) for bounding boxes specified by their center coordinates.

Documentation updates:

  • docs/source/ops.rst: Updated the documentation to include box_area_center and box_iou_center.

Test additions:

  • test/test_ops.py: Added TestBoxAreaCenter class with tests for box_area_center function.
  • test/test_ops.py: Added TestBoxIouCenter class with tests for box_iou_center function.

Module initialization:

Copy link

pytorch-bot bot commented Mar 22, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8992

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@@ -291,6 +291,25 @@ def box_area(boxes: Tensor) -> Tensor:
return (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1])


def box_area_center(boxes: Tensor) -> Tensor:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR and for the benchmarks @alperenunlu !

I agree with @AntoineSimoulin 's suggestion in #8961 (comment) to not expose the new _center() functions, and instead just add a new fmt (or in_fmt) parameter to the existing box_area() and box_iou() functions.

This will reduce surface area of the API, so it'll be easier to find for users, and easier for us to maintain as well!

For the rest I will let @AntoineSimoulin take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants