mindspore.dataset.vision.SlicePatches
- 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 numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> # default padding mode >>> num_h, num_w = (1, 4) >>> slice_patches_op = vision.SlicePatches(num_h, num_w) >>> transforms_list = [slice_patches_op] >>> cols = ['img' + str(x) for x in range(num_h*num_w)] >>> >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, ... input_columns=["image"], ... output_columns=cols) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(len(item), item["img0"].shape, item["img0"].dtype) ... break 4 (100, 25, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.SlicePatches(1, 2)(data) >>> print(np.array(output).shape, np.array(output).dtype) (2, 100, 50, 3) uint8 - Tutorial Examples: