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

fix to_grayscale deprecation warning #7702

Merged
merged 2 commits into from
Jun 27, 2023
Merged

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Jun 27, 2023

Fixes #7700. In #7120 we removed F.convert_colorspace and undeprecated F.rgb_to_grayscale in #7122. We just forgot to adapt the deprecation warning.

@pmeier pmeier requested a review from NicolasHug June 27, 2023 11:55
@pytorch-bot
Copy link

pytorch-bot bot commented Jun 27, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7702

Note: Links to docs will display an error until the docs builds have been completed.

❌ 32 New Failures

As of commit 2f8eadb:

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot but... Did we decide to still deprecate to_grayscale? (I remember it was a bit messy...)

@pmeier
Copy link
Collaborator Author

pmeier commented Jun 27, 2023

Did we decide to still deprecate to_grayscale? (I remember it was a bit messy...)

It is. In v1 we have both

  • # 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):
  • def rgb_to_grayscale(img: Tensor, num_output_channels: int = 1) -> Tensor:

For some reason, to_grayscale only handles PIL images:

if isinstance(img, Image.Image):
return F_pil.to_grayscale(img, num_output_channels)
raise TypeError("Input should be PIL Image")

rgb_to_grayscale handles both PIL and tensor images and dispatches to to_grayscale for the former:

if not isinstance(img, torch.Tensor):
return F_pil.to_grayscale(img, num_output_channels)
return F_t.rgb_to_grayscale(img, num_output_channels)

Meaning, in the (now private) _functional_tensor there is no to_grayscale and in _functional_pil there is no rgb_to_grayscale.

The transforms ToGrayscale and RandomGrayscale in v1 and v2 only use rgb_to_grayscale, which is why we deprecated to_grayscale in v2.

@pmeier pmeier merged commit c9ac3a5 into pytorch:main Jun 27, 2023
@pmeier pmeier deleted the to-grayscale branch June 27, 2023 13:46
@github-actions
Copy link

Hey @pmeier!

You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

facebook-github-bot pushed a commit that referenced this pull request Jul 3, 2023
Reviewed By: vmoens

Differential Revision: D47186572

fbshipit-source-id: 3818db074027c4643f33255ddd1df90f936d15e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_grayscale gives non-actionable deprecation warning
3 participants