-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Remaining BBox kernel perf optimizations #6896
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ecb927
Bbox resize optimization
datumbox cef0a23
Other (untested) optimizations on `_affine_bounding_box_xyxy` and `el…
datumbox 8a657a9
fix conflict
datumbox 2ed8031
Merge branch 'main' into prototype/bbox_speedups
datumbox 27605e2
Reverting changes on elastic
datumbox a2b9681
revert one more change
datumbox fd7f0d5
Further improvement
datumbox b270b12
Merge branch 'main' into prototype/bbox_speedups
datumbox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,9 +181,11 @@ def resize_bounding_box( | |
) -> Tuple[torch.Tensor, Tuple[int, int]]: | ||
old_height, old_width = spatial_size | ||
new_height, new_width = _compute_resized_output_size(spatial_size, size=size, max_size=max_size) | ||
ratios = torch.tensor((new_width / old_width, new_height / old_height), device=bounding_box.device) | ||
w_ratio = new_width / old_width | ||
h_ratio = new_height / old_height | ||
ratios = torch.tensor([w_ratio, h_ratio, w_ratio, h_ratio], device=bounding_box.device) | ||
return ( | ||
bounding_box.reshape(-1, 2, 2).mul(ratios).to(bounding_box.dtype).reshape(bounding_box.shape), | ||
bounding_box.mul(ratios).to(bounding_box.dtype), | ||
(new_height, new_width), | ||
) | ||
|
||
|
@@ -367,8 +369,7 @@ def _affine_bounding_box_xyxy( | |
# 3) Reshape transformed points to [N boxes, 4 points, x/y coords] | ||
# and compute bounding box from 4 transformed points: | ||
transformed_points = transformed_points.reshape(-1, 4, 2) | ||
out_bbox_mins, _ = torch.min(transformed_points, dim=1) | ||
out_bbox_maxs, _ = torch.max(transformed_points, dim=1) | ||
out_bbox_mins, out_bbox_maxs = torch.aminmax(transformed_points, dim=1) | ||
out_bboxes = torch.cat([out_bbox_mins, out_bbox_maxs], dim=1) | ||
|
||
if expand: | ||
|
@@ -388,8 +389,7 @@ def _affine_bounding_box_xyxy( | |
new_points = torch.matmul(points, transposed_affine_matrix) | ||
tr, _ = torch.min(new_points, dim=0, keepdim=True) | ||
# Translate bounding boxes | ||
out_bboxes[:, 0::2] = out_bboxes[:, 0::2] - tr[:, 0] | ||
out_bboxes[:, 1::2] = out_bboxes[:, 1::2] - tr[:, 1] | ||
out_bboxes.sub_(tr.repeat((1, 2))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improvement for both changes:
|
||
# Estimate meta-data for image with inverted=True and with center=[0,0] | ||
affine_vector = _get_inverse_affine_matrix([0.0, 0.0], angle, translate, scale, shear) | ||
new_width, new_height = _FT._compute_affine_output_size(affine_vector, width, height) | ||
|
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.
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.
Improvement: