Google AutoML Vision for Image Classification

Original article was published on Artificial Intelligence on Medium

Google’s AutoML lets you train custom machine learning models without having to code

Training high-performance deep networks is often a big task especially for those who have less experience in deep learning or AI. Also, we might require GPU in addition to RAM and CPU. I experienced a lot of issues while trying to classify with CNN.

How AutoML works (Made using Canva)

What if I said Google AutoML Vision will solve our problems? Yes, AutoML Vision enables us to train custom machine learning models to classify our images according to our own defined labels. It will train the model from labeled images and evaluate the performance. It doesn’t require the user to have any knowledge of deep learning or AI, all you need is labeled data! It will Train, Deploy, and Server the application for us.

In this article, I am going to show you how to use Google AutoML for facial expression recognition.

This is a good time to start. (Designed using Canva)

Are you excited? Let’s dive deep before it’s too late!

Preparing the Labeled DataSet

Facial Expression Recognition (Designed using Canva)

The data in facial expressions come from a variety of sources which includes

I downloaded a CSV file, a dataset that consists of pixels of both the training and testing images provided by Kaggle.

Data frame with Pixel values (Photo by Author)

Now we have the data frame with pixels of an image and its corresponding label (0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral). We need to get the images from those pixel values and organize each label in a separate folder.

Pixels to Image Conversion — Data Organization

After the images are organized you can count the number of images present in each label. Make sure the dataset is balanced with each label having a similar number of images (at least the count should not vary drastically) for better results.

Balanced data (Photo by Author)

After the images are organized perfectly, your dataset folder would look something like this,

Labeled Dataset (Photo by Author)

Before you can use the Cloud Vision API, you must enable it for your project:

Google offers you 300$ credits for new customers in order to get started on Google Cloud Platform for free. If you are not using free tier, Google charges you for every resource you create.

  1. Sign in to your Google Account.
  2. In the Cloud Console, on the project selector page, select or create a Cloud project.
  3. Make sure that billing is enabled for your Google Cloud project.
  4. Enable the Cloud Vision API.
  5. Set up authentication.

For additional information click here.

Create New DataSet

Vision (Photo by Author)

After the initial setup, you can see the Vision Dashboard as shown above. Now click on Get Started.

Create New DataSet (Photo by Author)

You will be redirected to a console to create a new dataset. Give it a name, select your model objective, and click on CREATE DATASET.

Import DataSet

Import DataSet (Photo by Author)

Now upload the dataset zip file by clicking on SELECT FILES. And browse the destination on cloud storage i.e, the path for a bucket to store the dataset. Click on CONTINUE. We can also import a CSV file with links to images.
It will take some time to import the dataset.

Imported Images (Photo by Author)

Once the dataset is imported, you can check the number of images in each label. We can add new labels here, delete any images. You can see the total number of images is 38,535. But out initial dataset contains 41,944 samples, it is because some images will be discarded by AutoML by default (with Error: The label is already a ground truth).

Click on LABEL STATS, to check the number of images used for training, validation, and testing.

DataSet Splitting (Photo by Author)

Train the Model

Now we have the labeled dataset imported to google cloud. We can train the model by selecting START TRAINING.

Train the model (Photo by Author)

Now a console will appear to train the model,

Define Model (Photo by Author)

Give the model a name and select Edge to download the model file for later use. Also, you can select Cloud-hosted if you want to host the model on Google cloud. Click on CONTINUE.

Optimize model (Photo by Author)

After Defining the model, we need to optimize it by trading off between the package size(model file), Response time, accuracy. Choose an option required for your application and click on CONTINUE.

Set a node hour budget (Photo by Author)

In the Final Step, we need to set the budget. AutoML will recommend the number of nodes necessary to train the model. However, you can decrease or increase the node hours. (NOTE: more the node hours cost will be high). Click on START TRAINING. Training may take several hours and you will get an email once training is finished.

Training the model is finished (Photo by Author)

Click on the link to start using your model.

Evaluate the Model

Model Evaluation (Photo by Author)

Once the training is finished, we can check the details of the model i.e, the number of samples (images) used for training, time took for training, Precision, Recall, etc. Click on SEE FULL EVALUATION.

Avergare Precision is 76%