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 numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.transforms import Compose >>> >>> # Use the transform in dataset pipeline mode >>> transforms_list = Compose([vision.ToTensor(), ... vision.RandomErasing(value='random')]) >>> # apply the transform to dataset through map function >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image") >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (3, 100, 100) float32 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(254, 255, size=(3, 100, 100)).astype(np.uint8) >>> output = vision.RandomErasing(prob=1.0, max_attempts=1)(data) >>> print(output.shape, output.dtype) (3, 100, 100) uint8
- Tutorial Examples: