GithubHelp home page GithubHelp logo

justinhj / mnistdigitsserver Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 5.79 MB

API server to host a keras model to predict handwritten digits based on the mnist data set

JavaScript 79.61% HTML 11.41% Dockerfile 2.32% CSS 6.66%

mnistdigitsserver's Introduction

MNist digit handwriting recognition server

Summary

This is small end to end ML project I did over xmas '23. I started by training a model on a publicly available data set of hand written digits which you can find here.

https://www.kaggle.com/datasets/hojjatk/mnist-dataset

Then I built a frontend and server so you can draw digits in real time and which runs predictions on the trained model and shows what digit it thinks you probably drew.

Running

The backend is a Fastify/Node server, which also serves the frontend. To run simply execute:

npm install
npm run start

There is also a dev mode that will update and restart when you change source files.

npm run dev

You can also run using Docker, check README.docker.md.

Technical details

The model was built in tensorflow/keras using a Jupyter notebook. The notebook trains on the mnist digit data set and saves the keras model. TODO link to the notebook.

Once you have the keras model it is exported to tensorflowjs format TODO link to script so that it can be served via a node server and that library.

As the user draws into the canvas the image is periodically submitted to the server which returns the predictions.

Production concerns

See https://www.tensorflow.org/js/guide/nodejs#production_considerations

Model Conversion

As noted above Keras models as exported from tensorflow are not ready to use by tensorflowjs. You can export it using tensoreflowjs's converter.

This repo contains both the exported model and the

tensorflowjs is very fussy about Python versions and at time of writing is broken. I finally got it working by installing Python 3.9 and manually applying the following change to the jaxlib python code. lmao.

https://github.com/tensorflow/tfjs/pull/8103/files

TODO notes on the Dockerfile used for the conversion.

Then you can run the script as follows.

tensorflowjs_converter --input_format keras ./model/digitsmodel.keras ./model/converted/

Things to do

  1. Fix bug where mouse leaves the drawing area
  2. Drawing area should be larger so you can see the pixels better (high)
  3. Test on mobile (low)
  4. Probabilities under digits instead of alone
  5. Pixel data can be collapsed (maybe cheat and bring in material.css)

mnistdigitsserver's People

Contributors

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