Open In App

Tensorflow.js tf.profile() Function

Improve
Improve
Like Article
Like
Save
Share
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. 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



Last Updated : 31 May, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads