Code Monkey home page Code Monkey logo

number-guesser's Introduction

This repo holds the code to train a simple digit recognizing feed foward neural network with the MNIST database digits and also a website which allows the user to draw digits and visualize the neural network prediction of the drawings.

Usage

  • Draw digit on the "Digit" canvas
  • Click on node to highlight it's weights
  • Check table for camera controls in the 3D visualizer
  • Space to reset weights and camera

Installation

First, clone the repository:

git clone https://github.com/g-otn/number-guesser.git
cd number-guesser

Client

If you do not wish to train a new neural network, you can simply serve the client/ folder:

  1. npm i -g serve
  2. serve client or cd train && npm run-script serve

Training

If you wish to run the training script to generate a new model, follow these steps. Steps 1-3 are optional, but if you wish to skip them, please read Note 2 below:

  1. Navigate to the train/ folder: cd train
  2. BEFORE creating node_modules/ (i.e npm i) in the train/ folder, download these two files from the MNIST database:
  3. Extract the two files into the data/ folder:
data
├───train-images-idx3-ubyte
└───train-labels-idx1-ubyte

Note: Notice the - character in the file names. You may need to rename them (replacing the . for -) if you get an file not found error in the next step.

  1. Install the packages: npm i. A post-install npm script should do all the work with the files.

  2. Run npm start or node train.js

  3. After training ends the model file will already be in the right path to be loaded by the browser.

Note 2: If something goes wrong during steps 1-3 you can skip it, however you will need to edit the train.js file and lower the mnist set to a sum <= 10000. (i.e mnist.set(8000, 2000). Otherwise the training might log NaNs and save an invalid model.

Using your own model

If you already have an exported brain.js model, you can replace the client/model.json file so the client can use your model instead. Because of hard-coded code, and since it's using a poorly modified version of brain-browser.js, the client requires the model to have this structure for the visualization to work:

  • Type: feed forward (brain.NeuralNetwork)
  • Layers: 784 nodes input layer (28*28 image pixels), at least one hidden layer, 10 nodes output layer (digits 0-9)
  • Activation function: sigmoid

Built with

Acknowledgements

This repo was highly motivated by 3Blue1Brown's videos on Neural Networks.

Most of the training code was based on Ralph's Blog article on "Machine Learning with brain.js and Tensorflow.js".

Thanks to MSc Adriana Natividad Lopez Valverde for assigning me the project related to this repo.

License

MIT

This repo uses a modified version of a BrainJS/brain.js file, licensed under MIT.

number-guesser's People

Contributors

g-otn avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

dr-data

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.