mindspore.ops.SpaceToBatchND
- class mindspore.ops.SpaceToBatchND(block_shape, paddings)[source]
Divides spatial dimensions into blocks and combines the block size with the original batch.
This operation will divide spatial dimensions into blocks with block_shape, and then the output tensor’s spatial dimension is the corresponding number of blocks after division. The output tensor’s batch dimension is the product of the original batch and all elements in block_shape. Before division, the spatial dimensions of the input are zero padded according to paddings if necessary.
- Parameters
block_shape (Union[list(int), tuple(int), int]) – The block shape of dividing block with all elements greater than 1. If block_shape is a list or tuple, the length of block_shape is the number of spatial dimensions, called M later. 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.
paddings (Union[tuple, list]) – The padding values for spatial dimensions, containing M subtraction list. Each contains 2 integer values. All values must be greater than 0. paddings[i] specifies the paddings for the spatial dimension i, which corresponds to the input dimension i + offset. For each i, input_shape[i + offset]+paddings[i][0]+paddings[i][1] should be divisible by block_shape[i].
- Inputs:
input_x (Tensor) - The input tensor. The input tensor must be a 4-D tensor on Ascend.
- Outputs:
Tensor, the output tensor with the same data type as the input. Assume the input shape is \((n, c_1, ... c_k, w_1, ..., w_M)\) with \(block\_shape\) and \(paddings\). The shape of the output tensor will be \((n', c_1, ... c_k, w'_1, ..., w'_M)\), where
\(n' = n*(block\_shape[0]*...*block\_shape[M])\)
\(w'_i = (w_i+paddings[i][0]+paddings[i][1])//block\_shape[i]\)
- Raises
TypeError – If block_shape is not one of list, tuple, int.
TypeError – If paddings 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 shape of paddings is not (M, 2), where M is the length of block_shape.
ValueError – If the element of block_shape is not an integer larger than 1.
ValueError – If the element of paddings is not an integer larger than 0.
- Supported Platforms:
Ascend
CPU
Examples
>>> block_shape = [2, 2] >>> paddings = [[0, 0], [0, 0]] >>> space_to_batch_nd = ops.SpaceToBatchND(block_shape, paddings) >>> input_x = Tensor(np.array([[[[1, 2], [3, 4]]]]), mindspore.float32) >>> output = space_to_batch_nd(input_x) >>> print(output) [[[[1.]]] [[[2.]]] [[[3.]]] [[[4.]]]]