Follow along: building an app that recognises beers šŸŗ

ā—4 MIN READ

Follow along: building an app that recognises beers šŸŗ

Follow me along the journey of building a mobile app that recognises different bottles of beers. This blogpost will be updated every time there is a breakthrough.

Introduction

So a year ago I created ā€œbeerificial intelligenceā€. At the time I was really intrigued with the concepts of neural networks and wanted to see what I could make with it. The TensorFlow for Poets Tutorial explained how you could train a classifier to classify images of flowers. I went through the tutorial and after a few days I created the classifier, but with beers instead of flowers. I put it on my website (it’s not available anymore) and people could upload pictures of bottles of beer, and the algorithm would guess which beer it was (it was trained on 8 types of beers). Pretty cool stuff!

This is how it worked back then:

The idea for this side-project is to create a mobile app that can classify beers as well. However, there are a few requirements:

  • The app has to be native, so no cordova, react-native, etc. This will make the development much harder and longer as I’ve got almost no experience with Swift/Xcode and Kotlin/Android Studio. From a ā€œbusiness perspectiveā€ not the best choice, but it’s not business, so… šŸ˜€
  • The machine learning has to be performed on the device. No APIs, no whatever. The machine learning model will be placed on the device and every classification will be made locally on the device itself. This way I don’t need a server, the app would work offline and there’s no problems with privacy and image uploading to the server and stuff.
  • The neural network has to know the difference between a Carolus Classic and Carolus Tripel šŸŗ

This project has three big components: The neural network, the iOS app and the Android app.

The neural network

What needs to be done:

  1. gather training images of the beers
  2. pick a neural network architecture
  3. train the neural network
  4. make sure it performs well (if it doesn’t, go back to point 1)

I’ve gathered over 70000 images of 55 brands of beer, which is around 1300 images per brand. I’ve got no idea if this is nearly enough, but in the worst case I’ll just start with only 10 brands, and obtain some more images for each of the 10 brands.

Screen-Shot-2018-03-03-at-17.17.50-1
Screen-Shot-2018-03-03-at-17.00.14

The most popular neural network architecture to use is Inception v4, so I’ll start with this one and see if the performance on mobile is okay. It uses quite a lot of features so it might be to slow on the Android phone of the average Joe.

The model (with Inception v4) is trained on a DigitalOcean machine learning droplet. It’s CPU only, which is okay for Inception v4, as we’ll only retrain the last layer. If the performance is not okay, I’ll probably go with AWS and use a GPU EC2 instance.

The iOS app

What needs to be done:

  1. create an app in XCode
  2. when the app opens, it should show the camera as the first screen
  3. user can take a picture
  4. when a picture is taken, we use the classifier to see which beer it is
  5. display the brand of the beer

Luckily, I have a Macbook Pro, so I can develop for iOS! Xcode is installed, and the app is made.

To make it somewhat custom, I decided to go with SwiftyCam to create a custom Camera.

The Android app

I’ll start this after the iOS app is ready.

Update April 28, 2018

After brainstorming for a while about it, and the release of Tensorflow.js I decided to take a different route.

I bought a desktop with a 1080GTX TI GPU, so I can play around more with machine learning in my spare time. The only problem that’s left now is finding good data.

As I’ve been thinking a lot about beerificial, I don’t think there’s enough value in just an app that allows you to classify around 15 types of beers. It’s maybe fun for a minute, but that’s it.

In order to make it more sticky, I decided to make it a game, and it’ll work like this: When you open the web app (more about this later), you’ll see 9 blurry beer bottles. Which beers are they? That’s for you to find out by using the camera to scan beer bottles in your vicinity. To make it less random, there are hints you can get.

So, let’s talk about this web app thing. Google recently launched Tensorflow.js, which allows developers to train models and use them with JavaScript. And where’s JavaScript primarily used? In the browser! Do you see where it’s going?

So instead of spending a lot of time coding the two apps, I can just make it as a web app in JavaScript. This means people won’t have to download and install it, which makes the whole process smoother.

More polaroids I want to share

CLICK OR DRAG THE TOP ONE ASIDE

You've reached the end of the shoebox. More polaroids and other posts live on my Instagram.

@GMJELLE →
Polaroid of a calm lake at dusk reflecting pink clouds and dark hills, at a wild campsite near Adana, Turkey
Polaroid of Josip Broz Tito's marble tomb seen through plant leaves in Belgrade, Serbia
Polaroid of a motorcycle parked at a Soviet-era bus stop decorated with a flower mosaic in Moldova
Polaroid of a large stone statue of a bearded man in a long coat on a hillside near Buzludzha, Bulgaria
Polaroid of the saucer-shaped Buzludzha Monument on a distant hilltop above the trees in Bulgaria
Polaroid of a man standing in front of the Buzludzha Monument and its tower in Bulgaria
Polaroid of a valley of pale, cone-shaped rock formations in Cappadocia, Turkey
Polaroid of hot air balloons silhouetted against the dawn sky in Cappadocia, Turkey
Polaroid of the brutalist Cosmos Hotel tower in Chisinau, Moldova
Polaroid of the Tomb of Cyrus the Great on its stepped stone base at Pasargadae, Iran
Polaroid of a close view of the Tomb of Cyrus the Great at Pasargadae, Iran
Polaroid of a converted red fire truck camper and a motorcycle at a campsite on the west coast of Turkey
Polaroid of a mosque minaret and domes silhouetted against a cloudy sky in Edirne, Turkey
Polaroid of the Mimar Sinan statue in front of the Selimiye Mosque in Edirne, Turkey
Polaroid of the courtyard of a historic house with a fountain and colored-glass windows in Isfahan, Iran
Polaroid of a man standing next to an Isfahan city emblem sign on a sidewalk in Isfahan, Iran
Polaroid of the tiled dome and entrance portal of the Sheikh Lotfollah Mosque in Isfahan, Iran
Polaroid of the tiled entrance portal and twin minarets of the Shah Mosque in Isfahan, Iran
Polaroid of a columned palace silhouetted at sunset behind a fountain pool on Naqsh-e Jahan Square, Isfahan, Iran
Polaroid of a dark interior lit through colorful stained-glass windows in a historic house in Isfahan, Iran
Polaroid of rocky ridges and rock formations under a cloudy sky near Goreme, Cappadocia, Turkey
Polaroid of a loaded motorcycle parked by a desert road with mountains behind it in Iran
Polaroid of a loaded motorcycle with a helmet on the mirror, parked on a coastal road near Izmir, Turkey
Polaroid of a Soviet-era mosaic of workers and a motorcyclist on a building wall in Lutsk, Ukraine
Polaroid of a Soviet-era mosaic of a crowned woman holding scales, framed by tree leaves in Lviv, Ukraine
Polaroid of the Lviv Opera House facade with a fountain in front in Lviv, Ukraine
Polaroid of a Soviet WWII memorial column with a stork's nest on top in northern Moldova
Polaroid of a large Soviet-era mural of figures on a wall beside a tree in Moldova
Polaroid of royal tombs carved into the cliff face at Naqsh-e Rustam near Persepolis, Iran
Polaroid of a stone relief of a Persian soldier holding a spear at Persepolis, Iran
Polaroid of the Gate of All Nations with its winged bull statues and columns at Persepolis, Iran
Polaroid of four men sharing dinner at a table in a traditional hostel in Shiraz, Iran
Polaroid of the tiled courtyard and reflecting pool of the Nasir al-Mulk (Pink) Mosque in Shiraz, Iran
Polaroid of two men smiling at a restaurant table in Tabriz, Iran
Polaroid of the mirrored hall of Golestan Palace lit by large chandeliers in Tehran, Iran
Polaroid of the bronze statue of Leonidas raising a spear at the Thermopylae monument, Greece
Polaroid of a man looking up at the wooden Trojan Horse from the Troy film in Canakkale, Turkey
Polaroid of a backgammon board on a table overlooking the sea at a campsite in Turkey
Polaroid of a Soviet-era mosaic of a woman in traditional dress under a Ukrainian coat of arms in Ukraine
Polaroid of a motorcycle parked at a bus stop with a mosaic of three knights in Ukraine
Polaroid of a man standing on a boardwalk in front of the stairway of the Ziggurat of Ur, Iraq
Polaroid looking up the brick stairway of the Ziggurat of Ur, Iraq
Polaroid of eroded mud-brick ruins with a small sign in front at Uruk, Iraq
Polaroid of a man and two boys crouching by a freshly slaughtered sheep on grass on the road to Van, Turkey
Polaroid looking up at the curved glass Zlota 44 skyscraper in Warsaw, Poland
Polaroid of the Palace of Culture and Science lit at dusk in Warsaw, Poland
Polaroid of the Zoroastrian Fire Temple with a round reflecting pool in Yazd, Iran