• 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')
    // 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');

    Parameters

    • sourceURL: string

      Source URL of copying.

    • destURL: string

      Destination URL of copying.

    Returns Promise<ModelArtifactsInfo>

    ModelArtifactsInfo of the copied model (if and only if copying is successful).

    Error if copying fails, e.g., if no model exists at sourceURL, or if oldPath and newPath are identical.