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 等人的“随机擦除数据增强”。请参阅 https://arxiv.org/abs/1708.04896
- 参数:
p (float, 可选) – 执行随机擦除操作的概率。
scale (tuple of python:float, 可选) – 擦除区域占输入图像的比例范围。
ratio (tuple of python:float, 可选) – 擦除区域的纵横比范围。
value (number 或 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(), >>> ])