Grayscale¶
- class torchvision.transforms.Grayscale(num_output_channels=1)[source]¶
将图像转换为灰度。如果图像是 torch Tensor,它应具有 […, 3, H, W] 的形状,其中 … 表示任意数量的前导维度
- 参数:
num_output_channels (int) – (1 或 3) 输出图像所需的通道数
- 返回:
输入图像的灰度版本。
如果
num_output_channels == 1
:返回的图像是单通道如果
num_output_channels == 3
:返回的图像是 3 通道的,其中 r == g == b
- 返回类型:
PIL Image
使用
Grayscale
的示例