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