Tensorflow.js tf.disposeVariables() Function
Last Updated :
08 Jun, 2022
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
import * as tf from "@tensorflow/tfjs"
var x = tf.tensor([1, 2, 3, 4]);
tf.disposeVariables();
console.log( "Variables disposed." )
|
Output:
Variables disposed.
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
var t1 = tf.tensor([1.1, 2.1, 3.1]);
var t2 = tf.tensor([ null , 0, -2]);
tf.dispose(t2);
tf.disposeVariables();
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
Share your thoughts in the comments
Please Login to comment...