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)[source]¶
隨機選擇輸入圖片或影片中的矩形區域,並清除其像素。
此轉換不支援 PIL Image。 Zhong 等人的 ‘Random Erasing Data Augmentation’。 請參閱 https://arxiv.org/abs/1708.04896
- 參數:
p (float, optional) – 執行隨機清除操作的機率。
scale (tuple of python:float, optional) – 清除區域相對於輸入圖片的比例範圍。
ratio (python:float 的 tuple, optional) – 抹除區域的長寬比範圍。
value (數字 或 數字的 tuple) – 抹除值。預設值為 0。如果是一個整數,則用於抹除所有像素。如果是長度為 3 的 tuple,則分別用於抹除 R、G、B 通道。如果是字串 ‘random’,則使用隨機值抹除每個像素。
inplace (bool, optional) – 布林值,用於設定是否就地 (inplace) 執行此轉換。預設值為 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(), >>> ])