mindspore.ops.batch_to_space_nd
- mindspore.ops.batch_to_space_nd(input_x, block_shape, crops)[source]
Divides the batch dimension into blocks and interleaves these blocks back into spatial dimensions.
Warning
This interface is deprecated and will be removed after version 2.9.0.
This operation will divide the 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 \(w_1, ..., w_M\) dimension is the product of original \(w_1, ..., w_M\) dimension and block_shape with given amount to crop from dimension, respectively.
If the input shape is \((n, c_1, ... c_k, w_1, ..., w_M)\), the output shape is \((n', c_1, ... c_k, w'_1, ..., w'_M)\), where
\[\begin{split}\begin{array}{ll} \\ n' = n//(block\_shape[0]*...*block\_shape[M-1]) \\ w'_i = w_i*block\_shape[i-1]-crops[i-1][0]-crops[i-1][1] \end{array}\end{split}\]- Parameters
input_x (Tensor) – The input tensor. It must be at least a 2-D tensor (equal to 4-D tensor on Ascend), the batch dimension must be divisible by product of block_shape.
block_shape (Union[list(int), tuple(int), int]) – The block shape for dividing the batch into blocks with all values 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 sizes 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
- Supported Platforms:
AscendGPUCPU
Examples
>>> import mindspore >>> block_shape = [2, 2] >>> crops = [[0, 0], [0, 0]] >>> input_x = mindspore.tensor([[[[1]]], [[[2]]], [[[3]]], [[[4]]]], mindspore.float32) >>> output = mindspore.ops.batch_to_space_nd(input_x, block_shape, crops) >>> print(output) [[[[1. 2.] [3. 4.]]]]