Skip to main content

One post tagged with "Image Classification"

View All Tags

Train and Deploy an AutoML Image Classification Model with Vertex AI

ยท 4 min read

This tutorial guides you through the process of using Vertex AI to train and deploy an AutoML Image Classification model. You'll use a public flower image dataset, train the model using AutoML, evaluate its performance, deploy it to an endpoint, and send predictions โ€” all from the Google Cloud Console.



๐Ÿงฑ Step 1: Set Up Your Google Cloud Projectโ€‹


Select or Create a Projectโ€‹


  1. Visit the Google Cloud Console project selector.
  2. Choose an existing project or create a new one for this tutorial.

๐Ÿ’ก Tip: If you don't plan to retain the resources, create a new project so cleanup is easier.


Open Cloud Shellโ€‹


Click the Activate Cloud Shell button in the top-right of the console. Once ready, set your project ID:


gcloud config set project PROJECT_ID
export projectid=PROJECT_ID
echo $projectid

Replace PROJECT_ID with your actual project identifier.



๐Ÿ”ง Step 2: Enable Required APIsโ€‹


Run the following command in Cloud Shell:


gcloud services enable   iam.googleapis.com   compute.googleapis.com   notebooks.googleapis.com   storage.googleapis.com   aiplatform.googleapis.com

๐Ÿ” Step 3: Set IAM Permissionsโ€‹


Grant the necessary IAM roles:


gcloud projects add-iam-policy-binding PROJECT_ID   --member="user:your-email@example.com"   --role=roles/aiplatform.user

gcloud projects add-iam-policy-binding PROJECT_ID --member="user:your-email@example.com" --role=roles/storage.admin

These permissions allow you to use Vertex AI and access Cloud Storage for dataset management.


๐Ÿ—‚๏ธ Step 4: Create and Import Image Datasetโ€‹


Open Vertex AI > Datasetsโ€‹


  1. Click Create Dataset.
  2. Select Image as the data type.
  3. Choose Image Classification (Single-label).
  4. Set region to us-central1.
  5. Enter a name for the dataset (optional).
  6. Click Create.

Import Data from Cloud Storageโ€‹


Use this public CSV containing image URIs and labels:


cloud-samples-data/ai-platform/flowers/flowers.csv

This CSV includes rows like:


gs://cloud-samples-data/ai-platform/flowers/daisy/10559679065_50d2b16f6d.jpg,daisy
gs://cloud-samples-data/ai-platform/flowers/dandelion/10828951106_c3cd47983f.jpg,dandelion

๐Ÿ“Œ You'll see a preview of your images and labels after import completes (takes a few minutes).



๐Ÿง  Step 5: Train AutoML Modelโ€‹


  1. Go to the Models section.
  2. Click Train new model.
  3. Select:
    1. Training method: AutoML
    2. Target dataset: Your image dataset
  4. (Optional) Name your model.
  5. Define training options:
    • Training budget: 8 node hours
    • Enable Incremental Training: Only if you have a base model
  6. Click Start training.

๐Ÿ“ฌ Youโ€™ll get an email notification when training finishes (can take several hours).


๐Ÿ“ˆ Step 6: Evaluate Modelโ€‹


Navigate to the Evaluate tab of your model:


  • View key metrics:
    • Precision
    • Recall
    • Confusion Matrix
  • Analyze false positives, false negatives, and true positives.
  • Use Review Similar Images to find label inconsistencies or outliers.

๐Ÿ” Fix incorrect labels and re-train if needed to improve accuracy.


๐Ÿš€ Step 7: Deploy Model to Endpointโ€‹


  1. Go to Deploy & Test tab.
  2. Click Deploy to Endpoint.
  3. Choose:
    • Create New Endpoint
    • Name: image-classification
    • Traffic Split: 100%
    • Compute Nodes: 1
  4. Click Deploy.

Deployment takes a few minutes.


๐Ÿงช Step 8: Send a Predictionโ€‹


After deployment:


  1. Go to Deploy & Test > Test your model.
  2. Click Upload Image.
  3. Choose a local image.
  4. View the predicted label and confidence.

๐Ÿงน Step 9: Clean Up Resourcesโ€‹


To avoid charges, delete the resources:

Undeploy Modelโ€‹


Vertex AI > Models > Deploy & Test > Undeploy

Delete Endpointโ€‹


Vertex AI > Endpoints > Delete image-classification

9.3 Delete Model and Datasetโ€‹


Vertex AI > Models > Delete
Vertex AI > Datasets > Delete

Delete Cloud Storage Bucketโ€‹


Go to Cloud Storage and delete your bucket.


๐Ÿ“š Summaryโ€‹


  • โœ… Created dataset with labeled images
  • โœ… Trained an AutoML image classification model
  • โœ… Evaluated model performance
  • โœ… Deployed to a live endpoint
  • โœ… Sent predictions and cleaned up

Vertex AI simplifies machine learning workflows with a UI-based AutoML approach. Stay tuned for more advanced tutorials on custom training, multi-class classification, and model explainability.


๐Ÿ’ก "Teaching AI has never been easier. With Vertex AI, all you need is your data."