Label images by using an AutoML Vision Edge model
This quickstart walks you through the process of:
- Copying a set of images into Google Cloud Storage.
- Creating a CSV listing the images and their labels.
- Using AutoML Vision to create your dataset, train a custom AutoML Vision Edge model (image classification or object detection), and make a prediction.
- Exporting and deploying your AutoML Vision Edge model for one of several types of edge devices, such as mobile phones, ARM-based devices, and the Coral Edge TPU.
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.
-
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.
-
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 Google Cloud Storage bucket. The bucket name must be in the format:
project-id-vcm
. The following command creates a storage bucket in theus-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 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 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 (optional), select the model objective, and then click Create dataset to continue the dataset creation process.
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 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
Edge model radio option. Select Continue to move to the following section.In the Optimize model for section accept the
Best trade-off option and select Continue.In the Set a node hour budget section accept the suggested node budget (4 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 the model
Before you can export your model you must deploy it for use.
To deploy your model, select the Test & use tab. In the tab click the Deploy model option near the model name.
In the window that follows, specify 1 node to deploy on, and select Deploy to begin the model deployment process.
You will receive a notification when model deployment completes.
Export the model
The final step in using an AutoML Vision Edge model is to export (optimize and download) and deploy (use) your model.
There are multiple ways you can export and deploy your models to use for prediction on Edge devices.
In this quickstart you will use Tensorflow Lite (TF Lite) as an example. TF Lite models are both easy to use and have a wide set of use cases.
Under the Use your model section of the Test & use tab, select the TF Lite option.
In the Export TF Lite package window that shows, specify a Cloud Storage bucket location to export a TF Lite package to, then select Export. The export process typically takes several minutes.
In the Google Cloud Storage destination location you will find a folder named with timestamp and model format, under which you can find the following files:
- a tflite file (
model.tflite
), - a dictionary file (
dict.txt
) - a metadata file (
tflite_metadata.json
)
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.
What's next
With these files, you can follow tutorials to deploy on Android devices, iOS devices, Raspberry Pi 3, or the Web.
Other model use options
- You can export the model as a CoreML (iOS/macOS) supported model. After training, you can export the model by selecting the CoreML option in the Test & use tab, and follow the CoreML tutorial.
- You can export the model for running on the Coral Edge TPU. After training, export the model by selecting the Coral option in the Test & use tab. However, due to current incompatibility with our object detection model, we recommend you only export image classification models for the Edge TPU (to train an object detection model for the Edge TPU, instead follow one of these Google Colab tutorials). After exporting your model, follow Coral's official documentation about how to run an inference on the Edge TPU.
- You can export the model as TensorFlow SavedModel and use it with a Docker container. After training, you can export the model by selecting the Container option in the Test & use tab, and follow the Edge containers tutorial on how to export to a container.
- You can export the model for use in a browser or in Node.js as a Tensorflow.js model. After training, you can export the model by selecting the Tensorflow.js option in the Test & use tab, and follow the Edge TensorFlow.js tutorial.
Cleanup
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.