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:
- 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:
- 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.
- fetchFunc: The stated optional custom fetch function.
- 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
import * as tf from "@tensorflow/tfjs"
console.log(result);
|
Output:
{
"DEFAULT_METHOD": "POST",
"path": "https://js.tensorflow.org/api/latest/#io.http",
"requestInit": {}
}
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const model = tf.sequential();
model.add(
tf.layers.dense({units: 2, inputShape: [10]}));
const result = await model.save(tf.io.http(
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
Share your thoughts in the comments
Please Login to comment...