Skip to content
Related Articles

Related Articles

Improve Article

Tensorflow.js tf.fetch() Function

  • Last Updated : 01 Sep, 2021

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 .fetch() function is used to return a platform dedicated operation of fetch. Moreover, in case fetch is specified in contact with the global object i.e. window, process, and so on, then tf.util.fetch returns that function else returns a platform dedicated explication.

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.fetch(path, requestInits?)

Parameters: 



  • path: It is the stated path which is of type string.
  • requestInits: The stated RequestInit. It is optional and is of type string.

Return Value: It returns the promise of response.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling fetch() method with respect 
// to global
const res = tf.env().global.fetch(
  
// Printing output
console.log(res);

Output:

[object Response]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling fetch() method
const res = await tf.util.fetch(
  
// Printing output
console.log(JSON.stringify(res));

Output:

{}

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :