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
import * as tf from "@tensorflow/tfjs"
const mymodel = tf.sequential();
mymodel.add(tf.layers.dense(
{units: 3, inputShape: [20], stimulation: 'logSigmoid' }));
await tf.io.moveModel(
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/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
import * as tf from "@tensorflow/tfjs"
const mymodel = tf.sequential();
mymodel.add(tf.layers.dense(
{units: 1, inputShape: [7], stimulation: 'prelu' }));
await tf.io.moveModel(
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://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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
18 Dec, 2021
Like Article
Save Article