Skip to content
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

Add rotated bounding box formats #8841

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AntoineSimoulin
Copy link

This PR is part of a series of contributions aiming to add rotated boxes to torchvision. This first contribution aims at modifying the definition of bounding boxes in torchvision. We operate the two following modifications:

Extend BoundingBoxFormat for rotated boxes

We add four multiple allowed formats in BoundingBoxFormat. The formats "xyxyr", "xywhr", "cxcywhr" simply extend the non-rotated counterparts by adding a 5th coordinate to the bounding box, r, the rotation angle with respect to the box center by |r| degrees counter clock wise in the image plan. The last format "xyxyxyxy" represents a box with 4 corners.

Potential limitations:

  • We are proposing to extend BoundingBoxes instead of creating a new RoratedBoundingBoxes class. The reason is to simplify the possible input types for transforms and avoid having two different paths for transformations. For instance keeping a single horizontal_flip_bounding_boxes and _horizontal_flip_bounding_boxes_dispatch instead of creating a new function horizontal_flip_rotated_bounding_boxes;
  • This choice can have some disadvantages as some utility functions expect a 4-dimensional tensor and will be by design incompatible with rotated boxes. One example among other will be the generalized_box_iou_loss. However, please note these functions do not expect a BoundingBox as input, but a torch.Tensor[N, 4] or torch.Tensor[4]. So there is no direct incompatibility.

Add conversion functions for rotated boxes

We add 10 pairwise conversion functions in "_box_convert.py" to allow converting rotated bounding boxes between all four new formats. We also modified the logic in box_convert to support all possible conversion directions.

Potential limitations:

  • We chose to keep the convention previously used in torchvision for which (x1, y1) refer to top left of the bounding box and (x2, y2) refer to the bottom right of the bounding box. However, with the "xyxyxyxy" format it means that when going through the corner of the box in the counter clock-wise direction, we have the following sequence 1, 3, 2, 4. It would maybe make more sense to rename the bottom right of the bounding box as (x3, y3).

Testing

Please run unit tests for the modifications with: pytest test/test_ops.py -vvv -k TestBoxConvert

Next steps

Next modifications will aim at updating transforms functions (e.g. horizontal_flip_bounding_boxes), and adding utility functions specific to rotated boxes (e.g. rotated_box_area, _rotated_box_inter_union, rotated_box_iou).

Test Plan:
Run unit tests: `pytest test/test_ops.py -vvv -k TestBoxConvert`
Copy link

pytorch-bot bot commented Jan 8, 2025

🔗 Helpful Links

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

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

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

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.

2 participants