Thursday, February 5, 2026
HomeLanguagesJavascriptTensorflow.js tf.setBackend() Function

Tensorflow.js tf.setBackend() 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. 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.setBackend() function is used to set the current backend name.

Syntax:

tf.setBackend( backendName )

Parameters:

  • backendName: The name of the backend.

Return Value: It returns Promise <boolean>

Example 1: In this example, we have set the backend to string “cpu”. Then it’s set to string “webgl” and the backend is removed returning “null” string.

Javascript




// Setting the backend
tf.setBackend("cpu")
console.log(tf.getBackend())
  
tf.setBackend("webgl")
tf.removeBackend("webgl")
console.log(tf.getBackend())


Output:

cpu
null

Example 2: In this example, we have set the backend to string “cpu”. The backend is removed returning a “null” in the console. We set the backend to “webgl” returning backend as string “webgl”.

Javascript




// Setting the backend
tf.setBackend("cpu")
tf.removeBackend('cpu')
console.log(tf.getBackend())
  
tf.setBackend("webgl")
  
// Getting the backend using
// getBackend method
console.log(tf.getBackend())


Output:

null
webgl

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32481 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6857 POSTS0 COMMENTS
Nicole Veronica
11982 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12069 POSTS0 COMMENTS
Shaida Kate Naidoo
6992 POSTS0 COMMENTS
Ted Musemwa
7230 POSTS0 COMMENTS
Thapelo Manthata
6940 POSTS0 COMMENTS
Umr Jansen
6923 POSTS0 COMMENTS