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

How to Redirect to CMS-page if Cookies are Disabled in Magento 2 | Rootways

Edit your site via FTP for non-coders

Argon x Launchzone — Lottery


That night, the group, which gathered to plan our wedding, gathered to plan his funeral

Generate incremental Firebase Firestore order/number vs ordered document ID

Skaffold: How to work with multiple configs in one file aka modules

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

Learning about Spring4Shell exploit

Building an android application to control Tello drone flight and perform real-time object…

OCR Preprocessing: Detect and Unrotate a Document Image using Java

How to Read Multiple Barcode and QR Code with Dynamsoft Java Barcode SDK