Converting Images To Grayscale With PyTorch's Torchvision
Grayscale() converts images to grayscale. OxfordIIITPet() dataset requires 1 or 3 output channels. Use Grayscale(num_output_channels=1) for 1-channel images and num_output_channels=3 for 3-channel images.
Buy Me a Coffee☕ *Memos: My post explains OxfordIIITPet(). Grayscale() can convert an image to grayscale as shown below: *Memos: The 1st argument for initialization is num_output_channels(Optional-Default:1-Type:int). *It must be 1 or 3. The 1st argument is img(Required-Type:PIL Image or tensor(int)): *Memos: A tensor must be 3D. Don't use img=. v2 is recommended to use according to V1 or V2? Which one should I use?. from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import Grayscale gs = Grayscale() gs = Grayscale(num_output_channels=1) gs # Grayscale(num_...