-
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
[prototype] Minor improvements on functional #6832
Conversation
if not (isinstance(image, torch.Tensor)): | ||
raise TypeError("Input img should be Tensor image") |
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.
As decided previously, removing the final tensor checks on tensor kernels.
@@ -183,12 +183,8 @@ def clamp_bounding_box( | |||
return convert_format_bounding_box(xyxy_boxes, BoundingBoxFormat.XYXY, format) | |||
|
|||
|
|||
def _split_alpha(image: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: | |||
return image[..., :-1, :, :], image[..., -1:, :, :] |
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.
tensor_split
is marginally faster because it avoids the double indexing:
[------------------------------- Convert_color_space_image_tensor cpu torch.uint8 ------------------------------]
| convert_color_space_image_tensor v2 before | convert_color_space_image_tensor_ v2 after
1 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 217 | 213
6 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 297 | 292
Times are in microseconds (us).
[------------------------------ Convert_color_space_image_tensor cuda torch.uint8 ------------------------------]
| convert_color_space_image_tensor v2 before | convert_color_space_image_tensor_ v2 after
1 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 56.4 | 52
6 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 56.4 | 52
Times are in microseconds (us).
[------------------------------ Convert_color_space_image_tensor cpu torch.float32 -----------------------------]
| convert_color_space_image_tensor v2 before | convert_color_space_image_tensor_ v2 after
1 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 236 | 232
6 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 325 | 321
Times are in microseconds (us).
[----------------------------- Convert_color_space_image_tensor cuda torch.float32 -----------------------------]
| convert_color_space_image_tensor v2 before | convert_color_space_image_tensor_ v2 after
1 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 56.9 | 52.4
6 threads: ------------------------------------------------------------------------------------------------------
(4, 400, 400) | 56.7 | 52.4
Times are in microseconds (us).
def _strip_alpha(image: torch.Tensor) -> torch.Tensor: | ||
image, alpha = _split_alpha(image) | ||
image, alpha = torch.tensor_split(image, indices=(-1,), dim=-3) |
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.
IMO we don't need a private one liner method for something Torch has a built in method.
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.
Non-blocking: I would prefer it since it is a little more expressive. Plus, since we have a _add_alpha
function it would be consistent to have the complementary _split_alpha
as well. With this change we have three identical, non-trivial calls of torch.tensor_split
. At a glance, it is harder to see that these three actually do exactly the same.
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.
OK I'll restore `_split_alpha.
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.
Restoring this causes more harm than good. JIT is complaining that it's not longer a tuple, which means I would have to split into 2 lines and return as tuple to please it. I don't think it's worth this.
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, thanks Vasilis.
Summary: * Minor improvements on functional. * Restore `_split_alpha`. * Revert "Restore `_split_alpha`." This reverts commit 2286120. Reviewed By: YosuaMichael Differential Revision: D40722902 fbshipit-source-id: 3a574939365abd1b74ed3a558b4354b1c40fc883
Minor last improvements on the functional kernels. I consider these mostly code-quality improvements rather that speed optimizations.
cc @vfdev-5 @bjuncek @pmeier