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 SanitizeBoundingBoxes transform #7246

Merged
merged 17 commits into from
Feb 15, 2023

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Feb 14, 2023

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.

Thanks Nicolas. Left a few high level comments.

torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
Comment on lines 293 to 299
params = dict(valid_indices=valid_indices, labels=labels)
flat_outputs = [
# Even-though it may look like we're transforming all inputs, we don't:
# _transform() will only care about BoundingBoxes and the labels
self._transform(inpt, params)
for inpt in flat_inputs
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if we can do better without other changes, but this looks pretty weird. I mean, we have the bounding box and labels here. All we need to do is to put it at the right place in flat_inputs and we should be good to go without going the extra mile through self._transform.

Copy link
Member Author

Choose a reason for hiding this comment

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

All we need to do is to put it at the right place in flat_inputs

yup... and I don't know how to do that easily :)
But if you can find a way to bypass _transforms(), I'm all ears

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean for boxes, we can change query_bounding_box to whatever we like. Meaning, we could return the index from there. For the labels the story is different. We can't pass the flat_inputs because we rely on the dict keys. Meaning, users would need to return a spec similar to what tree_flatten produces, but that is bad UX. 🤷

assert out["boxes"].shape[0] == out["labels"].shape[0]

# This works because we conveniently set labels to arange(num_boxes)
assert out["labels"].tolist() == valid_indices
Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I can also manually check that all valid_boxes are there, and that there's no invalid ones... LMK

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.

Looks good so far. We should also test the other label heuristics though.

One thing that came to mind is that only allowing a str key might be a little restrictive. Even for our builtin pipelines we have (PIL.Image.Image, dict(labels=...)). Maybe we can relax that and accept a sequence which items are used for a repeated index? Meaning, if someone passes labels=(1, "labels"), we do

input = input[1]
input = input["labels"]

torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
Comment on lines +302 to +303
# TODO: Do we really need to check for out of bounds here? All
# transforms should be clamping anyway, so this should never happen?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would keep this for now until we are sure about this, i.e. we have tests that guarantee this. Happy to remove if it turns out we don't need it.

torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
@NicolasHug NicolasHug marked this pull request as ready for review February 14, 2023 21:09
@NicolasHug
Copy link
Member Author

Maybe we can relax that and accept a sequence which items are used for a repeated index?

I had in mind something similar where we would go as deep as needed in the inputs until we find a "labels" key (up to case-insensitive, etc.). This is similar to yours except that the "nesting" could be handled automatically. I'm happy to do that if we can do it easily, otherwise we always allow to pass callables so I'd say it's alright

@NicolasHug NicolasHug mentioned this pull request Feb 15, 2023
49 tasks
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
torchvision/prototype/transforms/_misc.py Outdated Show resolved Hide resolved
test/test_prototype_transforms.py Show resolved Hide resolved
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.

LGTM if CI is green. Thanks Nicolas!

@NicolasHug NicolasHug merged commit 1e19d73 into pytorch:main Feb 15, 2023
@github-actions
Copy link

Hey @NicolasHug!

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

@NicolasHug
Copy link
Member Author

Thanks a lot for the reviews and for the help with myp

facebook-github-bot pushed a commit that referenced this pull request Mar 28, 2023
Summary: Co-authored-by: Philip Meier <github.pmeier@posteo.de>

Reviewed By: vmoens

Differential Revision: D44416597

fbshipit-source-id: a4fa3db7daaf5ca5a563935545df17ad36363703
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.

3 participants