Tensorflow.js tf.time() Function
Tensorflow.js is an open-source library that was developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The tf.time() function is used to execute the stated function, f() as well as return a promise in order that determines along with timing details. The resultant is an object along with the properties like Wall execution time, Kernel execution time, excluding transfer of data. In case the WebGL backend is used as well as query ticker is unavailable then this method will throw an error object. Moreover, the WebGL backend will provide the further properties like uploadWaitMs i.e. blocking time of CPU on texture uploads, and downloadWaitMs i.e. blocking time of CPU on texture downloads.
Syntax:
tf.time(f)
Parameters: This function accepts a single parameter as mentioned below:
- f: It is the stated function to execute as well as time.
Return Value: It returns a Promise of TimingInfo.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Using truncatedNormal() function in order to // define the parameter for the function used const p = tf.truncatedNormal([10, 10]); // Calling time() method and also using // dot() method const tm = await tf.time(() => p.dot(p)); // Printing output console.log(`Kernel execution time: ${tm.kernelMs}, Wall execution time: ${tm.wallMs}` ); |
Output:
Kernel execution time: 0.048498, Wall execution time: 85.19999992847443
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling time() method and also using // square() as well as ones() method const t = await tf.time(() => tf.square(tf.ones([15, 21]))); // Printing output for WebGL backend console.log(`uploadWaitMs: ${t.uploadWaitMs}, downloadWaitMs: ${t.downloadWaitMs}`); |
Output:
uploadWaitMs: 1.100000023841858, downloadWaitMs: 0
Reference: https://js.tensorflow.org/api/latest/#time
Please Login to comment...