Creating an image classifier on Android using TensorFlow (part 2)

Rebuild the TensorFlow demo app from source

Using a virtual machine

  • It is easier to get started. This is because we can create a virtual machine image that already has most of the dependencies we need.
  • It protects your computer from any unwanted side effects. If you follow the TensorFlow Android demo app build instructions without thinking, you might accidentally mess up your development environment by installing or upgrading tools needed for the TensorFlow build.

Install Docker and create a TensorFlow-ready container

  • Install Docker (Mac, Windows). Wait for Docker to finish starting.
  • Check Docker is installed correctly:
$ docker run hello-world | grep Hello
  • Download my Docker image with all the dependencies:
$ docker pull danjarvis/tensorflow-android:1.0.0
  • Start a Docker container using this image:
$ docker run -it danjarvis/tensorflow-android:1.0.0
  • Check Python and all the TensorFlow dependencies are working by copying and pasting in the code in this Gist.
Hello from TensorFlow. Everything seems to be working!

Docker essentials

Building the TensorFlow project

Make a small update to the demo project

# find /tensorflow/ -name
# vi /tensorflow/tensorflow/examples/android/src/org/tensorflow/demo/

Build the demo project

# cd /tensorflow
# bazel build -c opt --local_resources 4096,4.0,1.0 -j 1 //tensorflow/examples/android:tensorflow_demo

Testing the APK

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS 68f8994d3b19 <image>:<version> "/bin/bash" 7 hours ago Up 7 hours
$ docker cp 68f8994d3b19:/tensorflow/bazel-bin/tensorflow/examples/android/tensorflow_demo.apk /tmp/
$ adb install -r /tmp/tensorflow_demo.apk




Machine Learning & Android —

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Git Bash Customization

Building a simple Poll System in Django [Part — II]

More deterministic tests + better signal-to-noise with branch ‘cross-targeting’


Serverless Image Object Detection at a Social Media Startup

Navigation in Swift using Protocol Extensions

21 Resources and Tutorials to Learn Kubernetes

Udacity — GwG — Baking App (Day 7)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dan Jarvis

Dan Jarvis

Machine Learning & Android —

More from Medium

Image Processing API: How to Resize an Image & Preserve the Aspect Ratio

Android QR Code Detection with TensorFlow Lite

Data Versioning in Computer Vision projects

KotlinDL 0.4