mindspore.dataset.vision.CutOut

查看源文件
class mindspore.dataset.vision.CutOut(length, num_patches=1, is_hwc=True)[源代码]

从输入图像数组中随机裁剪出给定数量的正方形区域。

参数:
  • length (int) - 每个正方形区域的边长,必须大于 0。

  • num_patches (int, 可选) - 要从图像中切出的正方形区域数,必须大于0。默认值: 1

  • is_hwc (bool, 可选) - 表示输入图像是否为HWC格式, True 为HWC格式, False 为CHW格式。默认值: True

异常:
  • TypeError - 如果 length 不是int类型。

  • TypeError - 如果 num_patches 不是int类型。

  • TypeError - 如果 is_hwc 不是bool类型。

  • ValueError - 如果 length 小于或等于 0。

  • ValueError - 如果 num_patches 小于或等于 0。

  • RuntimeError - 如果输入图像的shape不是 <H, W, C>。

支持平台:

CPU

样例:

>>> 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
教程样例: