Checkpoints
Upload training images to Cloud Storage
/ 25
Create a dataset
/ 25
Train your model
/ 25
Deploy to endpoint
/ 25
Identify Damaged Car Parts with Vertex AutoML Vision
GSP972
Overview
Vertex AI brings together the Google Cloud services for building ML under one, unified UI and API. In Vertex AI, you can now easily train and compare models using AutoML or custom code training and all your models are stored in one central model repository. These models can now be deployed to the same endpoints on Vertex AI.
AutoML Vision helps anyone with limited Machine Learning (ML) expertise train high quality image classification models. In this hands-on lab, you will learn how to produce a custom ML model that automatically recognizes damaged car parts.
Once you’ve produced your ML model, it’ll be immediately available for use. You can use the UI or the REST API to start generating predictions directly from the Google Cloud Console.
Objectives
In this lab, you learn how to:
-
Upload a labeled dataset to Cloud Storage using a CSV file and connect it to Vertex AI as a Managed Dataset
-
Inspect uploaded images to ensure there are no errors in your dataset
-
Review your trained model and evaluate its accuracy
Setup and requirements
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.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
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 the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
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.
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.
-
Click Activate Cloud Shell
at the top of the Google Cloud console.
-
Click Continue.
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. The output contains a line that declares the PROJECT_ID for this session:
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
-
(Optional) You can list the active account name with this command:
Output:
-
(Optional) You can list the project ID with this command:
Output:
Example output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Upload training images to Cloud Storage
In this task you will upload the training images you want to use to Cloud Storage. This will make it easier to import the data into Vertex AI later.
To train a model to classify images of damaged car parts, you need to provide the machine with labeled training data. The model will use the data to develop an understanding of each image, differentiating between car parts and those with damages on them.
In this example, your model will learn to classify five different damaged car parts: bumper, engine compartment, hood, lateral, and windshield.
Create a Cloud Storage bucket
-
To start, open a new Cloud Shell window and execute the following commands to set some environment variables:
- Next, to create a Cloud Storage bucket, execute the following command:
Upload car images to your Storage Bucket
The training images are publicly available in a Cloud Storage bucket. Again, copy and paste the script template below into Cloud Shell to copy the images into your own bucket.
-
To copy images into your Cloud Storage bucket, execute the following command:
-
In the navigation pane, click Cloud Storage > Browser.
-
Click the Refresh button at the top of the Cloud Storage browser.
-
Click on your bucket name. You should see five folders of photos for each of the five different damaged car parts to be classified:
- Optionally, you can click one of the folders and check out the images inside.
Great! Your car images are now organized and ready for training.
Click Check my progress to verify the objective.
Task 2. Create a dataset
In this task, you create a new dataset and connect your dataset to your training images to allow Vertex AI to access them.
Normally, you would create a CSV file where each row contains a URL to a training image and the associated label for that image. In this case, the CSV file has been created for you; you just need to update it with your bucket name and upload the CSV file to your Cloud Storage bucket.
Update the CSV file
Copy and paste the script templates below into Cloud Shell and press enter to update, and upload the CSV file.
- To create a copy of the file, execute the following command:
- To update the CSV with the path to your storage, execute the following command:
-
Verify your bucket name was inserted into the CSV properly:
- To upload the CSV file to your Cloud Storage bucket, execute the following command:
-
Once the command completes, click the Refresh button at the top of the Cloud Storage browser and open your bucket.
-
Confirm that the
data.csv
file is listed in your bucket.
Create a managed dataset
-
In the Google Cloud Console, on the Navigation menu (
) click Vertex AI > Dashboard.
-
Click Enable Vertex AI API.
-
From the Vertex AI navigation menu on the left, click Datasets.
-
At the top of the console, click + Create.
-
For Dataset name, type
damaged_car_parts
. -
Select Image classification (Single label). (Note: in your own projects, you may want to check the "Multi-label Classification" box if you're doing multi-class classification).
-
Click Create.
Connect your dataset to your training images
In this section, you will choose the location of your training images that you uploaded in the previous step.
-
In the Select an import method section, click Select import files from Cloud Storage.
-
In the Select import files from Cloud Storage section, click Browse.
-
Follow the prompts to navigate to your storage bucket and click your
data.csv
file. Click Select. -
Once you've properly selected your file, a green checkbox appears to the left of the file path. Click Continue to proceed.
- Once the import has completed, prepare for the next section by clicking the Browse tab. (Hint: You may need to refresh the page to confirm.)
Click Check my progress to verify the objective.
Task 3. Inspect images
In this task, you examine the images to ensure there are no errors in your dataset.
Check image labels
-
If your browser page has refreshed, click Datasets , select your image name, and then click Browse.
-
Under Filter labels, click any one of the labels to view the specific training images. (Example: engine_compartment.)
- If an image is labeled incorrectly, you can click on it to select the correct label or delete the image from your training set:
- Next, click on the Analyze tab to view the number of images per label. The Label Stats window appears on the right side of your browser.
Task 4. Train your model
You're ready to start training your model! Vertex AI handles this for you automatically, without requiring you to write any of the model code.
-
From the right-hand side, click Train New Model.
-
From the Training method window, leave the default configurations and select AutoML as the training method. Click Continue.
-
From the Model details window, enter a name for your model, use:
damaged_car_parts_model
. -
From the Explainability window, click continue and for Compute and pricing window, set your budget to 8 maximum node hours.
-
Click Start Training.
Click Check my progress to verify the objective.
Task 5. Evaluate your model
In this task, you evaluate your model. This will vary based on the metrics you chose for your model. Ideally, you’ll work with a data scientist at this point to verify the accuracy of your model.
- Navigate to your newly trained model. Click on the Evaluate tab. This tab displays information about Precision and Recall of the model. It should resemble the following:
-
You can also adjust the Confidence threshold slider to see its impact.
-
Scroll down to view the Confusion matrix.
This section provides some common machine learning metrics to help you evaluate your model’s accuracy and identify areas for improvement in your training data.
Task 6. Test your understanding
In this task, answer the following multiple-choice questions to reinforce your understanding of this lab's concepts. Answer the questions to the best of your abilities.
- The confusion matrix provides insights on the classes (aka labels) that the model is still a little confused about.
- Everything that is greater than 0 and is outside of the diagonal represents misclassification. These will be highlighted.
- Use the highlighted boxes as signals to consider collecting more labeled images and to help improve the confidence of the classification.
Task 7. Deploy to endpoint
-
From the Vertex AI navigation menu on the left, select Models Registry.
-
Click the model you just created (
damaged-car-part-model
) and then click on Version ID. -
Click on DEPLOY & TEST tab, click Deploy to Endpoint.
-
For the name, use
damaged-car-part-model-endpoint
. Click Continue. -
Keep the Traffic Split and Logging as default and set the Number of compute nodes to 1.
-
Click Done. Then click Deploy.
Click Check my progress to verify the objective.
Task 8. 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'll use the UI to upload new images and see how your model classifies the following images:
-
Damaged bumper
-
Damaged engine compartment
-
Damage to the hood and the bumper.
Note: This last image is a good candidate for a multi-label classification problem.
Add the images below to your model
Download these images to your local machine and then upload them to the model:
-
Right-click on each image below, then select Save image As…
-
Follow the prompts to save each image with a unique name. (Hint: Assign a simple name like 'Image1' and 'Image2' to assist with uploading later)
-
In the Cloud console, navigate to the Deploy & Test tab in the Vertex AI UI.
-
Under your newly deployed endpoint, click the Upload Image button under Test your model.
- Follow the prompts to select and upload the sample images you just saved to your local disk. When the prediction requests complete you should see something like the following:
How did your model do? Did it predict all three images correctly?
Congratulations!
In this lab, you learned how to train your own custom machine learning model and generate predictions on it through the web UI. You uploaded training images to Cloud Storage and used a CSV file for Vertex AI to find these images. You inspected the labeled images for any discrepancies before finally evaluating a trained model. Now you've got what it takes to train a model on your own image dataset.
Finish your quest
This self-paced lab is part of the Build and Deploy Machine Learning Solutions on Vertex AI quest. A quest is a series of related labs that form a learning path. Completing this 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 this quest and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.
Take your next lab
Continue the Build and Deploy Machine Learning Solutions on Vertex AI
quest with the next lab, Deploy a BigQuery ML Customer Churn Classifier to Vertex AI for Online Predictions.
Next steps / learn more
- Read more about Vertex AI in the Vertex AI Documentation
Google Cloud training and 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 August 17, 2022
Lab Last Tested August 17, 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.