灰度¶
- 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 图像
使用
Grayscale
的示例