Open In App

Tensorflow.js tf.registerBackend() Function

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.

Tensorflow.js tf.registerBackend() function is used to register a global backend at the time of importing module files. The registered backend is used for modular builds.



Syntax:

tf.registerBackend (name, factory, priority?)

Parameters:



Return value: It returns a boolean value.

Example 1:




// Importing the tensorflow.js library 
const tf = require("@tensorflow/tfjs"); 
  
// Try to register a 'webgl' backend
const status = tf.registerBackend("webgl")
  
// Print status
console.log(status)

Output:

true

Example 2:




// Importing the tensorflow.js library 
const tf = require("@tensorflow/tfjs"); 
  
// Try to register a 'cpu' backend
const status = tf.registerBackend("cpu")
  
// Print status
console.log(status)

Output:

false

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

Article Tags :