mindspore.dataset.vision.py_transforms.Cutout

class mindspore.dataset.vision.py_transforms.Cutout(length, num_patches=1)[source]

Randomly apply a given number of square patches of zeros to a location within the input numpy.ndarray image of shape (C, H, W).

See Terrance DeVries and Graham W. Taylor ‘Improved Regularization of Convolutional Neural Networks with Cutout’ 2017 on https://arxiv.org/pdf/1708.04552.pdf

Parameters
  • length (int) – The side length of each square patch.

  • num_patches (int, optional) – Number of patches to be applied to the image (default=1).

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

  • 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

>>> from mindspore.dataset.transforms.py_transforms import Compose
>>> transforms_list = Compose([py_vision.Decode(),
...                            py_vision.ToTensor(),
...                            py_vision.Cutout(80)])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")