Tensorflow.js tf.engine() Function
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .engine() function is used to return the global engine which saves the path of every single tensor as well as backends.
Syntax:
tf.engine()
Parameters: This method does not hold any parameter.
Return Value: It returns Engine.
Example 1:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"// Calling engine() and startScope()// methodtf.engine().startScope(); // Calling ones() methodconst res = tf.ones([200, 250]);// Printing outputconsole.log(res); |
Output: Here, the scope is not ended so a tensor is returned.
Tensor
[[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1],
...,
[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1],
[1, 1, 1, ..., 1, 1, 1]]Example 2:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"// Calling engine() and startScope()// methodtf.engine().startScope(); // Calling ones() methodconst t1 = tf.ones([200, 250]);// Calling tidy() and min() method// with respect to t1const t2 = tf.tidy(() => t1.min());// Calling engine() and endScope()// methodtf.engine().endScope();// Printing outputconsole.log(t2); |
Output: Here, the scope is ended so the resultant tensor is being disposed.
An error occurred on line: 20 Tensor is disposed.
Reference: https://js.tensorflow.org/api/latest/#engine


