mindspore.ops.DepthToSpace

class mindspore.ops.DepthToSpace(block_size)[source]

Rearrange blocks of depth data into spatial dimensions.

This is the reverse operation of SpaceToDepth.

The depth of output tensor is input_depth/(block_sizeblock_size).

The output tensor's height dimension is heightblock_size.

The output tensor's weight dimension is weightblock_size.

The input tensor's depth must be divisible by block_size * block_size. The data format is "NCHW".

Parameters

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

Inputs:
  • x (Tensor) - The target tensor. It must be a 4-D tensor with shape (N,Cin,Hin,Win). The data type is Number.

Outputs:

Tensor of shape (N,Cin/block_size2,Hinblock_size,Winblock_size).

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 GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.random.rand(1, 12, 1, 1), mindspore.float32)
>>> block_size = 2
>>> depth_to_space = ops.DepthToSpace(block_size)
>>> output = depth_to_space(x)
>>> print(output.shape)
(1, 3, 2, 2)