arrow_back

Classify Images of Clouds in the Cloud with AutoML Vision

Join Sign in

Classify Images of Clouds in the Cloud with AutoML Vision

2 hours 5 Credits

GSP223

Google Cloud Skills Boost logo

Overview

AutoML Vision helps developers with limited ML expertise train high quality image recognition models. Once you upload images to the AutoML UI, you can train a model that will be immediately available on Google Cloud for generating predictions via an easy to use REST API.

In this lab, you will upload images to Cloud Storage and use them to train a custom model to recognize different types of clouds (cumulus, cumulonimbus, etc.).

What you'll learn

  • Uploading a labeled dataset to Cloud Storage and connecting it to AutoML Vision with a CSV label file.

  • Training a model with AutoML Vision and evaluating its accuracy.

  • Generating predictions on your trained model.

Setup and requirements

Qwiklabs setup

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Chrome OS device, open an Incognito window to run this lab.

How to start your lab and sign in to the Google Cloud Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.

    Open Google Console

  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Sign in

    Tip: Open the tabs in separate windows, side-by-side.

  3. In the Sign in page, paste the username that you copied from the left panel. Then copy and paste the password.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Training credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).

  4. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

Set up AutoML Vision

AutoML Vision provides an interface for all the steps in training an image classification model and generating predictions on it. Start by enabling the Cloud AutoML API.

From the Navigation menu, select APIs & Services > Library.

In the search bar type in "Cloud AutoML". Click on the Cloud AutoML API result and then click Enable.

This will take a minute to set up.

Now open this AutoML UI link in a new browser.

Click Check my progress to verify the objective.

Enable the AutoML API

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell button.

Cloud Shell icon

Click Continue.

cloudshell_continue.png

It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:

Cloud Shell Terminal

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

You can list the active account name with this command:

gcloud auth list

(Output)

ACTIVE: * ACCOUNT: student-01-xxxxxxxxxxxx@qwiklabs.net To set the active account, run: $ gcloud config set account `ACCOUNT`

You can list the project ID with this command:

gcloud config list project

(Output)

[core] project = <project_ID>

(Example output)

[core] project = qwiklabs-gcp-44776a13dea667a6

In Cloud Shell, use the following commands to create environment variables for your Project ID and Username, replacing <USERNAME> with the User Name you logged into the lab with:

export PROJECT_ID=$DEVSHELL_PROJECT_ID export QWIKLABS_USERNAME=<USERNAME>

Run the following command to give AutoML permissions:

gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="user:$QWIKLABS_USERNAME" \ --role="roles/automl.admin"

Now create a storage bucket by running the following:

gsutil mb -p $PROJECT_ID \ -c standard \ -l us-central1 \ gs://$PROJECT_ID-vcm/

In the Google Cloud console, open the Navigation menu and click on Cloud Storage to see it.

cloud_storage.png

Click Check my progress to verify the objective.

Create a Cloud Storage Bucket

Upload training images to Cloud Storage

In order to train a model to classify images of clouds, you need to provide labeled training data so the model can develop an understanding of the image features associated with different types of clouds. In this example your model will learn to classify three different types of clouds: cirrus, cumulus, and cumulonimbus. To use AutoML Vision you need to put your training images in Cloud Storage.

Before adding the cloud images, create an environment variable with the name of your bucket.

Run the following command in Cloud Shell:

export BUCKET=$PROJECT_ID-vcm

The training images are publicly available in a Cloud Storage bucket.

Use the gsutil command line utility for Cloud Storage to copy the training images into your bucket:

gsutil -m cp -r gs://spls/gsp223/images/* gs://${BUCKET}

When the images finish copying, click the Refresh button at the top of the Storage browser, then click on your bucket name. You should see 3 folders of photos for each of the 3 different cloud types to be classified:

autoML_bucket_folders.png

If you click on the individual image files in each folder you can see the photos you'll be using to train your model for each type of cloud.

Create a dataset

Now that your training data is in Cloud Storage, you need a way for AutoML Vision to access it. You'll create a CSV file where each row contains a URL to a training image and the associated label for that image. This CSV file has been created for you; you just need to update it with your bucket name.

Run the following command to copy the file to your Cloud Shell instance:

gsutil cp gs://spls/gsp223/data.csv .

Then update the CSV with the files in your project:

sed -i -e "s/placeholder/${BUCKET}/g" ./data.csv

Now upload this file to your Cloud Storage bucket:

gsutil cp ./data.csv gs://${BUCKET}

Once that command completes, click the Refresh button at the top of the Storage browser. Confirm that you see the data.csv file in your bucket.

Navigate back to the AutoML Vision tab. Your page should now resemble the following:

MLVision_nobeta.png

At the top of the console, click + NEW DATASET.

Type "clouds" for the Dataset name.

Select "Single-Label Classification".

mlvision-new-dataset.png

Click CREATE DATASET.

Choose Select a CSV file on Cloud Storage and add the file name to the URL for the file you just uploaded - gs://your-bucket-name/data.csv

An easy way to get this link is to go back to the Cloud Console, click on the data.csv file. Click on the copy icon in the URI field.

mlvision-select-file.png

Click CONTINUE.

It will take 2 - 5 minutes for your images to import. Once the import has completed, you'll be brought to a page with all the images in your dataset.

Click Check my progress to verify the objective.

Create a Dataset

Inspect images

After the import completes, click on the Images tab to see the images you uploaded.

autoML_images.png

Try filtering by different labels in the left menu (i.e. click cumulus) to review the training images:

If any images are labeled incorrectly you can click on the image to switch the label:

mlvision-image-detail.png

To see a summary of how many images you have for each label, click on LABEL STATS at the top of the page. You should see the following show up on the right side of your browser.

label_stats.png

Train your model

You're ready to start training your model! AutoML Vision handles this for you automatically, without requiring you to write any of the model code.

To train your clouds model, go to the Train tab and click Start Training.

Enter a name for your model, or use the default auto-generated name.

Leave Cloud-hosted selected, then click Continue.

Set the node hours to 8.

VisionAutoML_8nodehrs.png

Click Start Training.

Since this is a small dataset, it will only take around 25-30 minutes to complete.

While you're waiting, you can watch this YouTube video on preparing an image data in AutoML - the images should look familiar!

Evaluate your model

In the Evaluate tab, you'll see information about Precision and Recall of the model.

AutoML_precision_graph.png

You can also play around with Confidence threshold.

Finally, scroll down to take a look at the Confusion matrix.

AutoML_confusion.png

All of this provides some common machine learning metrics to evaluate your model accuracy and see where you can improve your training data. Since the focus for this lab was not on accuracy, move on to the next section about predictions section. Feel free to browse the accuracy metrics on your own.

Deploy your model

Now it's time for the most important part: generating predictions on your trained model using data it hasn't seen before.

Navigate to the Test & Use tab in the AutoML UI:

mlvision-test-n-use.png

Click Deploy model and then click Deploy.

This will take around 20 minutes to deploy.

Generate predictions

There are a few ways to generate predictions. In this lab you'll use the UI to upload images. You'll see how your model does classifying these two images (the first is a cirrus cloud, the second is a cumulonimbus).

Download these images to your local machine by right-clicking on each of them:

a4e6d50183e83703.png

1d4aaa17ec62e9ba.png

Return to the AutoML Vision UI, click Upload Images and upload the clouds to the online prediction UI. When the prediction request completes you should see something like the following:

predict.png

Click Check my progress to verify the objective.

Run the predictions

Pretty cool - the model classified each type of cloud correctly!

Congratulations!

You've learned how to train your own custom machine learning model and generate predictions on it through the web UI. Now you've got what it takes to train a model on your own image dataset.

What was covered

  • Uploading training images to Cloud Storage and creating a CSV for AutoML Vision to find these images.

  • Reviewing labels and training a model in the AutoML Vision UI.

  • Generating predictions on new cloud images.

Finish your Quest

ml_quest_icon.png ML-Image-Processing-badge.png

This self-paced lab is part of the Qwiklabs Machine Learning APIs and Intro to ML: Image Processing Quests. A Quest is a series of related labs that form a learning path. Completing a Quest earns you a badge to recognize your achievement. You can make your badge (or badges) public and link to them in your online resume or social media account. Enroll in these Quests and get immediate completion credit if you've taken this lab. See other available Qwiklabs Quests.

Take your next lab

Continue your Quest with Detect Labels, Faces, and Landmarks in Images with the Cloud Vision API, or check out these suggestions:

Next steps / learn more

Google Cloud Training & Certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated April 20, 2022
Lab Last Tested April 20, 2022

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.