RandomPosterize¶ class torchvision.transforms.RandomPosterize(bits, p=0.5)[源]¶ 以给定的概率随机地对图像进行色调分离,方法是减少每个颜色通道的位数。如果图像是 torch Tensor,它应该是 torch.uint8 类型,并且预期具有 […, 1 或 3, H, W] 的形状,其中 … 表示任意数量的前导维度。如果 img 是 PIL Image,则预期模式为 “L” 或 “RGB”。 参数: bits (int) – 每个通道保留的位数 (0-8) p (float) – 图像被色调分离的概率。默认值为 0.5 使用 RandomPosterize 的示例 变换示例 变换示例 forward(img)[源]¶ 参数: img (PIL Image 或 Tensor) – 要进行色调分离的图像。 返回: 随机进行色调分离后的图像。 返回类型: PIL Image 或 Tensor