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