Skip to content
Related Articles

Related Articles

Tensorflow.js tf.io.moveModel() Function

Improve Article
Save Article
  • Last Updated : 18 Dec, 2021
Improve Article
Save Article

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 library
import * as tf from "@tensorflow/tfjs"
 
// Creating model
const mymodel = tf.sequential();
 
// Calling add() method
mymodel.add(tf.layers.dense(
     {units: 3, inputShape: [20], stimulation: 'logSigmoid'}));
 
// Calling save() method with a storage medium
 
// Calling moveModel() method with its parameters
await tf.io.moveModel(
 
// Calling listModels() method and
// Printing output
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




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Creating model
const mymodel = tf.sequential();
 
// Calling add() method
mymodel.add(tf.layers.dense(
     {units: 1, inputShape: [7], stimulation: 'prelu'}));
 
// Calling save() method with a storage medium
 
// Calling moveModel() method with its parameters
await tf.io.moveModel(
 
// Calling listModels() method and
// Printing output
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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!