RandomInvert¶ class torchvision.transforms.RandomInvert(p=0.5)[source]¶ 根据给定的概率随机反转给定图像的颜色。如果 img 是 Tensor,则期望其格式为 […, 1 或 3, H, W],其中 … 表示可以有任意数量的前导维度。如果 img 是 PIL Image,则期望其模式为 “L” 或 “RGB”。 参数: p (float) – 图像被颜色反转的概率。默认值为 0.5 使用 RandomInvert 的示例 转换图示 转换图示 forward(img)[source]¶ 参数: img (PIL Image 或 Tensor) – 要反转的图像。 返回: 随机颜色反转的图像。 返回类型: PIL 图像或张量