Open DLumi opened 3 days ago
Hi @DLumi , thanks for the feature request. Some reading modes like gray are only implemented for some specific image format: https://pytorch.org/vision/main/generated/torchvision.io.ImageReadMode.html#torchvision.io.ImageReadMode
Unfortunately, webp doesn't natively support a grayscale output format: https://stackoverflow.com/questions/51006981/does-webp-support-grayscale-colorspace
So for your use-case, it might be best to simply call the ToGrayscale
transform on such images. It would be a no-op for images which are already in grayscale.
@NicolasHug , thank you for the reply. I've just noticed the Note on ImageReadMode page, so thanks for pointing that out.
Is there a possibility to add this extra call inside the function just for the WEBP to keep things consistent? Not sure how it's implemented, but opencv can read WEBP as grayscale if you specify it in read function. I think tensorflow is also able to read it as a grayscale image, although, I'm not sure.
Or at least emit a warning when trying to open WEBP with ImageReadMode.GRAY
so that it's super clear what went wrong if you missed the note in documentation?
🐛 Describe the bug
The
read_image
func ignoresImageReadMode.GRAY
when reading WEBP images. It produces tensors with 3 color channels instead of 1.Example image: here
Reproduction code:
Expected:
torch.Size([1, 576, 1022])
Actual:
torch.Size([3, 576, 1022])
Versions