mindspore.dataset.vision.RandomErasing

class mindspore.dataset.vision.RandomErasing(prob=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=False, max_attempts=10)[source]

Randomly erase pixels within a random selected rectangle erea on the input numpy.ndarray image.

See Random Erasing Data Augmentation .

Parameters
  • prob (float, optional) – Probability of performing erasing, which must be in range of [0.0, 1.0]. Default: 0.5.

  • scale (Sequence[float, float], optional) – Range of area scale of the erased area relative to the original image to select from, arranged in order of (min, max). Default: (0.02, 0.33).

  • ratio (Sequence[float, float], optional) – Range of aspect ratio of the erased area to select from, arraged in order of (min, max). Default: (0.3, 3.3).

  • value (Union[int, str, Sequence[int, int, int]]) – Pixel value used to pad the erased area. If a single integer is provided, it will be used for all RGB channels. If a sequence of length 3 is provided, it will be used for R, G, B channels respectively. If a string of 'random' is provided, each pixel will be erased with a random value obtained from a standard normal distribution. Default: 0.

  • inplace (bool, optional) – Whether to apply erasing inplace. Default: False.

  • max_attempts (int, optional) – The maximum number of attempts to propose a valid erased area, beyond which the original image will be returned. Default: 10.

Raises
  • TypeError – If prob is not of type float.

  • TypeError – If scale is not of type sequence.

  • TypeError – If ratio is not of type sequence.

  • TypeError – If value is not of type integer, string, or sequence.

  • TypeError – If inplace is not of type boolean.

  • TypeError – If max_attempts is not of type integer.

  • ValueError – If prob is not in range of [0.0, 1.0].

  • ValueError – If scale is negative.

  • ValueError – If ratio is negative.

  • ValueError – If value is not in range of [0, 255].

  • ValueError – If max_attempts is not positive.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.transforms import Compose
>>>
>>> transforms_list = Compose([vision.Decode(to_pil=True),
...                            vision.ToTensor(),
...                            vision.RandomErasing(value='random')])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")
Tutorial Examples: