📜  Tensorflow.js tf.io.listModels()函数

📅  最后修改于: 2022-05-13 01:58:10.595000             🧑  作者: Mango

Tensorflow.js tf.io.listModels()函数

Tensorflow.js 是一个由谷歌开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

.listModels()函数用于记录在注册存储库中累积的每个模型。此外,在 Web 浏览器环境的情况下,记录的介质是Local Storage以及IndexedDB

句法 :

tf.io.listModels()

参数:

它不包含任何参数。

返回值:返回 {[url: 字符串]: ModelArtifactsInfo} 的 Promise。

示例1:使用“ logSigmoid ”作为激活,“ Local Storage ”作为存储介质。

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
await mymodel.save('localstorage://display/command/mymodel');
 
// Calling listModels() method and
// Printing output
console.log(await tf.io.listModels());


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
await mymodel.save('indexeddb://example/command/mymodel');
 
// Calling listModels() method and
// Printing output
console.log(JSON.stringify(await tf.io.listModels()));


输出:

{
  "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
  }
}

示例 2:使用“ prelu ”作为激活,“ IndexedDB ”作为存储介质和“ JSON.stringify ”以返回字符串格式的输出。

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
await mymodel.save('indexeddb://example/command/mymodel');
 
// Calling listModels() method and
// Printing output
console.log(JSON.stringify(await tf.io.listModels()));


输出:

{"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}}

参考: https://js.tensorflow.org/api/latest/#io.listModels