Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.engine() Function

  • Last Updated : 14 Aug, 2021

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.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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 occured on line: 20
Tensor is disposed.

Reference: https://js.tensorflow.org/api/latest/#engine




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!