Skip to content
Related Articles

Related Articles

Tensorflow.js tf.profile() Function

Improve Article
Save Article
  • Last Updated : 31 May, 2021
Improve Article
Save Article

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 in Node.js.

The tf.profile() function is used for executing the provided function and the function returns a Promise that resolves with information about its memory use.

Syntax:

tf.profile(f);

Parameters:

  • f: It is a callback function.

Return Value: It returns Promise.

Example:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing tensor and 
// Using .profile() function 
let geekProfile =
   await tf.profile(function (){
   let geek1 = tf.tensor2d([[1, 2, 3], [4, 5, 6]]);
   geek1.square();
   return geek1;
});
  
// Printing the result of returned Promise
console.log("peakBytes: ")
console.log(geekProfile.peakBytes);
console.log("kernelName: ");
console.log(geekProfile.kernelNames);


Output:

peakBytes: 
48
kernelName: 
Square

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing tensor and 
// Using .profile() function 
let geekProfile =
   await tf.profile(function (){
   let geek2 = tf.tensor4d([[[[7], [11]], [[13], [34]]]]);
   return geek2;
});
  
// Printing the result of returned Promise
console.log("newBytes ")
console.log(geekProfile.newBytes);


Output:

newBytes 
16

Reference: https://js.tensorflow.org/api/latest/#profile


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!