RandomErasing¶
- class torchvision.transforms.RandomErasing(p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=False)[source]¶
随机选择 torch.Tensor 图像中的一个矩形区域并擦除其像素。此变换不支持 PIL Image。“Random Erasing Data Augmentation” by Zhong et al. 参见 https://arxiv.org/abs/1708.04896
- 参数:
p – 执行随机擦除操作的概率。
scale – 擦除区域相对于输入图像的比例范围。
ratio – 擦除区域的宽高比范围。
value – 擦除值。默认为 0。如果为单个整数,则用于擦除所有像素。如果为长度为 3 的元组,则分别用于擦除 R、G、B 通道。如果为字符串 ‘random’,则用随机值擦除每个像素。
inplace – 布尔值,用于使此变换为原地操作。默认设置为 False。
- 返回:
已擦除的图像。
示例
>>> transform = transforms.Compose([ >>> transforms.RandomHorizontalFlip(), >>> transforms.PILToTensor(), >>> transforms.ConvertImageDtype(torch.float), >>> transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)), >>> transforms.RandomErasing(), >>> ])