mindspore.dataset.vision.c_transforms.SlicePatches

class mindspore.dataset.vision.c_transforms.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 (Inter, optional) – A mode represents pad or drop (default=SliceMode.PAD). It can be any of [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

>>> # default padding mode
>>> decode_op = c_vision.Decode()
>>> num_h, num_w = (1, 4)
>>> slice_patches_op = c_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 = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns=["image"],
...                                                 output_columns=cols, column_order=cols)