Open In App

Tensorflow.js tf.disposeVariables() Function

Last Updated : 08 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads