随机海报化¶ class torchvision.transforms.RandomPosterize(bits, p=0.5)[source]¶ 通过减少每个颜色通道的位数,以给定的概率随机对图像进行海报化处理。如果图像是torch张量,它应该是torch.uint8类型,并且期望具有[…, 1或3, H, W]形状,其中…表示任意数量的前导维度。如果图像是PIL图像,则期望其模式为“L”或“RGB”。 Parameters: bits (int) – 每个通道保留的位数 (0-8) p (float) – 图像被海报化的概率。默认值为0.5 使用RandomPosterize的示例: 变换的图示 Illustration of transforms forward(img)[source]¶ Parameters: img (PIL Image 或 Tensor) – 要进行海报化的图像。 Returns: 随机海报化的图像。 Return type: PIL 图像或张量