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.

PR

Just a small problem.

I can fix it online!

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.ops.batch_to_space_nd

View Source On Gitee
mindspore.ops.batch_to_space_nd(input_x, block_shape, crops)[source]

Divides batch dimension with blocks and interleaves these blocks back into spatial dimensions.

This operation will divide batch dimension N into blocks with block_shape, the output tensor’s N dimension is the corresponding number of blocks after division. The output tensor’s w1,...,wM dimension is the product of original w1,...,wM dimension and block_shape with given amount to crop from dimension, respectively.

If the input shape is (n,c1,...ck,w1,...,wM), the output shape is (n,c1,...ck,w1,...,wM), where

n=n//(block_shape[0]...block_shape[M1])wi=wiblock_shape[i1]crops[i1][0]crops[i1][1]
Parameters
  • input_x (Tensor) – The input tensor. It must be greater or equal to 2-D tensor(equal to 4-D tensor on Ascend), batch dimension must be divisible by product of block_shape.

  • block_shape (Union[list(int), tuple(int), int]) – The block shape of dividing block with all value greater than or equal to 1. If block_shape is a tuple or list, the length of block_shape is M corresponding to the number of spatial dimensions. If block_shape is an int, the block size of M dimensions are the same, equal to block_shape. In this case of Ascend, M must be 2.

  • crops (Union[list(int), tuple(int)]) – The crops values for spatial dimensions, containing M subtraction list. Each contains 2 integer values. All values must be >= 0. crops[i] specifies the crops values for spatial dimension i, which corresponds to input dimension i + offset,where offset = N-M, and N is the number of input dimensions. It is required that input_shape[i+offset]block_shape[i]>crops[i][0]+crops[i][1]

Returns

Tensor, the output tensor with the same type as input.

Raises
  • TypeError – If block_shape is not one of list, tuple, int.

  • TypeError – If crops is neither list nor tuple.

  • ValueError – If block_shape is not one dimensional when block_shape is a list or tuple.

  • ValueError – If the length of block_shape is not 2 on Ascend.

  • ValueError – If the element of block_shape is not an integer larger than or euqal to 1.

  • ValueError – If shape of crops is not (M, 2), where M is the length of block_shape.

  • ValueError – If the element of crops is not an integer larger than or euqal to 0.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> block_shape = [2, 2]
>>> crops = [[0, 0], [0, 0]]
>>> input_x = Tensor(np.array([[[[1]]], [[[2]]], [[[3]]], [[[4]]]]), mindspore.float32)
>>> output = ops.batch_to_space_nd(input_x, block_shape, crops)
>>> print(output)
[[[[1.  2.]
   [3.  4.]]]]