Tensorflow.js tf.GraphModel class .dispose() Method
Last Updated :
10 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 .dispose() function is used to free the memory that is being utilized by the weight tensors as well as resourceManager.
Syntax:
dispose()
Parameters:
This method do not holds any parameter.
Return Value: It returns void.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const model_Url =
const mymodel = await tf.loadGraphModel(model_Url);
mymodel.dispose();
console.log( 'Model Disposed.' );
|
Output:
Model Disposed.
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const model_Url =
const mymodel = await tf.loadGraphModel(model_Url);
const inputs = tf.zeros([1, 224, 224, 3]);
mymodel.dispose();
mymodel.execute(inputs).print();
|
Output:
An error occurred
Cannot read property 'backend' of undefined
Here, an error occurred and the output is not printed as the stated model is already disposed. So, the execute() method is not able to return any output.
Reference: https://js.tensorflow.org/api/latest/#tf.GraphModel.dispose
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...