mindspore.ops.SpaceToDepth

class mindspore.ops.SpaceToDepth(*args, **kwargs)[source]

Rearranges blocks of spatial data into depth.

The output tensor’s height dimension is \(height / block\_size\).

The output tensor’s weight dimension is \(weight / block\_size\).

The depth of output tensor is \(block\_size * block\_size * input\_depth\).

The input tensor’s height and width must be divisible by block_size. The data format is “NCHW”.

Parameters

block_size (int) – The block size used to divide spatial data. It must be >= 2.

Inputs:
  • x (Tensor) - The target tensor.

Outputs:

Tensor, the same data type as x. It must be a 4-D tensor.

Raises
  • TypeError – If block_size is not an int.

  • ValueError – If block_size is less than 2.

  • ValueError – If length of shape of x is not equal to 4.

Supported Platforms:

Ascend

Examples

>>> x = Tensor(np.random.rand(1,3,2,2), mindspore.float32)
>>> block_size = 2
>>> space_to_depth = ops.SpaceToDepth(block_size)
>>> output = space_to_depth(x)
>>> print(output.shape)
(1, 12, 1, 1)