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

 


Previous Article
Next Article

Similar Reads

Tensorflow.js tf.layers.embedding() Function
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 tf.layers.embedding() function is used to map positive integers into dense vectors of fixed size. Syntax: tf.layers.embedding(args)Parameters: This function accepts
3 min read
Tensorflow.js tf.selu() Function
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 .selu() function is used to find the scaled exponential linear and is done element wise. Syntax: tf.selu(x) Where, x < 0 ? scale * alpha * (exp(x) - 1) : x Parame
1 min read
Tensorflow.js tf.io.removeModel() Function
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 .removeModel() function is used to remove a stated model by means of a URL provided from a recorded repository medium. Syntax: tf.io.removeModel(url) Parameters: url
3 min read
Tensorflow.js tf.relu6() Function
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 .relu6() function is used to find rectified linear 6 i.e. min(max(x, 0), 6) and is done element wise. Syntax : tf.relu6(x) Parameters: x: It is the stated tensor inp
1 min read
Tensorflow.js tf.unique() Function
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .unique() function is used to find unique elements along an axis of a tensor. Syntax: tf.unique (x, axis?) Parameters : x: It is a first tensor input that can
2 min read
Tensorflow.js tf.layers.elu() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or Node.js. The tf.layers.elu() function is abbreviated as Exponential L
2 min read
Tensorflow.js tf.batchToSpaceND() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.batchToSpaceND() function is used to restructure the given "batch" from their zero dimension to "M+1" dimensions having shape of "block-Shape + [batch]", where block-Shape is th
2 min read
Tensorflow.js tf.concat() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.concat() function is used to concatenate the list of specified Tensors along the given axis. Syntax: tf.concat (tensors, axis)Parameters: This function accepts two parameters wh
2 min read
Tensorflow.js tf.layers.globalMaxPooling1d() Function
Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. The tf.layers.globalMaxPooling1d() function is us
2 min read
Tensorflow.js tf.ready() Function
Introduction: 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 .ready() function is used to return a promise which determines at what time the recently picked backend or else the topmost priority one has been initi
1 min read