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

Related Articles

Tensorflow.js tf.disposeVariables() 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 .disposeVariables() function is used to dispose every single variable stored in the backend engine.

Syntax:

tf.disposeVariables()

Parameters: This method does not accept any parameters.

Return Value: It returns void.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Declaring a variable
var x = tf.tensor([1, 2, 3, 4]);
 
// Calling disposeVariables() method
tf.disposeVariables();
 
// Printing output
console.log("Variables disposed.")

Output: 

Variables disposed.

Example 2: 

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Declaring two tensors
var t1 = tf.tensor([1.1, 2.1, 3.1]);
var t2 = tf.tensor([null, 0, -2]);
 
// Calling dispose() and disposeVariables()
// method
tf.dispose(t2);
tf.disposeVariables();
 
// Printing outputs
console.log(t1);
console.log(t2);

Output: 

Tensor
    [1.1, 2.0999999, 3.0999999]

An error occurred on line: 15
Tensor is disposed.

Here, an error occurred for the tensor t2 as its disposed. 

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

 

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