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 sanitize_bounding_boxes kernel/functional #8308

Merged
merged 4 commits into from
Mar 15, 2024

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Mar 12, 2024

Addresses part of #8294

Some design discussion started on #8294 (comment). After chatting a bit offline we decided to go with Option 3 (#8294 (comment)) because:

  • Option 1 wouldn't support torchscript (*args)
  • Option 2 forces users to manually re-wrap with tv_tensors.wrap()
  • Option 3 is the only option that doesn't have these sort of non-starters

cc @vfdev-5

Copy link

pytorch-bot bot commented Mar 12, 2024

🔗 Helpful Links

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

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

❌ 16 New Failures, 20 Unrelated Failures

As of commit e5a5892 with merge base d1f3a7b (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

Returns:
out (tuple of Tensors): The subset of valid bounding boxes, and the corresponding indexing mask.
The mask can then be used to subset other tensors (e.g. labels) that are associated with the bounding boxes.
"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ss

@pytest.mark.parametrize("min_size", (1, 10))
@pytest.mark.parametrize("labels_getter", ("default", lambda inputs: inputs["labels"], None, lambda inputs: None))
@pytest.mark.parametrize("sample_type", (tuple, dict))
def test_transform(self, min_size, labels_getter, sample_type):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test did not change, I just moved the input generation above in a function so that it can be reused in the newly added tests below

torchvision/transforms/v2/_misc.py Outdated Show resolved Hide resolved
Comment on lines +325 to +328
valid = _get_sanitize_bounding_boxes_mask(
bounding_boxes, format=format, canvas_size=canvas_size, min_size=min_size
)
bounding_boxes = bounding_boxes[valid]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit sad that these 2 lines are somewhat duplicated below in the else: block. I couldn't find a decent way to make all that work without upsetting torchscript.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's not bother.

return bounding_boxes, valid


def _get_sanitize_bounding_boxes_mask(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of this function is completely unchanged from the existing logic in the class.

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments but otherwise LGTM. Thanks Nicolas!

test/test_transforms_v2.py Show resolved Hide resolved
torchvision/transforms/v2/_misc.py Outdated Show resolved Hide resolved
torchvision/transforms/v2/_misc.py Outdated Show resolved Hide resolved
Comment on lines +325 to +328
valid = _get_sanitize_bounding_boxes_mask(
bounding_boxes, format=format, canvas_size=canvas_size, min_size=min_size
)
bounding_boxes = bounding_boxes[valid]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's not bother.

@@ -123,7 +123,7 @@ def _extract_image_targets(
if not (len(images) == len(bboxes) == len(masks) == len(labels)):
raise TypeError(
f"{type(self).__name__}() requires input sample to contain equal sized list of Images, "
"BoundingBoxeses, Masks and Labels or OneHotLabels."
"BoundingBoxes, Masks and Labels or OneHotLabels."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Driveby

@NicolasHug NicolasHug merged commit 53869eb into pytorch:main Mar 15, 2024
9 of 34 checks passed
@NicolasHug NicolasHug deleted the sanitize_func branch March 15, 2024 12:52
facebook-github-bot pushed a commit that referenced this pull request Mar 21, 2024
Reviewed By: vmoens

Differential Revision: D55062772

fbshipit-source-id: 677840081e6516e2d1d603853f16314d209dbf5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

3 participants