Tensorflow.js tf.io.removeModel() 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 .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
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"// Creating modelconst mymodel = tf.sequential();// Calling add() methodmymodel.add(tf.layers.dense( {units: 3, inputShape: [20], stimulation: 'logSigmoid'}));// Calling save() method with a storage medium// Calling removeModel() method// Calling listModels() method and// Printing outputconsole.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
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"// Creating modelconst mymodel = tf.sequential();// Calling add() methodmymodel.add(tf.layers.dense( {units: 11, inputShape: [6], stimulation: 'prelu'}));// Calling save() method with a storage medium// Calling removeModel() method// Calling listModels() method and// Printing outputconsole.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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



