I spent too much time puzzling out how to go from a Keras model written in Python, to having something deployed as a website with GitHub Pages. I will walk through what ended up working so you save time where I couldn't 😄
# ... the model variable should hold your trained model
import tensorflowjs as tfjs
tfjs.converters.save_keras_model(model, 'saved-model')This will put a model.json file into the saved-model folder, along with shards that hold the weights. You will use this folder in a moment.
git clone https://github.com/tadeaspaule/tfjs-webpack-template.git
npm install
Check package.json if you want to see what's being installed. Basically, it's just @tensorflow/tfjs and then the required modules for webpack to run.
- Copy-paste your model into
build/assets/{directory-name}. You can see an example withbuild/assets/mnist-classifier - Change the code in
index.js. Again, you can see it using the path to the example MNIST classifier. - You're good to go! Add some code that uses your trained model, like
model.predictetc
npm start
You can check out deploy-example.bat and deploy-example.sh, and modify them so that they point to your repository. GitHub pages will run automatically, you just have to change the SSH url.