-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
base: main
Are you sure you want to change the base?
Conversation
🔗 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. ⏳ No Failures, 32 PendingAs of commit b6e7a4c with merge base f515c45 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
torchvision/ops/boxes.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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
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 |
Hi @AntoineSimoulin, Thanks for reviewing the PR. Since we now support the Overall, I’m very satisfied with the changes. |
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
andbox_iou_center
functions, as well as comprehensive tests to ensure their correctness.New utility functions:
torchvision/ops/boxes.py
: Addedbox_area_center
function to compute the area of bounding boxes specified by their center coordinates.torchvision/ops/boxes.py
: Addedbox_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 includebox_area_center
andbox_iou_center
.Test additions:
test/test_ops.py
: AddedTestBoxAreaCenter
class with tests forbox_area_center
function.test/test_ops.py
: AddedTestBoxIouCenter
class with tests forbox_iou_center
function.Module initialization:
torchvision/ops/__init__.py
: Updated the module initialization to includebox_area_center
andbox_iou_center
[1] [2].