0% found this document useful (0 votes)
4 views30 pages

Lab 5 Classifying Images of Clouds in The Cloud With AutoML Vision

Uploaded by

Julius Sutrisno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Lab 5 Classifying Images of Clouds in The Cloud With AutoML Vision

Uploaded by

Julius Sutrisno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Classifying Images of Clouds in the Cloud with AutoML Vision

help_outline
language

Start Lab

02:30:00

 Overview
 Set up your environments
 Task 1. Set up AutoML Vision
 Task 2. Upload training images to Cloud Storage
 Task 3. Create an AutoML Vision training dataset
 Task 4. Inspect the images
 Task 5. Train your model
 Task 6. Evaluate your model
 Task 7. Generate predictions
 Congratulations!
 End your lab
Classifying Images of
Clouds in the Cloud
with AutoML Vision
2 hours 30 minutes1 Credit

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

What you learn

In this lab, you learn how to perform the following tasks:

 Upload a labeled dataset to Cloud Storage and


connect it to AutoML Vision with a CSV label
file
 Train a model with AutoML Vision and
evaluate its accuracy

 Generate predictions on your trained model

Set up your environments

Lab setup

For each lab, you get a new GCP project and set of resources for a fixed time at no cost.

1. Make sure you signed into Qwiklabs


using an incognito window.

2. Note the lab's access time (for

example, and make


sure you can finish in that time block.

There is no pause feature. You can restart if needed, but you have to start at the beginning.
3. When ready,

click .

4. Note your lab credentials. You will use


them to sign in to Cloud Platform
Console.

5. Click Open Google Console.

6. Click Use another account and


copy/paste credentials for this lab into
the prompts.

If you use other credentials, you'll get errors or incur charges.


7. Accept the terms and skip the recovery
resource page.
Do not click End Lab unless you are finished with the lab or want to restart it. This clears your
work and removes the project.

Task 1. 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 AutoML API.

Open the navigation menu and and select APIs & Services > Library. In the search bar type in
"Cloud AutoML API". Click on the Cloud AutoML API result and then click Enable.

This may take a minute. You should now be on the following page (ensure that the
Activation Status is Enabled):

Create a Cloud Storage bucket for your training data


1. On the GCP Console title bar,
click Activate Cloud Shell ( ).
2. When prompted, click Continue.
In Cloud Shell, paste the below command to make a new bucket to hold your training. We use
the magic variable $DEVSHELL_PROJECT_ID, which knows your current project, and simply
add -vcm to the end.

3. Run the below command in Cloud


Shell:
gsutil mb -p $DEVSHELL_PROJECT_ID \
-c regional \
-l us-central1 \
gs://$DEVSHELL_PROJECT_ID-vcm/
Copied!
content_copy
Leave your Cloud Shell window open for additional steps to follow.

4. Click to open the AutoML UI ub a new


browser tab .
The AutoML Vision datasets page opens once the APIs are verified.

Task 2. 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.

1. In the Cloud Console, open


the Navigation menu and select Cloud
Storage > Browser.
Once there, you should see the bucket from the last step.
2. 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://cloud-training/automl-lab-clouds/*
gs://$DEVSHELL_PROJECT_ID-vcm/
Copied!
content_copy
3. Once copying is complete you can view
the CSV file and three types of clouds
you have images for:
gsutil ls gs://$DEVSHELL_PROJECT_ID-vcm/
Copied!
content_copy
Which types of clouds do you have training data (images) for?

Stratus

Cirrus

Cumulonimbus

Cumulus
Submit

Optional: View the images using the Cloud Storage


Console UI

1. When the images finish copying, click


the Refresh button at the top of the
Cloud Storage browser.
2. Then click on your bucket name. You
should see a data.csv file and 3
folders of photos for each of the 3
different cloud types to be classified:
If you click on the individual image files in each folder, and then click once more when you see
the URL, you can see the photos you'll be using to train your model for each type of cloud.
Task 3. Create an AutoML Vision training
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.

1. Run the following commands which:


 Copy the template file to your Cloud Shell
instance

 Update the CSV with the files in your project

 Upload this updated CSV file to your Cloud


Storage bucket

 Show the bucket to confirm the data.csv file is


present

gsutil cp gs://cloud-training/automl-lab-clouds/data.csv .
head --lines=10 data.csv
sed -i -e "s/placeholder/$DEVSHELL_PROJECT_ID-vcm/g" ./data.csv
head --lines=10 data.csv
gsutil cp ./data.csv gs://$DEVSHELL_PROJECT_ID-vcm/
gsutil ls gs://$DEVSHELL_PROJECT_ID-vcm/
Copied!
content_copy
2. View all the folders and files in your
bucket you can add a wildcard
to gsutil ls like so:
gsutil ls gs://$DEVSHELL_PROJECT_ID-vcm/*
Copied!
content_copy
3. Highlight and copy the location of your
data file to your clipboard which will
look similar to: gs://qwiklabs-
gcp-your-project-id-will-
be-here-vcm/data.csv

4. Click to open the AutoML


Vision datasets page.
5. At the top of the Cloud Console,
click + New dataset.

6. Type clouds for the dataset name.

7. Leave Single-Label
Classification checked.

8. Click Create dataset to continue.


On the next screen you will choose the location of your training images (the ones you uploaded
in the previous step).

9. Choose Select a CSV file on Cloud


Storage and add the file name to the
URL for the file that is in your
clipboard from the previous step. You
may also use the browse function to
find the csv file. Once you see the
white in green checkbox you may
select Continue to proceed.
10. Once the import has completed click
the Images tab to see the images in
your dataset.
 It will take 8 to 12 minutes while the image
metadata is processed ("Running: Importing
Images" will appear on the screen).
 Once complete, the images will appear by
category.

Task 4. Inspect the images


1. Next, proceed with a brief examination
of the images.
2. Try filtering by different labels in the
left menu (i.e. click cumulus) to review
the training images.
Note: If you were building a production model, you'd want at least 100 images per label to
ensure high accuracy. This is just a demo so only 20 images of each type were used so the model
could train quickly.
3. If any images are labeled incorrectly
you can click on them to switch the
label or delete the image from your
training set:
4. To see a summary of how many images
you have for each label, click on Label
stats. You should see the following
pop-out box show up on the right side
of your browser.
5. Press Done after reviewing the list.
Note: If you are working with a dataset that isn't already labeled, AutoML Vision provides an in-
house human labeling service.

Task 5. 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.

1. To train your clouds model, go to


the Train tab and click Start training.
2. Enter a name for your model, or use the
default auto-generated name.

3. Leave Cloud hosted selected and


click Continue.

4. For the next step, type the value "8"


into the Set your budget * box and
check Deploy model to 1 node after
training. This process (auto-deploy)
will make your model immediately
available for predictions after testing is
complete.

5. Click Start training.

Note: Training this custom model can be expected to take over an hour to complete (55 to 90
minutes on average). The total training time includes node training time as well as infrastructure
setup and tear down. To get full credit for the lab you do not need to wait for training to
complete and can simply review the below screenshots from Evaluation and Prediction.

Task 6. Evaluate your model


1. After training is complete, select
the Evaluate tab. Here you'll see
information about Precision and Recall
of the model. It should resemble the
following:
2. You can also adjust the Confidence
threshold slider to see its impact.

3. Finally, scroll down to take a look at


the Confusion matrix.
This tab 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. Feel free to browse the accuracy metrics on your
own.
Task 7. Generate predictions
Now it's time for the most important part: generating predictions on your trained model using
data it hasn't seen before.

There are a few ways to generate predictions. In this lab you 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).

1. First, download these images to your


local machine by right-clicking on each
of them (Note: You may want to assign
a simple name like 'Image1' and
'Image2' to assist with uploading later):
2. Navigate to the Test & Use tab in the
AutoML UI.
On this page you will see that the model you just trained and deployed is listed in the Model pick
list.

3. Click Upload images and upload the


cloud sample images you just saved to
your local disk (you can select both
images at the same time).
When the prediction request completes you should see something like the following:
Excellent - 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.

End your lab


When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the
resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of
stars, type a comment, and then click Submit.

The number of stars indicates the following:

 1 star = Very dissatisfied


 2 stars = Dissatisfied
 3 stars = Neutral
 4 stars = Satisfied
 5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2021 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.

How satisfied are you with this lab?*


Additional Comments

Cancel
Submit
error_outline

All done? If you end this lab, you will lose all
your work. You may not be able to restart the
lab if there is a quota limit. Are you sure you
want to end this lab?
Cancel
Submit

You might also like