Wednesday, July 3, 2024
HomeLanguagesJavascriptTensorflow.js tf.io.listModels() Function

Tensorflow.js tf.io.listModels() 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 .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

 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments