mindspore.ops.space_to_batch_nd

View Source On Gitee
mindspore.ops.space_to_batch_nd(input_x, block_size, paddings)[source]

Divides a tensor's spatial dimensions into blocks and combines the block sizes with the original batch.

n=n(block_size[0]...block_size[M])wi=(wi+paddings[i][0]+paddings[i][1])//block_size[i]

Note

  • This operation divides the spatial dimensions [1, …, M] of the input into blocks of size block_size and interleaves them into the batch dimension (default: dimension 0). Before splitting, the spatial dimensions are padded with zeros according to paddings.

  • If the input shape is (n,c1,...ck,w1,...,wM), then the output shape will be (n,c1,...ck,w1,...,wM).

  • If block_size is a tuple or list, the length of block_size is M corresponding to the number of spatial dimensions. If block_size is an int, the block size of M dimensions are the same, equal to block_size. M must be 2 on Ascend.

Parameters
  • input_x (Tensor) – The input tensor, must be a 4-D tensor on Ascend.

  • block_size (Union[list(int), tuple(int), int]) – Specifies the block size for spatial dimension division.

  • paddings (Union[tuple, list]) – The padding size for each spatial dimension.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> block_size = [2, 2]
>>> paddings = [[0, 0], [0, 0]]
>>> input_x = mindspore.tensor([[[[1, 2], [3, 4]]]], mindspore.float32)
>>> output = mindspore.ops.space_to_batch_nd(input_x, block_size, paddings)
>>> print(output)
[[[[1.]]]
 [[[2.]]]
 [[[3.]]]
 [[[4.]]]]