Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.profile() Function

  • Last Updated : 31 May, 2021

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.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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
Recommended Articles
Page :