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
import * as tf from "@tensorflow/tfjs"
let geekProfile =
await tf.profile( function (){
let geek1 = tf.tensor2d([[1, 2, 3], [4, 5, 6]]);
geek1.square();
return geek1;
});
console.log( "peakBytes: " )
console.log(geekProfile.peakBytes);
console.log( "kernelName: " );
console.log(geekProfile.kernelNames);
|
Output:
peakBytes:
48
kernelName:
Square
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
let geekProfile =
await tf.profile( function (){
let geek2 = tf.tensor4d([[[[7], [11]], [[13], [34]]]]);
return geek2;
});
console.log( "newBytes " )
console.log(geekProfile.newBytes);
|
Output:
newBytes
16
Reference: https://js.tensorflow.org/api/latest/#profile