mindspore.dataset.vision.py_transforms.RandomErasing
- class mindspore.dataset.vision.py_transforms.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. 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 int is provided, it will be used for all RGB channels. If Sequence[int, int, int] 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[float, float].
TypeError – If ratio is not of type Sequence[float, float].
TypeError – If value is not of type int, str, or Sequence[int, int, int].
TypeError – If inplace is not of type bool.
TypeError – If max_attempts is not of type int.
ValueError – If prob is not in range of [0, 1].
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
>>> from mindspore.dataset.transforms.py_transforms import Compose >>> >>> transforms_list = Compose([py_vision.Decode(), ... py_vision.ToTensor(), ... py_vision.RandomErasing(value='random')]) >>> # apply the transform to dataset through map function >>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list, ... input_columns="image")