-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Closed
Description
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
vision/torchvision/transforms/v2/functional/_deprecated.py
Lines 12 to 22 in 52eb503
| 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
vision/torchvision/transforms/functional.py
Lines 1249 to 1253 in 52eb503
| # 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