/**
|
* @license
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* you may not use this file except in compliance with the License.
|
* You may obtain a copy of the License at
|
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
* Unless required by applicable law or agreed to in writing, software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* See the License for the specific language governing permissions and
|
* limitations under the License.
|
* =============================================================================
|
*/
|
/// <amd-module name="@tensorflow/tfjs-core/dist/io/model_management" />
|
import { ModelArtifactsInfo, ModelStoreManager } from './types';
|
export declare class ModelStoreManagerRegistry {
|
private static instance;
|
private managers;
|
private constructor();
|
private static getInstance;
|
/**
|
* Register a save-handler router.
|
*
|
* @param saveRouter A function that maps a URL-like string onto an instance
|
* of `IOHandler` with the `save` method defined or `null`.
|
*/
|
static registerManager(scheme: string, manager: ModelStoreManager): void;
|
static getManager(scheme: string): ModelStoreManager;
|
static getSchemes(): string[];
|
}
|
/**
|
* List all models stored in registered storage mediums.
|
*
|
* For a web browser environment, the registered mediums are Local Storage and
|
* IndexedDB.
|
*
|
* ```js
|
* // First create and save a model.
|
* const model = tf.sequential();
|
* model.add(tf.layers.dense(
|
* {units: 1, inputShape: [10], activation: 'sigmoid'}));
|
* await model.save('localstorage://demo/management/model1');
|
*
|
* // Then list existing models.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
*
|
* // Delete the model.
|
* await tf.io.removeModel('localstorage://demo/management/model1');
|
*
|
* // List models again.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
* ```
|
*
|
* @returns A `Promise` of a dictionary mapping URLs of existing models to
|
* their model artifacts info. URLs include medium-specific schemes, e.g.,
|
* 'indexeddb://my/model/1'. Model artifacts info include type of the
|
* model's topology, byte sizes of the topology, weights, etc.
|
*
|
* @doc {
|
* heading: 'Models',
|
* subheading: 'Management',
|
* namespace: 'io',
|
* ignoreCI: true
|
* }
|
*/
|
declare function listModels(): Promise<{
|
[url: string]: ModelArtifactsInfo;
|
}>;
|
/**
|
* Remove a model specified by URL from a registered storage medium.
|
*
|
* ```js
|
* // First create and save a model.
|
* const model = tf.sequential();
|
* model.add(tf.layers.dense(
|
* {units: 1, inputShape: [10], activation: 'sigmoid'}));
|
* await model.save('localstorage://demo/management/model1');
|
*
|
* // Then list existing models.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
*
|
* // Delete the model.
|
* await tf.io.removeModel('localstorage://demo/management/model1');
|
*
|
* // List models again.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
* ```
|
*
|
* @param url A URL to a stored model, with a scheme prefix, e.g.,
|
* 'localstorage://my-model-1', 'indexeddb://my/model/2'.
|
* @returns ModelArtifactsInfo of the deleted model (if and only if deletion
|
* is successful).
|
* @throws Error if deletion fails, e.g., if no model exists at `path`.
|
*
|
* @doc {
|
* heading: 'Models',
|
* subheading: 'Management',
|
* namespace: 'io',
|
* ignoreCI: true
|
* }
|
*/
|
declare function removeModel(url: string): Promise<ModelArtifactsInfo>;
|
/**
|
* Copy a model from one URL to another.
|
*
|
* This function supports:
|
*
|
* 1. Copying within a storage medium, e.g.,
|
* `tf.io.copyModel('localstorage://model-1', 'localstorage://model-2')`
|
* 2. Copying between two storage mediums, e.g.,
|
* `tf.io.copyModel('localstorage://model-1', 'indexeddb://model-1')`
|
*
|
* ```js
|
* // First create and save a model.
|
* const model = tf.sequential();
|
* model.add(tf.layers.dense(
|
* {units: 1, inputShape: [10], activation: 'sigmoid'}));
|
* await model.save('localstorage://demo/management/model1');
|
*
|
* // Then list existing models.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
*
|
* // Copy the model, from Local Storage to IndexedDB.
|
* await tf.io.copyModel(
|
* 'localstorage://demo/management/model1',
|
* 'indexeddb://demo/management/model1');
|
*
|
* // List models again.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
*
|
* // Remove both models.
|
* await tf.io.removeModel('localstorage://demo/management/model1');
|
* await tf.io.removeModel('indexeddb://demo/management/model1');
|
* ```
|
*
|
* @param sourceURL Source URL of copying.
|
* @param destURL Destination URL of copying.
|
* @returns ModelArtifactsInfo of the copied model (if and only if copying
|
* is successful).
|
* @throws Error if copying fails, e.g., if no model exists at `sourceURL`, or
|
* if `oldPath` and `newPath` are identical.
|
*
|
* @doc {
|
* heading: 'Models',
|
* subheading: 'Management',
|
* namespace: 'io',
|
* ignoreCI: true
|
* }
|
*/
|
declare function copyModel(sourceURL: string, destURL: string): Promise<ModelArtifactsInfo>;
|
/**
|
* Move a model from one URL to another.
|
*
|
* This function supports:
|
*
|
* 1. Moving within a storage medium, e.g.,
|
* `tf.io.moveModel('localstorage://model-1', 'localstorage://model-2')`
|
* 2. Moving between two storage mediums, e.g.,
|
* `tf.io.moveModel('localstorage://model-1', 'indexeddb://model-1')`
|
*
|
* ```js
|
* // First create and save a model.
|
* const model = tf.sequential();
|
* model.add(tf.layers.dense(
|
* {units: 1, inputShape: [10], activation: 'sigmoid'}));
|
* await model.save('localstorage://demo/management/model1');
|
*
|
* // Then list existing models.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
*
|
* // Move the model, from Local Storage to IndexedDB.
|
* await tf.io.moveModel(
|
* 'localstorage://demo/management/model1',
|
* 'indexeddb://demo/management/model1');
|
*
|
* // List models again.
|
* console.log(JSON.stringify(await tf.io.listModels()));
|
*
|
* // Remove the moved model.
|
* await tf.io.removeModel('indexeddb://demo/management/model1');
|
* ```
|
*
|
* @param sourceURL Source URL of moving.
|
* @param destURL Destination URL of moving.
|
* @returns ModelArtifactsInfo of the copied model (if and only if copying
|
* is successful).
|
* @throws Error if moving fails, e.g., if no model exists at `sourceURL`, or
|
* if `oldPath` and `newPath` are identical.
|
*
|
* @doc {
|
* heading: 'Models',
|
* subheading: 'Management',
|
* namespace: 'io',
|
* ignoreCI: true
|
* }
|
*/
|
declare function moveModel(sourceURL: string, destURL: string): Promise<ModelArtifactsInfo>;
|
export { moveModel, copyModel, removeModel, listModels };
|