Open In App
Related Articles

Tensorflow.js tf.engine() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 13 Jun, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials