GithubHelp home page GithubHelp logo

merklefruit / digit_recognizer Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 2.25 MB

A Python implementation of the popular MNIST dataset application of Digit Recognition with CNNs

License: MIT License

Python 53.43% JavaScript 6.41% HTML 38.31% Mako 1.85%
mnist-dataset digit-recognition python

digit_recognizer's Introduction

If you want to know more, I've written an article on my blog about this project!

Digit Recognizer

A Python implementation of the popular MNIST dataset application of Digit Recognition with Convolutional Neural Networks

This project was made to demonstrate a Python implementation of web inference capability. The network was trained on the MNIST database in Jupyter Notebook with the Keras library with Tensorflow backend. The recognition error on the test data set is 0.75% after 12 epochs, without hyperparameter tuning. The convolutional neural network I used is an 8-layer Sequential model.

Installation

# clone repo
git clone https://github.com/nicolas-racchi/digit_recognizer && cd digit_recognizer/flask_3

# If you're using MacOS/Linux:
export FLASK_APP=recognition.py

# If you're using Windors:
set FLASK_APP=recognition.py

# (Optional): create a virtual environment
virtualenv venv

# install and run
pip install -r requirements.txt
flask run

How it works:

The neural network was trained on the MNIST dataset in a Jupyter Notebook in Python, using ADAM, an algorithm for first-order gradient-based optimization of stochastic objective functions, based on adaptive estimates of lower-order moments. The loss function choosen was categorical crossentropy, since there are 10 classes. The network itself is an 8 layer sequential model, which has 784 input units (28x28 resolution grayscale images, normalized to values ranging from [-1: 1]). The network structure is as follows:

  • 2 Convolutional layers with rectified linear unit activation
  • A Pooling layer to choose the best features of the digits
  • A Dropout layer to improve convergence
  • A Flatten layer since there are too many dimensions and we need only 10 classes
  • A Dense layer, fully connected, to get all relevant data
  • A second Dropout layer
  • A Dense layer with softmax activation to squash the matrix into output probabilities

Using this training method I was able to obtain 99.25% test accuracy after only 12 epochs, without hyperparameter tuning, so there is still room for improvement. The training process took 16 seconds per epoch on a GRID 520 GPU.

Preprocessing

When you draw an image in the canvas, you are writing into a 280x280px area. The preprocessing is needed so that the output of the canvas is as similar as possible to the training data, in order to not loose accuracy. First of all, the image is converted in a base64 string, then its colors are inverted so that the majority of the canvas is black (this makes it easier for the classifier); finally, it is resized to 28x28px, the same as the training data.

Notes on Deploying

Originally I had deployed this project on Google Cloud and mapped it to my personal domain, but after several months I have decided that it's not worth keeping it online as far as costs are concerned, for now.

digit_recognizer's People

Contributors

merklefruit avatar

Stargazers

 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.