灰度¶
- class torchvision.transforms.Grayscale(num_output_channels=1)[源代码]¶
将图像转换为灰度图。如果图像是 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
的示例