RandomErasing

class paddle.vision.transforms. RandomErasing ( prob=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=False, keys=None ) [source]

Erase the pixels in a rectangle region selected randomly.

Parameters
  • prob (float, optional) – Probability of the input data being erased. Default: 0.5.

  • scale (sequence, optional) – The proportional range of the erased area to the input image. Default: (0.02, 0.33).

  • ratio (sequence, optional) – Aspect ratio range of the erased area. Default: (0.3, 3.3).

  • value (int|float|sequence|str, optional) – The value each pixel in erased area will be replaced with. If value is a single number, all pixels will be erased with this value. If value is a sequence with length 3, the R, G, B channels will be ereased respectively. If value is set to “random”, each pixel will be erased with random values. Default: 0.

  • inplace (bool, optional) – Whether this transform is inplace. Default: False.

  • keys (list[str]|tuple[str], optional) – Same as BaseTransform. Default: None.

Shape:
  • img(paddle.Tensor | np.array | PIL.Image): The input image. For Tensor input, the shape should be (C, H, W).

    For np.array input, the shape should be (H, W, C).

  • output(paddle.Tensor | np.array | PIL.Image): A random erased image.

Returns

A callable object of RandomErasing.

Examples

>>> import paddle

>>> fake_img = paddle.randn((1, 5, 5)).astype(paddle.float32)
>>> transform = paddle.vision.transforms.RandomErasing()
>>> result = transform(fake_img)
>>> 
>>> print(result)
Tensor(shape=[1, 5, 5], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[[[-0.22141267, -0.71004093,  1.71224928,  2.99622107, -0.82959402],
  [ 0.36916021, -0.25601348,  0.86669374,  1.27504587, -0.56462914],
  [-0.45704395, -0.87613666,  1.12195814, -0.87974882,  0.04902615],
  [-0.91549885, -0.15066874,  1.26381516,  0.        ,  0.        ],
  [ 0.87887472, -1.59914243, -0.73970413,  0.        ,  0.        ]]])