Tensorflow.js tf.io.moveModel() 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 .moveModel() function is used to move a model away from one URL towards a new one. Moreover, this method favors movement either inside a storage medium i.e. within a same kind of recorded medium or between two storage mediums i.e. between different kind of recorded mediums.
Syntax:
tf.io.moveModel(sourceURL, destURL)
Parameters:
- sourceURL: It is the stated source URL of moving. It is of type string.
- destURL: It is the stated destination URL of moving. It is of type string.
Return Value: It returns Promise of ModelArtifactsInfo.
Example 1:
- Movement between two different kind of storage mediums.
- Using “logSigmoid” as activation, “Local Storage” and “IndexedDB” as storage mediums.
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 moveModel() method with its parametersawait tf.io.moveModel(// 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/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://demo/management/model1": {
"dateSaved": "2021-06-24T11:52:29.368Z",
"modelTopologyType": "JSON",
"modelTopologyBytes": 611,
"weightSpecsBytes": 124,
"weightDataBytes": 44
},
"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:55:00.803Z",
"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
}
}Example 2:
- Movement inside same kind of storage mediums.
- Using “prelu” as activation, “Local Storage” as 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: 1, inputShape: [7], stimulation: 'prelu'}));// Calling save() method with a storage medium// Calling moveModel() method with its parametersawait tf.io.moveModel(// 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://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
}
}Reference: https://js.tensorflow.org/api/latest/#io.moveModel
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

