Using Google Cloud AutoML to classify poisonous Australian spiders

Posted by by Matt Fraser

Warning: This post contains pictures of spiders (and Spiderman)!

Google’s new Cloud AutoML Vision is a new machine learning service from Google Cloud that aims to make state of the art machine learning techniques accessible to non-machine learning experts. In this post I will show you how I was able, in just a few hours, to create a custom image classifier that is able to distinguish between different types of poisonous Australian spiders. I didn’t have any data when I started and it only required a very basic understanding of machine learning related concepts. I could probably show my Mum how to do it!

Cloud AutoML is currently in a private alpha, you can request access here.

Getting Data

Everyone knows that to train a machine learning model, the first thing you need is data. I didn’t feel like taking a trip to the Australian bush to capture a bunch of original pictures of poisonous spiders. Luckily Google already provides another tool that let’s us search for images of things: Google Image Search!

I also didn’t feel like manually downloading hundreds of images so I used this handy tool to download images with a simple Python script. I ran it twice using the search terms “whitetail spider” and “redback spider” to collect 100 images of each type of spider.

And that’s it, I had finished collecting my data!

If you have a lot of unlabelled images, it is possible to import them into the Cloud AutoML Vision service and then request the Human Labelling Service to label them for you. You simply need to define your labels with a good description and Google’s team of human labellers will do the rest.

Importing the Dataset to Cloud AutoML

The Cloud AutoML service requires that your images are located within a Google Cloud storage bucket. It is possible to import the images into the tool using the UI but to save time I simply copied the images to the bucket from my machine using the gcloud command line tool.

Next I needed a CSV that contained the bucket url of each image along with its label. The Google image search download tool places its results into folders so I wrote a small script that enumerated the list of files into a CSV of the format below and then uploaded this CSV to the same bucket.

gs://my-automl-bucket/path/to/image,whitetail gs://my-automl-bucket/path/to/image,redback

Next I created a new dataset in the Cloud AutoML service and gave it the location of my classification CSV:

Training the Model

Once you have imported and labeled your images, training your model is as simple as choosing between the ‘Base’ and ‘Advanced’ options and clicking train.

I chose the free option and within about 20 minutes I was emailed to say that my model had been trained!

Evaluating the Model

Once you have a trained model, the Cloud AutoML service provides some nice tools to help you determine the efficacy of your model. At this point some knowledge of machine learning related concepts would probably be beneficial but it certainly does not require a PhD.

You can also upload some new images and see how the model performs yourself. I uploaded two below and as you can see it has performed well despite my very low number of example training images.

It got a little confused when I gave it a Huntsman spider, a type it hadn’t seen before. Even with a cutting edge tool at your fingertips, if you give it garbage in, it will give you garbage out! The model’s entire ‘world view’ is the labels we provided in our training set, so no matter what we pass it, it will make a prediction according to those labels.

It also got a little confused on this one!

Using the Model in Production

Your model is automatically deployed as soon as training completes. This means that as soon as you have achieved model accuracy you are happy with, you can start using it in production by querying the Cloud Vision API and specifying your model. Of course you would need to include a lot more images, along with images of non-poisonous spiders and no spiders at all if you wanted to start using this particular model, but in theory it wouldn’t take much effort to go from what I have created here to to a model that can be relied upon and used in the real world.

Conclusion

Google’s new Cloud AutoML Vision service marks another step forward towards democratising advanced machine learning techniques and making them available to the masses. Using this and tools like it, any developer could build an application that requires custom image classification. A very handy tool to add to the tool box.

Who knows, if the pricing is reasonable, you might just see Spiderapp in the app stores shortly after this is made available to the public!