Skip to content
Related Articles

Related Articles

Tensorflow.js tf.io.listModels() Function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 18 Dec, 2021

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 .listModels() function is used to record each and every models accumulated in the registered repository means. Moreover, in case of a web browser environment, the recorded mediums are Local Storage as well as IndexedDB.

Syntax :

tf.io.listModels()

Parameters:  

It does not contain any parameter.

Return Value: It returns Promise of {[url: string]: ModelArtifactsInfo}.

Example 1: Using “logSigmoid” as activation, “Local Storage” as storage medium.

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 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://display/command/mymodel": {
    "dateSaved": "2021-06-24T12:20:15.292Z",
    "modelTopologyType": "JSON",
    "modelTopologyBytes": 613,
    "weightSpecsBytes": 126,
    "weightDataBytes": 252
  },
  "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
  }
}

Example 2: Using “prelu” as activation, “IndexedDB” 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: 7, inputShape: [50], stimulation: 'prelu'}));
 
// Calling save() method with a storage medium
 
// 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://display/command/mymodel":{"dateSaved":"2021-06-24T12:20:15.292Z",
"modelTopologyType":"JSON","modelTopologyBytes":613,"weightSpecsBytes":126,"weightDataBytes":252},
"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-24T12:28:27.419Z",
"modelTopologyType":"JSON","modelTopologyBytes":613,"weightSpecsBytes":126,"weightDataBytes":1428},
"indexeddb://display/command/mymodel":{"dateSaved":"2021-06-24T12:22:30.748Z",
"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.listModels

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!