Add rotated bounding box formats #8841
Open
+549
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 boxesWe 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:
BoundingBoxes
instead of creating a newRoratedBoundingBoxes
class. The reason is to simplify the possible input types for transforms and avoid having two different paths for transformations. For instance keeping a singlehorizontal_flip_bounding_boxes
and_horizontal_flip_bounding_boxes_dispatch
instead of creating a new functionhorizontal_flip_rotated_bounding_boxes
;generalized_box_iou_loss
. However, please note these functions do not expect aBoundingBox
as input, but atorch.Tensor[N, 4]
ortorch.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:
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
).