mindspore.dataset.vision.SlicePatches

View Source On Gitee
class mindspore.dataset.vision.SlicePatches(num_height=1, num_width=1, slice_mode=SliceMode.PAD, fill_value=0)[source]

Slice Tensor to multiple patches in horizontal and vertical directions.

The usage scenario is suitable to large height and width Tensor. The Tensor will keep the same if set both num_height and num_width to 1. And the number of output tensors is equal to num_height*num_width.

Parameters
  • num_height (int, optional) – The number of patches in vertical direction, which must be positive. Default: 1.

  • num_width (int, optional) – The number of patches in horizontal direction, which must be positive. Default: 1.

  • slice_mode (SliceMode, optional) – A mode represents pad or drop. Default: SliceMode.PAD. It can be SliceMode.PAD, SliceMode.DROP.

  • fill_value (int, optional) – The border width in number of pixels in right and bottom direction if slice_mode is set to be SliceMode.PAD. The fill_value must be in range [0, 255]. Default: 0.

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

  • TypeError – If num_width is not of type integer.

  • TypeError – If slice_mode is not of type Inter.

  • TypeError – If fill_value is not of type integer.

  • ValueError – If num_height is not positive.

  • ValueError – If num_width is not positive.

  • ValueError – If fill_value is not in range [0, 255].

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

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>>
>>> # default padding mode
>>> decode_op = vision.Decode()
>>> num_h, num_w = (1, 4)
>>> slice_patches_op = vision.SlicePatches(num_h, num_w)
>>> transforms_list = [decode_op, slice_patches_op]
>>> cols = ['img' + str(x) for x in range(num_h*num_w)]
>>>
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns=["image"],
...                                                 output_columns=cols)
Tutorial Examples: