Open In App

Tensorflow.js tf.io.http() Function

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 .io.http() function is used to generate an IOHandler subset which transmits model artifacts to the HTTP server. Moreover, an HTTP request of the multi-part or form-data mime type shall be transmitted to the path URL. Where, the form-data contains artifacts which describe the model topology and/or weights of the model. 



Syntax:

tf.io.http(path, loadOptions?)

Parameters:



Return Value: It returns IOHandler.

Example 1:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling io.http() method
const result = tf.io.http('https://js.tensorflow.org/api/latest/#io.http');
  
// Printing output
console.log(result);

Output:

{
  "DEFAULT_METHOD": "POST",
  "path": "https://js.tensorflow.org/api/latest/#io.http",
  "requestInit": {}
}

Example 2:




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Creating model
const model = tf.sequential();
  
// Adding layer to the model
model.add(
     tf.layers.dense({units: 2, inputShape: [10]}));
  
// Calling io.http() method within 
// save() method
const result = await model.save(tf.io.http(
  
// Printing output
console.log(result);

Output:

{
  "modelArtifactsInfo": {
    "dateSaved": "2021-08-26T08:43:49.648Z",
    "modelTopologyType": "JSON",
    "modelTopologyBytes": 611,
    "weightSpecsBytes": 124,
    "weightDataBytes": 88
  },
  "responses": [
    {}
  ]
}

Reference: https://js.tensorflow.org/api/latest/#io.http


Article Tags :