Skip to content

improve performance of {invert, solarize}_image_tensor #6819

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

Merged
merged 6 commits into from
Oct 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion torchvision/prototype/transforms/functional/_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,14 @@ def equalize(inpt: features.InputTypeJIT) -> features.InputTypeJIT:
return equalize_image_pil(inpt)


invert_image_tensor = _FT.invert
def invert_image_tensor(image: torch.Tensor):
num_channels, height, width = get_dimensions_image_tensor(image)
if num_channels not in (1, 3):
raise TypeError(f"Input image tensor can have 1 or 3 channels, but found {num_channels}")

return 1.0 - image if image.is_floating_point() else image.bitwise_not()


invert_image_pil = _FP.invert


Expand Down