tflite-mnist-android

General

Category
Battlefield
Tag
Library Demos
License
N/A
Registered
Mar 12, 2018
Favorites
2
Link
https://github.com/nex3z/tflite-mnist-android
See also
Neuronizer Notes
Android Showcase
soas
Delightful SQLBrite
Noute

Additional

Language
Java
Version
v1.0.0 (Mar 12, 2018)
Created
Mar 9, 2018
Updated
Apr 19, 2019
Owner
Tianxing Li (nex3z)
Contributor
Tianxing Li (nex3z)
1
Activity
Badge
Generate
Download
Source code
APK file

Promotion

MNIST with TensorFlow Lite on Android

This project demonstrates how to use TensorFlow Lite on Android for handwritten digits classification from MNIST.

Prebuilt APK can be downloaded from here.

How to build from scratch

Environment

  • Python 3.6, TensorFlow 1.13.1
  • Linux or macOS for tflite model conversion.

Step 1. Train and convert the model to TensorFlow Lite FlatBuffer

Run all the code cells in model.ipynb.

  • If you are running Jupyter Notebook locally, a mnist.tflite file will be saved to the project directory.
  • If you are running the notebook in Google Colab, a mnist.tflite file will be downloaded.

Step 2. Build Android app

Copy the mnist.tflite generated in Step 1 to /android/app/src/main/assets, then build and run the app. A prebuilt APK can be downloaded from here.

The Classifer reads the mnist.tflite from assets directory and loads it into an Interpreter for inference. The Interpreter provides an interface between TensorFlow Lite model and Java code, which is included in the following library.

implementation 'org.tensorflow:tensorflow-lite:1.13.1'

If you are building your own app, remember to add the following code to build.gradle to prevent compression for model files.

aaptOptions {
    noCompress "tflite"
    noCompress "lite"
}

Credits