Tensorflow.js tf.spaceToBatchND() Function
Last Updated :
21 Jul, 2021
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.spaceToBatchND() function is used to split the spatial dimensions of the specified input space into a matrix of blocks having shape of blockShape, where blockshape is the parameter. Here the spatial dimensions are padded according to the specified padding array.
Syntax:
tf.spaceToBatchND (x, blockShape, paddings)
Parameters: This function accepts three parameters which are illustrated below:
- x: A specified Tensor of N-Dimension with shape of “[batch] + spatialShape + remainingShape”, where spatialShape is having M dimensions.
- blockShape: It is 1-D array which must be having shape of [M], for all the values must be greater than or equal to 1.
- paddings: A 2-D array having shape of [M, 2], for all the values must be greater than or equal to 0. Here padding is equal to [padStart, padEnd].
Return Value: It returns a Tensor of the splitted version of the specified input space.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const x = tf.tensor4d(
[5, 10, 15, 20, 25, 30],
[1, 3, 2, 1]
);
const blockShape = [1, 1];
const paddings = [[0, 0], [0, 0]];
x.spaceToBatchND(blockShape, paddings).print();
|
Output:
Tensor
[[[[5 ],
[10]],
[[15],
[20]],
[[25],
[30]]]]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const x = tf.tensor4d([2, 4, 6, 8], [1, 2, 2, 1]);
x.spaceToBatchND([2, 2], [[0, 0], [0, 0]]).print();
|
Output:
Tensor
[ [ [[2],]],
[ [[4],]],
[ [[6],]],
[ [[8],]]]
Reference: https://js.tensorflow.org/api/latest/#spaceToBatchND
Share your thoughts in the comments
Please Login to comment...