Tensorflow.js tf.Tensor class .dispose() Method
Last Updated :
13 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 dispose the stated tf.Tensor from the memory.
Syntax:
dispose()
Parameters: This method does not hold any parameters.
Return Value: It returns void.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const t = tf.tensor([6, 7]);
t.dispose();
console.log( "Tensor Disposed." )
|
Output:
Tensor Disposed.
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const tn = tf.tensor2d([6, 7], [1, 2]);
const y = tn.dispose();
console.log(tn)
|
Output:
An error occurred on line: 11
Tensor is disposed.
Here, an error occurred while printing the tensor output as the tensor is already being disposed of.
Reference: https://js.tensorflow.org/api/latest/#tf.Tensor.dispose
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...