In this tutorial, I’ll show you how to create a single label classification model in Google AutoML. We’ll be using a dataset of AI-generated faces from generated.photos. We’ll be training our algorithm to determine whether a face is male or female. After that, we’ll deploy our model to the cloud AND create the web browser version of the algorithm.
Getting The Labels
Setting Up Our Project
Time to jump into Google AutoML. In this section we’ll create a Dataset on Google AutoML and begin training our model.
After our project is created, we can use the sidebar or search bar at the top to navigate to Google AutoML. You may need to enable some APIs and set up billing for this to work, GCP will walk you through the process.
Next, we can hit Get Started with Image Classification.
This took me to the Datasets view. From the Datasets view, we can click Create New Dataset and fill out some details for our dataset to train on.
Formatting the Input Data
Now to actually get our data into the Google Cloud Platform. All the data needs to be in a GCP Storage Bucket. The browser interface won’t work because our dataset is too big.
Now we just need to execute gsutil cp -r path/to/faces gs://YOUR_BUCKET/faces to move our files up to the bucket. Make sure to change YOUR_BUCKET to the name of the bucket that was created for you (my bucket name in the screenshot below is woven-icon-263815-vcm).
Our original CSV looks like this:
For Google AutoML to use it, we need to convert it this:
Finish Creating the Dataset
Now that we have a CSV in the format Google AutoML needs, we’re ready to finish creating our dataset.
Upload the new CSV we created to your bucket and select it within the Import Dataset screen.
After the data is imported, you can view all our images and labels from the browser.
Creating the Model
In this section, we’ll create a Cloud Model that runs on GCP with an easy-to-use API as well as an Edge Model that can be exported to Tensorflow and run on mobile devices, browsers, locally or hosted on premise.
1. Training the Cloud Model
Navigate to the “TRAIN” tab and click “START TRAINING”. I used all the default options.
A couple hours later the model completed with an overview of the model’s performance and the budget used (all 16 hours I allocated 🙂
2. Training the “Edge” Model (the one that runs anywhere)
Creating the edge model can be done in basically the same way, just click “Edge” instead of “Cloud”. When you create an Edge Model you can optimize for speed or accuracy. I decided to optimize for accuracy because I wanted to compare the Edge Model to the Cloud Model.
In the “EVALUATE” tab, we can see how our model performed. The Cloud Model was able to get 94.5% accuracy. The Edge Model was able to get 95.5% accuracy. It surprised me that the Cloud Model performed slightly worse, especially because it had a greater training budget!
Overall, I’m happy with the performance of both of the models. The confusion matrix reveals that the Cloud Model made more mistakes when predicting males than females, whereas the Edge Model was more even.
Cloud Model Performance
In the screenshot below, you can see the confusion matrix of the cloud model, as well as some statistics reported by AutoML. It was slightly better at predicting females than males.
Edge Model Performance
In the screenshot below, you can see the confusion matrix of the edge model, as well as some statistics reported by AutoML. The edge model was slightly better at predicting males!
Deploying our Model
Now that we’ve gotten models we’re happy with, we should put them to use! Our Cloud Model can be deployed on GCP and our Edge model can be downloaded and run with Tensorflow. Let’s explore the deployment of both Cloud and Edge Models.
Navigate to the “TEST & USE” tab and hit the “DEPLOY MODEL” button. For testing, I decided to only deploy to one node. It took about an hour to deploy the model.
The Cloud Model exposes an easy-to-use API where you upload a simple JSON object and receive a set of predictions with probabilities back. For me, this is the perfect API for integrations, nice and simple.
We can also use the API directly in the browser and inspect the results. I uploaded some face photos from the training set, and things appearing to be working great! Overall I’d say it’s a pretty easy to use API if you can afford to run a cloud instances in the background.
For the Edge Deployment, we have a variety of ways to download the model. Each option is really powerful:
- TF Lite: Allows you to run your model on mobile devices
- TensorFlow.js: Allows you to run your model in a web browser
- Core ML: Allows you to run your model on Apple devices
- Container Allows you to run your model in a docker container (perfect for web servers)
Overall, Google AutoML was easy-to-use and super effective at this task. I’m looking forward to trying other cloud providers to see how they compare!