RandomErasing¶
- class torchvision.transforms.RandomErasing(p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=False)[source]¶
Randomly selects a rectangle region in an torch Tensor image and erases its pixels. This transform does not support PIL Image. ‘Random Erasing Data Augmentation’ by Zhong et al. See https://arxiv.org/abs/1708.04896
- Parameters:
p – probability that the random erasing operation will be performed.
scale – range of proportion of erased area against input image.
ratio – range of aspect ratio of erased area.
value – erasing value. Default is 0. If a single int, it is used to erase all pixels. If a tuple of length 3, it is used to erase R, G, B channels respectively. If a str of ‘random’, erasing each pixel with random values.
inplace – boolean to make this transform inplace. Default set to False.
- Returns:
Erased Image.
Example
>>> 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(), >>> ])
- forward(img)[source]¶
- Parameters:
img (Tensor) – Tensor image to be erased.
- Returns:
Erased Tensor image.
- Return type:
img (Tensor)
- static get_params(img: Tensor, scale: Tuple[float, float], ratio: Tuple[float, float], value: Optional[List[float]] = None) Tuple[int, int, int, int, Tensor] [source]¶
Get parameters for
erase
for a random erasing.- Parameters:
img (Tensor) – Tensor image to be erased.
scale (sequence) – range of proportion of erased area against input image.
ratio (sequence) – range of aspect ratio of erased area.
value (list, optional) – erasing value. If None, it is interpreted as “random” (erasing each pixel with random values). If
len(value)
is 1, it is interpreted as a number, i.e.value[0]
.
- Returns:
params (i, j, h, w, v) to be passed to
erase
for random erasing.- Return type: