Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Tensorflow.js tf.engine() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 library
import * as tf from "@tensorflow/tfjs"
 
// Calling engine() and startScope()
// method
tf.engine().startScope(); 
 
// Calling ones() method
const res = tf.ones([200, 250]);
 
// Printing output
console.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 library
import * as tf from "@tensorflow/tfjs"
 
// Calling engine() and startScope()
// method
tf.engine().startScope(); 
 
// Calling ones() method
const t1 = tf.ones([200, 250]);
 
// Calling tidy() and min() method
// with respect to t1
const t2 = tf.tidy(() => t1.min());
 
// Calling engine() and endScope()
// method
tf.engine().endScope();
 
// Printing output
console.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

My Personal Notes arrow_drop_up
Last Updated : 13 Jun, 2022
Like Article
Save Article
Similar Reads
Related Tutorials