How can I save my session or my GAN model into a js file

Viewed 225

I want to deploy my GANs model on a web-based UI for this I need to convert my model's checkpoints into js files to be called by web code. There are functions for saved_model and Keras to convert into pb files but none for js

my main concern is that I am confused about how to dump a session or variable weights in js files

1 Answers

You can save a keras model from python. There is a full tutorial here but basically it amounts to calling this after training:

tfjs.converters.save_keras_model(model, tfjs_target_dir)

then hosting the result somewhere publicly accessible (or on the same server as your web UI) then you can load your model into tensorflow.js as follows:

import * as tf from '@tensorflow/tfjs';

const model = await tf.loadLayersModel('https://foo.bar/tfjs_artifacts/model.json');
Related