Label images by using AutoML Vision
This quickstart walks you through the process of:
- Copying a set of images into Cloud Storage.
- Creating a CSV listing the images and their classification labels.
- Using AutoML Vision to create your dataset, and train and deploy your model.
- Classifying an image using your model trained with custom labels.
Before you begin
Set up your project
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
-
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
-
-
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
-
Enable the AutoML and Cloud Storage APIs:
gcloud services enable storage-component.googleapis.com
automl.googleapis.com storage-api.googleapis.com - Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
-
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
-
-
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
-
Enable the AutoML and Cloud Storage APIs:
gcloud services enable storage-component.googleapis.com
automl.googleapis.com storage-api.googleapis.com - Set the
PROJECT_ID
environment variable to your Project ID.export PROJECT_ID=PROJECT_ID
The AutoML API calls and resource names include your Project ID in them. ThePROJECT_ID
environment variable provides a convenient way to specify the ID.
Create a Cloud Storage bucket
Use Cloud Shell, a browser-based Linux command line connected to your Google Cloud console project, to create your Cloud Storage bucket:
Create a Cloud Storage bucket. The bucket name must be in the format:
project-id-vcm
.The following command creates a storage bucket in the
us-central1
region namedproject-id-vcm
. For a complete list of available regions, see the Bucket Locations page.gsutil mb -p ${PROJECT_ID} -c regional -l us-central1 gs://${PROJECT_ID}-vcm/
Set the BUCKET variable.
export BUCKET=${PROJECT_ID}-vcm
Copy the sample images into your bucket
Next, copy the flower dataset used in this Tensorflow blog post. The images are stored in a public Cloud Storage bucket, so you can copy them directly from there to your own bucket.
In your Cloud Shell session, enter:
gsutil -m cp -R gs://cloud-samples-data/ai-platform/flowers/ gs://${BUCKET}/img/
The file copying takes about 20 minutes to complete.
Create the image classification CSV file
The sample dataset contains a CSV file with all of the image locations and the labels for each image. You'll use that to create your own CSV file:
Update the CSV file to point to the files in your own bucket:
gsutil cat gs://${BUCKET}/img/flowers/all_data.csv | sed "s:cloud-ml-data/img/flower_photos/:${BUCKET}/img/flowers/:" > all_data.csv
Copy the CSV file into your bucket:
gsutil cp all_data.csv gs://${BUCKET}/csv/
Create your image classification dataset
Visit the AutoML Vision UI to begin the process of creating your dataset and training your model.
When prompted, make sure to select the project that you used for your Cloud Storage bucket.
From the AutoML Vision page, click New Dataset:
Specify a name for this dataset. Click the + sign to continue.
In the Select files to import screen choose the
Select a CSV file on Cloud Storage radio option. Specify the Cloud Storage URI of your CSV file. For this quickstart, the CSV file is at:gs://${PROJECT_ID}-vcm/csv/all_data.csv
Replace
PROJECT_ID
with your specific project ID.Click Continue to begin image import. The import process takes a few minutes. When it completes, you are taken to the next page which has details on all of the images identified for your dataset, both labeled and unlabeled images.
Train your Cloud-hosted AutoML Vision model
Once your dataset has been created and processed, select the Train tab to initiate model training.
Select Start training to continue. This will open a Train new model window with training options.
In the Define your model section of the new model training window, change the model name (optional) and select the
Cloud hosted model radio option. Select Continue to move to the following section.In the Set a node hour budget section accept the suggested node budget (32 node hours).
Select "Start training" to begin model training.
Training is initiated for your model, and should take about an hour. The training might stop earlier than the node hour you selected. The service will email you once training has completed, or if any errors occur.
Deploy your AutoML Vision classification model
After your model has been successfully trained, you can use it to label images using your custom model. Select the Test and Use tab.
If you didn't opt-in for auto-deploy you will be prompted to deploy your model before you can make predictions.
Label an image using your AutoML Vision model
Click the Predict tab for instructions on sending an image to your model to get image content labels. You can also refer to Making an online prediction or Making batch predictions for examples.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the Google Cloud project with the resources.
If you no longer need your custom model or dataset, you can delete them.
To avoid unnecessary Google Cloud Platform charges, use the GCP Console to delete your project if you do not need it.
Undeploy your model
Your model incurs charges while it is deployed.
- Select the Test & Use tab just below the title bar.
- Select Remove deployment from the banner beneath your model name to open
the undeploy option window.
- Select Remove deployment to undeploy the model.
- You will receive an email when model undeployment has completed.
Delete your project (optional)
To avoid unnecessary Google Cloud Platform charges, use the Google Cloud console to delete your project if you do not need it.
What's next
- Learn more about machine learning (ML) in the Beginner's guide.
- Learn about ML fairness in the Inclusive ML guide - AutoML.
- Train an exportable AutoML Vision Edge model using the Edge device model quickstart.
- Get started with the AutoML Vision API in your language of choice by using a AutoML Vision API Client Library.
- Use the How-to guides to learn more about specific resource creation and management (such as datasets and models), or how to get annotations for an individual image or a batch of images.
- Work through one of the tutorials.