Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.ready() Function

  • Last Updated : 22 Aug, 2021

Introduction: Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .ready() function is used to return a promise which determines at what time the recently picked backend or else the topmost priority one has been initialized. Moreover, we need to await this promise if we are utilizing a backend that possesses asynchronous initialization.

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.ready()

Parameters: This method does not hold any parameter.



Return Value: It returns promise of void.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling setBackend() method
tf.setBackend('wasm');
  
// Calling ready() method and
// Printing output
await tf.ready().then(() => {
  console.log(tf.backend().blockSize)
});

Output:

48

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling setBackend() method
tf.setBackend('webgl');
  
// Calling ready() method and
// Printing output
await tf.ready().then(() => {
  console.log(JSON.stringify(tf.getBackend()))
});

Output:

"webgl"

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :