Jonas
Jonas

Reputation: 7885

Tensorflow.js create model from downloaded file

I have a trained model, saved it with const saveResult = await model.save('localstorage://my-model-1');.

Now I want to reload it and use it again. So I want to do something like this:

async function loadModel() {
    let myModel = tf.sequential();
    myModel = await model.save('downloads://my-model-1')
    console.log(myModel);

    let outputs = myModel.predict([
        tf.tensor2d([[0, 0, 1]])
    ]);
    outputs.print();
}

But It seems like model.save returns a modelArtifactsInfo. So how could I create a model from this Object?

I followed this tutorial but they don't really explain that.

is that even possible?

Upvotes: 1

Views: 312

Answers (1)

Sebastian Speitel
Sebastian Speitel

Reputation: 7346

In the tutorial it says it all:

You just have to call tf.loadModel with your savehandle which returns a promise which resolves to the loaded model or throws an error. In your case the handle would be 'localstorage://my-model-1'.

const model = await tf.loadModel('localstorage://my-model-1');

Upvotes: 1

Related Questions