Tensorflow.js tf.depthToSpace() function
The tf.depthToSpace() is an inbuilt function of tensorflow.js library, which is used to rearrange data in the input tensor, where values from the depth dimension are moved in spatial blocks to the height and width dimensions. It rearranges data from depth into blocks of spatial data.
tensor.depthToSpace(input, blocksize, dataformat)
- input: the given tensor
- blocksize: the width of output tensor is depth *blockSize.
- dataformat: specifies the layout of the given and resulting tensor. It has two options: “NHWC”: [ batch, height, width, channels ] and “NCHW”: [ batch, channels, height, width ]
Return value: It returns the rearranged tensor of the same data type.
Example 1: Using “NHWC” format
Tensor [[[, ], [, ]]]
Example 2: using “NCHW” format
Tensor [[[[1, 3], [5, 7]]]]