TensorFlow Lite and Android

This years TensorFlow Developer Summit was really interesting for my day job, but it did get me thinking about the possibilities for Machine Learning (ML) together with Android for my new business.

So I figured I would share with you my thoughts on running the demo app which they showed at the summit, and give some more insights into what’s going on.

I’m going to build using Android Studio, and I’m following the instructions that appear on the TensorFlow site

First things first, clone the TensorFlow git repo

git clone https://github.com/tensorflow/tensorflow.git

TensorFlow is an open source framework for defining, training, and running machine learning applications.  It’s heavily pushed and promoted by Google, but there is some crazy community involvement, and Google do a great service with things like the TensorFlow Developer Summit, with live streaming, Q&As over Twitter, etc.

Once the repo is cloned, fire up Android Studio you can import the project from tensorflow/lite/java/demo

Use the Import project (Gradle, Eclipse ADT, etc) option on the dialog.

It will then start to build automatically

And then you can launch it in the emulator.  If you didn’t bother setting up the camera to use your webcam (or if you don’t have a webcam), you will get the slightly lame Swedish house interior with nothing good on TV

For me, the demo was using the back camera as the default, and I couldn’t find a way to switch it on the device.  Making the virtual device use the webcam as the back camera fixed it, though the orientation is not how I’d like it

Holding up pictures of things seemed to work better than actual real life things.  It seems to think I am an Italian Greyhound.

Technically, it’s a ukulele, but I’ll settle for acoustic guitar.

iMac for the Android Studio win

Early days I know, but so far, so good.  The Android Studio install was painless.  Only issue was having to grant a security exception to allow HAXM to be installed, but other than that, the Studio install process was really slick and easy.

I was able to pretty quickly get an emulated device to appear, and I came here to declare success, but I realize it’s been sat on the boot screen for a while.  And with that, I complain and it’s up, though there’s the spinning wheel.  Still not happy.

I’ve killed it from the menu bar, and am trying again from the play button inside Android Studio.  Looks somewhat happier, and I even managed to get a screen grab.

But then all hell broke loose, and the emulator crashed again.  I shut down and restarted Android Studio, and Hello World! is back, but I shall definitely keep an eye on it.

So yeah, easy install.  Looks good.  Fast compiles.  Emulator seems snappy, but the crashes and hangs are a bit worrying.  Watch this space!

New machine

I cracked (which didn’t take much doing) and picked up a refurbished 21″ iMac for development.  After the usual 30 minute “omg I must update all the updates since I was shipped” freak out from the computer, I can now actually use it.

I’m not in love with the keyboard – seems really really small to me, and its actually pretty loud to type on, which is weird for a chiclet style keyboard.  Let’s see how it works when I’m coding – I may crack (again, see the pattern here) and spring for a nicer, bigger keyboard.

Mouse is nice though.

I’m assuming the Android Studio works the same in OS X as it did in Fedora.  It’ll be interesting to see if I have the same issues with firing up the emulated phone as I had on my old Fedora machine.

Android Virtual Device crashes on startup

I carefully followed the instruction in the Udacity course for setting up a Nexus 5 virtual device for launching my first app.  The device kept crashing as soon as I brought it up.

I did the usual googling, and eventually came across a post explaining how to start the emulator from the command line

For me, in Fedora, the emulator binary is in


You can see what AVDs are available.

[pjr@localhost emulator]$ ./emulator -list-avds

You can then start it disabling the hardware acceleration like this

./emulator -avd Nexus_5X_API_25 -gpu guest

Tada!  It’s a phone.

However, I couldn’t find a way to then execute with the guest GPU setting in Android Studio.  Though the option appears, and it looks selectable, its not!

Grr.  Turns out, this is a known problem with images downloaded from the playstore (shown with the little triangle)

So I’m trying the Nexus 6 with Nougat API level 24.  Finally, I get the option to select SW rendering

And now I have a lovely Nexus 6 running Android 7.0

Udacity course

I’m following the Udacity course called Developing Android Apps


The course description looks fine for me – I’ve done Java programming before, I’ve used git etc, so the pre-requisites look fine.

My first app is pretty simple, so I’m hoping to do just part of the course, and then develop my first app off on the side, while I keep following the course.

So far, the first few lessons have covered installing Android Studio, and setting up a virtual device.  My only issue is the world moves so fast, that the videos are already out of date, and you have to kind of guess for the new Android Studio, what makes sense.  In addition, in the video, they’ve already downloaded everything, so such as the part where you install a virtual device, it looks instantaneous, whereas in real life, it takes about half an hour.

So there’s quite a bit of pausing needed, but that’s fine.


Faster Android emulator performance on Fedora

I’ve ditched the ancient Dell, and am now running on an old work laptop which was reimaged with Fedora. I’m normally a Ubuntu man, but whatever.

I started to install the Android Studio, and I got a notification that said

We have detected that your system can run the Android emulator in an accelerated performance mode.
Linux-based systems support virtual machine acceleration through the KVM(Kernel-mode Virtual Machine) software package.

Search for install instructions for your particular Linux configuration (Android KVM Linux Installation) that KVM is enabled for faster Android emulator performance.

So here’s what I did to enable this

egrep ‘^flags.*(vmx|svm)’ /proc/cpuinfo;

This printed out a bunch of stuff which means that Android Studio was correct: my cpu does support kvm

sudo dnf group install –with-optional virtualization;

sudo systemctl start libvirtd;

sudo systemctl enable libvirtd;

lsmod | grep kvm

The lsmod showed that kvm_intel is in fact now running, and though I haven’t rebooted, the systemctl enable command should start the service each time.

About me

Every blog needs an about me, right?

Well, about me.  I’m getting older, but I don’t feel it.  I am a programmer by profession, but not an application developer.  I have done a ton of Java programming for my actual job, though it has been a while.

When Java first came out, I actually wrote a simple widget which resembles the first app I want to write so I know the logic is pretty simple. I also know the app has a certain appeal which I’ll explain elsewhere.

I am currently typing this on an ancient tiny Dell media PC, which has to be about ten years old, and is slow as all hell.  One of the things I want to figure out is what a good development environment will look like.  Can I use this crappy Dell, but then use the compute power of Amazon AWS for example.  Or do I need to buy a new machine (which is always fun!)

Getting started


Yesterday, I decided to build an android app.  Today, I decided to build an android app business, and to take you all along with me.

How will I make money?  How will I build the app?  What tools will I need?  What personality traits will help or hinder me?

Follow me as I learn, build, make mistakes, and see if I ever actually finish anything let alone make any money.

I’ll be totally transparent on everything I do, and always glad to hear from anyone with insights, advice and just general chit chat