Code Monkey home page Code Monkey logo

tfjs-webpack-template's Introduction

Template project for deploying your TensorFlow models with Webpack

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 ๐Ÿ˜„

1. Save model in Python

# ... 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.

2. Clone this repository

git clone https://github.com/tadeaspaule/tfjs-webpack-template.git

3. Install dependencies

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.

4. Add your model

  1. Copy-paste your model into build/assets/{directory-name}. You can see an example with build/assets/mnist-classifier
  2. Change the code in index.js. Again, you can see it using the path to the example MNIST classifier.
  3. You're good to go! Add some code that uses your trained model, like model.predict etc

Running on localhost

npm start

Deploying to GitHub pages

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.

tfjs-webpack-template's People

Contributors

dependabot[bot] avatar tadeaspaule avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.