mindspore.dataset.vision.Erase
- class mindspore.dataset.vision.Erase(top, left, height, width, value=0, inplace=False)[source]
Erase the input image with given value.
Supports Ascend hardware acceleration and can be enabled through the .device("Ascend") method.
- Parameters
top (int) – Vertical ordinate of the upper left corner of erased region.
left (int) – Horizontal ordinate of the upper left corner of erased region.
height (int) – Height of erased region.
width (int) – Width of erased region.
value (Union[float, Sequence[float, float, float]], optional) – Pixel value used to pad the erased area. Default:
0
. If float is provided, it will be used for all RGB channels. If Sequence[float, float, float] is provided, it will be used for R, G, B channels respectively.inplace (bool, optional) – Whether to apply erasing inplace. Default:
False
.
- Raises
TypeError – If top is not of type int.
ValueError – If top is negative.
TypeError – If left is not of type int.
ValueError – If left is negative.
TypeError – If height is not of type int.
ValueError – If height is not positive.
TypeError – If width is not of type int.
ValueError – If width is not positive.
TypeError – If value is not of type float or Sequence[float, float, float].
ValueError – If value is not in range of [0, 255].
TypeError – If inplace is not of type bool.
RuntimeError – If shape of the input image is not <H, W, C>.
- Supported Platforms:
CPU
Ascend
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> transforms_list = [vision.Erase(10,10,10,10)] >>> 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 (100, 100, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.Erase(10, 10, 10, 10)(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8
- Tutorial Examples:
- device(device_target='CPU')[source]
Set the device for the current operator execution.
When the device is Ascend, input type supports uint8 or float32 , input channel supports 1 and 3. The input data has a height limit of [4, 8192] and a width limit of [6, 4096]. The inplace parameter is not supported.
- Parameters
device_target (str, optional) – The operator will be executed on this device. Currently supports
CPU
andAscend
. Default:CPU
.- Raises
TypeError – If device_target is not of type str.
ValueError – If device_target is not within the valid set of ['CPU', 'Ascend'].
- Supported Platforms:
CPU
Ascend
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> transforms_list = [vision.Erase(10, 10, 10, 10, (100, 100, 100)).device("Ascend")] >>> 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 (100, 100, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.Erase(10, 10, 10, 10, (100, 100, 100)).device("Ascend")(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8
- Tutorial Examples: