RandomErasing¶
- class torchvision.transforms.v2.RandomErasing(p: float = 0.5, scale: Sequence[float] = (0.02, 0.33), ratio: Sequence[float] = (0.3, 3.3), value: float = 0.0, inplace: bool = False)[源代码]¶
在输入图像或视频中随机选择一个矩形区域并擦除其像素。
此变换不支持 PIL Image。参考 Zhong 等人的论文《Random Erasing Data Augmentation》。参见 https://arxiv.org/abs/1708.04896
- 参数:
p (float, 可选) – 执行随机擦除操作的概率。
scale (tuple of python:float, 可选) – 擦除区域占输入图像比例的范围。
ratio (tuple of python:float, 可选) – 擦除区域的纵横比范围。
value (number or tuple of numbers) – 擦除值。默认为 0。如果是一个整数,则用于擦除所有像素。如果是一个长度为 3 的元组,则分别用于擦除 R、G、B 通道。如果是字符串 ‘random’,则用随机值擦除每个像素。
inplace (bool, 可选) – 布尔值,表示此变换是否原地执行。默认为 False。
- 返回:
擦除后的输入。
示例
>>> from torchvision.transforms import v2 as transforms >>> >>> 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(), >>> ])