Tensorflow.js tf.memory() Function Last Updated : 09 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Tensorflow.js tf.memory() function is used to get memory info of the program at the current time. This function returns a memoryInfo object with the following properties: numBytes: It specifies the number of undisposed bytes allocated at the current time.numTensors: It specifies the number of unique tensors allocated.numDataBuffers: It specifies the number of undisposed unique data buffers allocated at the current time, which is greater than or equal to the number of tensors.unreliable: unreliable is True only and only if the memory usage is unreliable.reasons: It specifies an array of string, which represents the reasons why memory is unreliable. WebGL Properties: numBytesInGPU: It specifies the total number of undisposed bytes allocated in the GPU at the current time. Syntax: tf.memory() Parameters: This function do not accept any parameter. Return value: It returns a memoryInfo object. Example 1: Example to print number the allocated tensors. JavaScript // Importing the tensorflow.js library const tf = require("@tensorflow/tfjs"); // Declaring a variable let res1 // Calling tidy method const res2 = tf.tidy(() => { // Defining result parameter const result = tf.scalar(121); // Calling tf.keep() method res1 = tf.keep(result.sqrt()); }); // Printing the number of tensors allocated at this time console.log('numTensors: ' + tf.memory().numTensors); Output: numTensors: 1 Example 2: JavaScript // Importing the tensorflow.js library const tf = require("@tensorflow/tfjs"); // Declaring a variable let res1; // Calling tidy method const res2 = tf.tidy(() => { console.log('numTensors (in tidy) : ' + tf.memory().numTensors); // Calling tf.keep() method with its // parameter res1 = tf.keep(tf.tensor1d( [1.3, 0.5, 0, NaN, null, -.5]).cos()); }); // Printing memory information console.log('numBytes : ' + tf.memory().numBytes); console.log('numTensors (outside tidy): ' + tf.memory().numTensors); console.log('numDataBuffers : ' + tf.memory().numDataBuffers); Output: numTensors (in tidy) : 1 numBytes : 28 numTensors (outside tidy): 2 numDataBuffers : 2 Reference: https://js.tensorflow.org/api/latest/#memory Comment More infoAdvertise with us Next Article Tensorflow.js tf.tensor2d() Function A abhinavjain194 Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Performance Similar Reads 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 backe 1 min read Tensorflow.js tf.sum() 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.sum() function is used to calculate sum of the elements of a specified Tensor across its dimension. It reduces the given input 2 min read Tensorflow.js tf.oneHot() 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.oneHot() function is used to create a one-hot tf.Tensor. The locations represented by indices take the value as 1 (default valu 2 min read Tensorflow.js tf.tensor2d() 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 .tensor2d() function is used to create a new 2-dimensional tensor with the parameter namely value, shape, and datatype. Syntax: tf 3 min read Tensorflow.js tf.tensor5d() 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 .tensor5d() function is used to create a new 5-dimensional tensor with the parameters namely value, shape, and datatype. Syntax : 3 min read Tensorflow.js tf.tensor6d() 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 .tensor6d() function is used to create a new 6-dimensional tensor with the parameters namely value, shape, and datatype. Syntax: 3 min read Like