Skip to content

Conversation

AntoineSimoulin
Copy link
Member

@AntoineSimoulin AntoineSimoulin commented Aug 12, 2025

This PR adjust the behavior of _parallelogram_to_bounding_boxes. Instead of transforming a parallelogram into a rectangle based on the largest input diagonal, the function returns the minimum area rectangle covering the initial parallelogram. When applying transforms to input rotated bounding boxes, the output tend to be closer to the original boxes and therefore more consistent.

We illustrate below the impact when applying the transforms v2.RandomPerspective(distortion_scale=0.6, p=1.0) in the tutorial to transforms on Rotated Bounding Boxes.

Before fix:
image

After fix:
image

cc @vfdev-5

Copy link

pytorch-bot bot commented Aug 12, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 9fcf281 with merge base 64666c7 (image):

NEW FAILURE - The following job has failed:

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

@meta-cla meta-cla bot added the cla signed label Aug 12, 2025
@AntoineSimoulin
Copy link
Member Author

Note: Add tests (illustrated below) to control that the grey parallelogram is transformed into the green rectangle (and not the red rectangle).

image
# Test the transformation of a simple parallelogram.
#              1
#    1-2      /   2
#   / /  ->  /   /
# 4-3       4   /
#              3
#
#          1
# 1-2       \ 2
#   \ \  ->  \  \
#    4-3       4 \
#                 3
parallelogram = torch.tensor(
    [[0, 4, 3, 1, 5, 1, 2, 4], [0, 1, 2, 1, 5, 4, 3, 4]],
    dtype=torch.float32,
)
expected = torch.tensor(
    [[0, 4, 4, 0, 5, 1, 1, 5], [0, 1, 1, 0, 5, 4, 4, 5]],
    dtype=torch.float32,
)
actual = _parallelogram_to_bounding_boxes(parallelogram)
torch.testing.assert_close(actual, expected)

@facebook-github-bot
Copy link
Contributor

@AntoineSimoulin has imported this pull request. If you are a Meta employee, you can view this in D80916035.

@facebook-github-bot
Copy link
Contributor

@AntoineSimoulin has imported this pull request. If you are a Meta employee, you can view this in D80916035.

@AntoineSimoulin AntoineSimoulin merged commit 7a936da into pytorch:main Aug 25, 2025
60 of 61 checks passed
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

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