Code Monkey home page Code Monkey logo

mnist-android-tensorflow's Introduction

MNIST on Android with TensorFlow

Check the video demo here

Image Beautiful edition, I know.

Handwritten digits classification from MNIST on Android with TensorFlow.

If you want to make your own version of this app or want to know how to save your model and export it for Android or other devices check the very simple tutorial bellow.

The UI and expert-graph.pb model were taken from: https://github.com/miyosuda/TensorFlowAndroidMNIST, so thank you miyousuda.
The TensorFlow jar and so armeabi-v7a were taken from: https://github.com/MindorksOpenSource/AndroidTensorFlowMNISTExample, so thank you MindorksOpenSource.
The Tensorflow so of x86 was taken from: https://github.com/cesardelgadof/TensorFlowAndroidMNIST, so thank you cesardelgadof.

If you have no ideia what I just said above, have a look on the instructions bellow.

How to run this?

Just open this project with Android Studio and is ready to run, this will work with 86x and armeabi-v7a architectures.

How to export my model?

A full example can be seen here

  1. Train your model

  2. Keep an in memory copy of eveything your model learned (like biases and weights) Example: _w = sess.eval(w), where w was learned from training.

  3. Rewrite your model changing the variables for constants with value = in memory copy of learned variables. Example: w_save = tf.constant(_w)

    Also make sure to put names in the input and output of the model, this will be needed for the model later. Example:
    x = tf.placeholder(tf.float32, [None, 1000], name='input')
    y = tf.nn.softmax(tf.matmul(x, w_save) + b_save), name='output')

  4. Export your model with:
    tf.train.write_graph(<graph>, <path for the exported model>, <name of the model>.pb, as_text=False)

How to run my model with Android?

You need two things:

  1. The TensorFlow jar Move it to the libs folder, right click and add as library.
  2. The TensorFlow so file for the desired architecture:
    x86
    armeabi-v7a
    Move it to app/src/main/jniLibs/x86/libtensorflow_inference.so or app/src/jniLibs/armeabi-v7a/libtensorflow_inference.so

If you want to generate these files yourself, here is a nice tutorial of how to do it.

Interacting with TensorFlow

To interact with TensorFlow you will need an instance of TensorFlowInferenceInterface, you can see more details about it here

Thank you, have fun!

mnist-android-tensorflow's People

Contributors

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