Skip to content
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

to_grayscale gives non-actionable deprecation warning #7700

Closed
pmeier opened this issue Jun 27, 2023 · 0 comments · Fixed by #7702
Closed

to_grayscale gives non-actionable deprecation warning #7700

pmeier opened this issue Jun 27, 2023 · 0 comments · Fixed by #7702

Comments

@pmeier
Copy link
Collaborator

pmeier commented Jun 27, 2023

Originally reported in the user forum by @function2.

When I use to_grayscale, there’s a deprecation warning:

UserWarning: The function `to_grayscale(...)` is deprecated in will be removed in a future release. Instead, please use `convert_color_space(..., color_space=datapoints.ColorSpace.GRAY)`.

However, I can’t find this function in the current code base


Note that this only applies to torchvision.transforms.v2.function

def to_grayscale(inpt: PIL.Image.Image, num_output_channels: int = 1) -> PIL.Image.Image:
call = ", num_output_channels=3" if num_output_channels == 3 else ""
replacement = "convert_color_space(..., color_space=datapoints.ColorSpace.GRAY)"
if num_output_channels == 3:
replacement = f"convert_color_space({replacement}, color_space=datapoints.ColorSpace.RGB)"
warnings.warn(
f"The function `to_grayscale(...{call})` is deprecated in will be removed in a future release. "
f"Instead, please use `{replacement}`.",
)
return _F.to_grayscale(inpt, num_output_channels=num_output_channels)

since the v1 version, i.e. torchvision.transforms.functional does not emit the warning

# Looks like to_grayscale() is a stand-alone functional that is never called
# from the transform classes. Perhaps it's still here for BC? I can't be
# bothered to dig. Anyway, this can be deprecated as we migrate to V2.
@torch.jit.unused
def to_grayscale(img, num_output_channels=1):

Fixing the v2 warning was forgotten in #7120.

cc @vfdev-5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant