Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

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_heightnum_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: