-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
[proto] Speed-up crop on bboxes and tests #6881
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one minor comment.
sub = torch.tensor([left, top, left, top], device=bounding_box.device) | ||
else: | ||
sub = torch.tensor([left, top, 0, 0], device=bounding_box.device) | ||
bounding_box = bounding_box.sub_(sub) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is important to assign to bounding_box the output of bounding_box.sub_(sub)
otherwise, bounding_box is still BoundingBox with wrong spatial_size
Hey @vfdev-5! 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 |
bounding_box.clone(), old_format=format, new_format=features.BoundingBoxFormat.XYXY, inplace=True | ||
) | ||
|
||
bounding_box = bounding_box.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vasilis found that it is generally faster to do one regular operation instead of cloning and a single inplace operation. @vfdev-5 Have you benchmarked that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it faster by ~2us to go directly with bounding_box = bounding_box.sub(sub)
instead of cloning and sub_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we have used the idiom Vasilis found everywhere else, I think it would be good to also use it here especially if it is (marginally) faster. Do you want to send a PR or should I?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update in pad PR (#6890). Less lines of cleaner code is better then current code :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny, full benchmark shows ~10us improvements :)
Summary: * [proto] Speed-up crop on bboxes and tests * Fix linter * Update _geometry.py * Fixed device issue * Revert changes in test/prototype_transforms_kernel_infos.py * Fixed failing correctness tests Reviewed By: datumbox Differential Revision: D41020546 fbshipit-source-id: 0dbc8c900caad4c982fda96b87c98e5d888fe5aa
cc @datumbox @bjuncek @pmeier