Tensorflow.js es una biblioteca de código abierto desarrollada por Google para ejecutar modelos de aprendizaje automático, así como redes neuronales de aprendizaje profundo en el entorno del navegador o del Node.
La función .moveModel() se usa para mover un modelo de una URL hacia una nueva. Además, este método favorece el movimiento dentro de un medio de almacenamiento, es decir, dentro de un mismo tipo de medio grabado o entre dos medios de almacenamiento, es decir, entre diferentes tipos de medios grabados.
Sintaxis:
tf.io.moveModel(sourceURL, destURL)
Parámetros:
- sourceURL: es la URL de origen indicada de la mudanza. Es de tipo string.
- destURL: es la URL de destino indicada de la mudanza. Es de tipo string.
Valor devuelto: Devuelve Promesa de ModelArtifactsInfo .
Ejemplo 1:
- Movimiento entre dos tipos diferentes de medios de almacenamiento.
- Usando «logSigmoid» como activación, «Almacenamiento local» e «IndexedDB» como medios de almacenamiento.
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 moveModel() method with its parameters await tf.io.moveModel( 'localstorage://display/command/mymodel', 'indexeddb://display/command/mymodel1'); // Calling listModels() method and // Printing output console.log(await tf.io.listModels());
Producción:
{ "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 } }
Ejemplo 2:
- Movimiento dentro del mismo tipo de medios de almacenamiento.
- Usando «prelu» como activación, «Almacenamiento local» como medio de almacenamiento y «JSON.stringify» para devolver la salida en formato de string.
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 await mymodel.save('localstorage://display/command/mymodel1'); // Calling moveModel() method with its parameters await tf.io.moveModel( 'localstorage://display/command/mymodel1', 'localstorage://display/command/mymodel2'); // Calling listModels() method and // Printing output console.log(JSON.stringify(await tf.io.listModels()));
Producción:
{ "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 } }
Referencia: https://js.tensorflow.org/api/latest/#io.moveModel
Publicación traducida automáticamente
Artículo escrito por nidhi1352singh y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA