mindspore.dataset.vision.CutOut

View Source On Gitee
class mindspore.dataset.vision.CutOut(length, num_patches=1, is_hwc=True)[source]

Randomly cut (mask) out a given number of square patches from the input image array.

Parameters
  • length (int) – The side length of each square patch, must be larger than 0.

  • num_patches (int, optional) – Number of patches to be cut out of an image, must be larger than 0. Default: 1.

  • is_hwc (bool, optional) – Whether the input image is in HWC format. True - HWC format, False - CHW format. Default: True.

Raises
  • TypeError – If length is not of type integer.

  • TypeError – If is_hwc is not of type bool.

  • TypeError – If num_patches is not of type integer.

  • ValueError – If length is less than or equal 0.

  • ValueError – If num_patches is less than or equal 0.

  • RuntimeError – If given tensor shape is not <H, W, C>.

Supported Platforms:

CPU

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.CutOut(80, num_patches=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.CutOut(20)(data)
>>> print(output.shape, output.dtype)
(100, 100, 3) uint8
Tutorial Examples: