fix RandomGrayscale for grayscale inputs #5585
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5581. With this fix we don't need to touch
F.rgb_to_grayscale
. The mismatch between tensor and PIL kernel is still open, but somewhat irrelevant for this. The documentation as well as the name ofF.rgb_to_grayscale
clearly state that this is converting RGB inputs. Thus, having mismatching but not wrong behavior for grayscale inputs is not a major problem, since the user is already misusing the kernel. Plus, this whole issue will go away for the prototype transforms, since we will handle color space conversions in a general way there.RandomGrayscale
relied on the undocumented fact thatF.rgb_to_grayscale
is a no-op for grayscale PIL. As shown in #5581, this assumption does not hold for tensor images. This patch removes this assumption and handles grayscale inputs explicitly.