Skip to content

Conversation

@alperenunlu
Copy link
Contributor

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:

@pytorch-bot
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 New Failure

As of commit 80d12de with merge base 97920a5 (image):

NEW FAILURE - The following job has failed:

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

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

@alperenunlu alperenunlu requested a review from NicolasHug July 14, 2025 13:20
@AntoineSimoulin
Copy link
Member

Hi @alperenunlu, thanks for your patience here. I went through the PR again and pushed some small changes. To simplify the code, I integrated all the logic specific to different formats directly to the box_area, box_iou, and _box_inter_union. This should not change the logic behind your PR. Could you kindly review and let me know if this fits your needs before we merge? Thanks!

@alperenunlu
Copy link
Contributor Author

Hi @AntoineSimoulin,

Thanks for reviewing the PR.
These changes look great, and I’ve fixed a few small issues with them.

Since we now support the xywh format, I think we should also add tests for it.

Overall, I’m very satisfied with the changes.

@AntoineSimoulin
Copy link
Member

Thanks @alperenunlu. I simplified the test case a bit to limit verbosity and added some tests for all formats. Will merge when all tests are passing! Thanks a lot for your time and the contribution. Sorry for the rather long review. Excited to see the change to be included in the future release!

@AntoineSimoulin AntoineSimoulin merged commit 64666c7 into pytorch:main Aug 25, 2025
59 of 60 checks passed
@github-actions
Copy link

Hey @AntoineSimoulin!

You merged this PR, but no labels were added.
The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

@AntoineSimoulin AntoineSimoulin added module: ops Perf For performance improvements labels Aug 25, 2025
@alperenunlu alperenunlu changed the title Add box_area_center and box_iou_center functions for cxcywh format with tests Add cxcywh and xywh format options for box_area and box_iou functions with tests Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed module: ops Perf For performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants