Open In App

Tensorflow.js tf.io.http() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • path: The stated URL path to the model. Moreover, it could be a complete HTTP path i.e. ‘http://localhost:8000/model-upload’ or a comparable path i.e. ‘./model-upload’. It is of type string.
  • loadOptions: The stated configuration for the purpose of loading. It is optional and is of type LoadOptions. It comprises the following fields:
    1. weightPathPrefix: The stated optional prefix of path for the weight files. In addition, the by default value of this is evaluated from the path param.
    2. fetchFunc: The stated optional custom fetch function.
    3. onProgress: The stated optional progress callback function, it is released at regular intervals prior to the completion of load.

Return Value: It returns IOHandler.

Example 1:

Javascript




// 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:

Javascript




// 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



Last Updated : 30 Aug, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads