GithubHelp home page GithubHelp logo

abhiek187 / minibrainage Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 9.8 MB

An Android app where users draw a number and machine learning does the rest

Home Page: https://play.google.com/store/apps/details?id=com.abhi.minibrainage

Kotlin 51.48% Python 48.52%
android kotlin on-device-ml mnist-classification tensorflow-lite play-games

minibrainage's Introduction

Brain Smarts

Brain Smarts demo

Get it on Google Play

About

Inspired by Brain Age, this Android game tests players' math knowledge by hand drawing numbers and quickly solving math problems. With a Play Games account, players can upload their high scores to the leaderboards.

A key feature of this app is that it uses on-device machine learning to interpret handwritten digits. This is done by feeding the MNIST dataset into a neural network created in TensorFlow Lite.

The Neural Network

The neural network was created using Keras and its design is based on the LeNet convolutional architecture for handwritten character recognition. The following describes each layer:

  • Input: 1x28x28 (start with a 28x28 px grayscale drawing of the number)
  • Conv1: 1x28x28 input, 32 3x3 filters → 32x26x26 output (ReLU activation)
  • Conv2: 32x26x26 input, 64 3x3 filters → 64x24x24 output (ReLU activation)
  • MaxPool: 64x24x24 input, 2x2 filter, stride 2 → 64x12x12 output
  • Dropout: 25%
  • Flatten: 64x12x12 input → 9216 layers
  • Dense: 9216 layers → 10 layers (softmax activation, classify the number from 0-9)

Because players can draw anywhere on the canvas, data augmentation was used to improve the accuracy of the model—namely rotation, width & height shift, shear, and zoom. The model was trained for 5 epochs and was compressed to a TFLite file using quantization.

How to Run

To run the app, clone this repo and run it in Android Studio.

There are 3 Python files that can be executed after installing the TensorFlow module:

  • train_ml_model.py creates the initial MNIST neural network with 98% accuracy
  • improve_accuracy.py utilizes data augmentation to improve the accuracy on mobile devices
  • write_metadata.py generates info about the tflite file that can be viewed on code generators, such as Android Studio's ML Binding

write_metadata.py is executed with the following syntax:

python3 ./write_metadata.py \
    --model_file=./<path-to>/mnist.tflite \
    --label_file=./labels.txt \
    --export_directory=<output-directory>

Google Play and the Google Play logo are trademarks of Google LLC.

minibrainage's People

Contributors

abhiek187 avatar

Watchers

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