-
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
Changes from 1 commit
090a0d7
2286120
98ef6f2
b7dc533
b6b2db0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
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 commentThe 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 commentThe 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 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. OK I'll restore `_split_alpha. 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. 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. |
||
if not torch.all(alpha == _FT._max_value(alpha.dtype)): | ||
raise RuntimeError( | ||
"Stripping the alpha channel if it contains values other than the max value is not supported." | ||
|
@@ -237,7 +233,7 @@ def convert_color_space_image_tensor( | |
elif old_color_space == ColorSpace.GRAY_ALPHA and new_color_space == ColorSpace.RGB: | ||
return _gray_to_rgb(_strip_alpha(image)) | ||
elif old_color_space == ColorSpace.GRAY_ALPHA and new_color_space == ColorSpace.RGB_ALPHA: | ||
image, alpha = _split_alpha(image) | ||
image, alpha = torch.tensor_split(image, indices=(-1,), dim=-3) | ||
return _add_alpha(_gray_to_rgb(image), alpha) | ||
elif old_color_space == ColorSpace.RGB and new_color_space == ColorSpace.GRAY: | ||
return _rgb_to_gray(image) | ||
|
@@ -248,7 +244,7 @@ def convert_color_space_image_tensor( | |
elif old_color_space == ColorSpace.RGB_ALPHA and new_color_space == ColorSpace.GRAY: | ||
return _rgb_to_gray(_strip_alpha(image)) | ||
elif old_color_space == ColorSpace.RGB_ALPHA and new_color_space == ColorSpace.GRAY_ALPHA: | ||
image, alpha = _split_alpha(image) | ||
image, alpha = torch.tensor_split(image, indices=(-1,), dim=-3) | ||
return _add_alpha(_rgb_to_gray(image), alpha) | ||
elif old_color_space == ColorSpace.RGB_ALPHA and new_color_space == ColorSpace.RGB: | ||
return _strip_alpha(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.