I made a machine learning chicken rice classifier in ~4 hours to tell me what type of chicken rice I bought for lunch Preston Lim Follow Sep 25, 2018 · 5 min read

This entire frivolous episode started when my colleague got chicken rice for lunch. The lunchtime conversation then evolved into how there was this hilarious Instagram account called kuey.png whose owner photographed one plate of chicken rice every single day for 279 days as of yesterday.

An aside here. For non-Singaporeans: “kuey png” is the Hokkien term for chicken rice, one of the national dishes of Singapore. And this Instagram account owner uploads .png format photos of the chicken rice — hence the name, kuey.png. This really tickled me. Anyway, back to the lunchtime convo.

As conversations in the Data Science Division of GovTech do, our convo soon spiralled into “wow this would be an amazing machine learning dataset for chicken rice” and “wait could we train a classifier to differentiate between steamed and roasted chicken rice?”. Next thing I know, it is 1am on a Monday night and I’m waiting for my chicken rice machine learning model to finish training.

Here’s the solution — a tool that allows you to take or upload a photo of chicken rice, and the machine learning classifier tells you if it is a plate of steamed or roasted chicken rice. (I’m still debating whether I should turn it into a web app that anyone can use. Let me know what you think.)

Because… I don’t know why.

At the heart of the ridiculous exercise is this point: you can now create and deploy a very simple ML project within hours, thanks to the magic that is Google AutoML Vision.

The magic of AutoML Vision

Traditionally, it would haven taken me days at the very least to create and deploy an ML classifier on the internet. I would have had to (1) curate and label the dataset, (2) train an ML classifier, (3) deploy the ML model, (4) create a server with a REST API to call the ML classifier.

With AutoML Vision, all I had to do was step (1). And that’s why I was able to finish the entire project in ~4 hours. Though to be perfectly honest, I could have completed it sooner, but I was multi-tasking by labelling the chicken rice images while watching the extremely confusing pilot of Maniac ft. Emma Stone and Jonah Hill. What is even going on in this show? What year is it supposed to be in the world of Maniac? Anyway, I digress. Here’s a quick rundown of what I did.

Step 1: Obtain images from kuey.png on Instagram

Because Instagram makes it really hard to obtain images from its platform, I painstakingly took screenshots of the 279 individual images on my Macbook.

I got really hungry doing this.

Step 2: Upload images onto AutoML

I dragged and dropped all 279 images into AutoML and watched Netflix while they were uploading.

Step 3: Label images

I then labelled each image as roasted or steamed. This was really tough because I was debating between classifying “soy sauce chicken” as either roasted or steamed, or making it its own class. I eventually went with steamed since it technically is a steamed chicken, but chicken rice purists will fervently disagree with me.

This was when I realized that the kuey.png person prefers roasted chicken rice over steamed chicken rice. I don’t blame them.

Step 4: Train ML model

I just clicked on “Train”. More Netflix happened. Simply because AutoML does several things automatically:

it extracts 10% of the dataset to keep for model testing/validation. it scales your images for you. it generates the precision/recall graphs and confusion matrix for you.

The best Netflix and Chill companion

Step 5: Validate ML model

30 mins later — the results were out.

The precision and recall were decent enough. And according to the confusion matrix, the ML model was able to accurately classify all the roasted chicken rice photos (yay!).

However, the model got a little confused (hence the name confusion matrix) by some steamed chicken rice dishes. More specifically, the model thought that an image of a steamed chicken was a roasted chicken 16.7% of the time when it was actually a steamed chicken.

I mean, I don’t blame it. Have you seen how some people slather their chicken rice with so much soy sauce and chili that you can’t quite make out what they’re eating? Because I’m one of those people.

Some of the photos were really quite challenging to classify (shown below).