vision icon indicating copy to clipboard operation
vision copied to clipboard

Add `box_area_center` and `box_iou_center` functions for cxcywh format with tests

Open alperenunlu opened this issue 10 months ago • 1 comments

Related https://github.com/pytorch/vision/issues/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:

  • torchvision/ops/__init__.py: Updated the module initialization to include box_area_center and box_iou_center [1] [2].

alperenunlu avatar Mar 22 '25 11:03 alperenunlu

:link: Helpful Links

:test_tube: 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.

:x: 1 New Failure

As of commit 80d12de6a5c81d976f82104b8d1b8e60d8577a82 with merge base 97920a5210200e55cbab2929cb78cfcd918d3002 (image):

NEW FAILURE - The following job has failed:

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

pytorch-bot[bot] avatar Mar 22 '25 11:03 pytorch-bot[bot]

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!

AntoineSimoulin avatar Aug 11 '25 16:08 AntoineSimoulin

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.

alperenunlu avatar Aug 14 '25 08:08 alperenunlu

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 avatar Aug 22 '25 16:08 AntoineSimoulin

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

github-actions[bot] avatar Aug 25 '25 16:08 github-actions[bot]