Tensorflow.js tf.io.removeModel() Function
Last Updated :
13 Jan, 2022
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 .removeModel() function is used to remove a stated model by means of a URL provided from a recorded repository medium.
Syntax:
tf.io.removeModel(url)
Parameters:
- url: It is the stated URL within a recorded model, along with a pattern prefix i.e. ‘localstorage://my-mode-2’, ‘indexeddb://my/mode/3’. It is of type string.
Return Value: It returns Promise of ModelArtifactsInfo.
Example 1: Using “logSigmoid” as activation, “Local Storage” as the storage medium.
Javascript
import * as tf from "@tensorflow/tfjs"
const mymodel = tf.sequential();
mymodel.add(tf.layers.dense(
{units: 3, inputShape: [20], stimulation: 'logSigmoid' }));
console.log(await tf.io.listModels());
|
Output:
{
"localstorage://demo/manage/model1": {
"dateSaved": "2021-06-24T11:53:05.626Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"localstorage://demo/management/model1": {
"dateSaved": "2021-06-24T11:52:29.368Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 611,
"weightSpecsBytes": 124,
"weightDataBytes": 44
},
"localstorage://demo/management/model2": {
"dateSaved": "2021-06-24T11:53:33.384Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"localstorage://demo/management/model": {
"dateSaved": "2021-06-24T11:53:26.006Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"localstorage://display/command/mymodel2": {
"dateSaved": "2021-06-24T19:02:03.367Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 612,
"weightSpecsBytes": 125,
"weightDataBytes": 32
},
"indexeddb://demo/management/model1": {
"dateSaved": "2021-06-24T13:02:20.265Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 614,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"indexeddb://display/command/mymodel": {
"dateSaved": "2021-06-24T18:50:50.602Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 252
},
"indexeddb://display/command/mymodel1": {
"dateSaved": "2021-06-24T18:59:17.435Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 612,
"weightSpecsBytes": 125,
"weightDataBytes": 32
},
"indexeddb://example/command/mymodel": {
"dateSaved": "2021-06-24T12:33:06.208Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 1428
}
}
Example 2: Using “prelu” as activation, “IndexedDB” as a storage medium, and “JSON.stringify” in order to return the output in string format.
Javascript
import * as tf from "@tensorflow/tfjs"
const mymodel = tf.sequential();
mymodel.add(tf.layers.dense(
{units: 11, inputShape: [6], stimulation: 'prelu' }));
console.log(JSON.stringify(await tf.io.listModels()));
|
Output:
{
"localstorage://demo/manage/model1": {
"dateSaved": "2021-06-24T11:53:05.626Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"localstorage://demo/management/model1": {
"dateSaved": "2021-06-24T11:52:29.368Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 611,
"weightSpecsBytes": 124,
"weightDataBytes": 44
},
"localstorage://demo/management/model2": {
"dateSaved": "2021-06-24T11:53:33.384Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"localstorage://demo/management/model": {
"dateSaved": "2021-06-24T11:53:26.006Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"localstorage://display/command/mymodel2": {
"dateSaved": "2021-06-24T19:02:03.367Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 612,
"weightSpecsBytes": 125,
"weightDataBytes": 32
},
"indexeddb://demo/management/model1": {
"dateSaved": "2021-06-24T13:02:20.265Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 614,
"weightSpecsBytes": 126,
"weightDataBytes": 44
},
"indexeddb://display/command/mymodel": {
"dateSaved": "2021-06-24T18:50:50.602Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 252
},
"indexeddb://example/command/mymodel": {
"dateSaved": "2021-06-24T12:33:06.208Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 613,
"weightSpecsBytes": 126,
"weightDataBytes": 1428
}
}
Reference: https://js.tensorflow.org/api/latest/#io.removeModel
Share your thoughts in the comments
Please Login to comment...