Google Cloud: Creating Image Classification ML Model on Dog/Cat Dataset

Share At:

Integrate Google Cloud Vision with Spring Boot | by Hamdi Bouallegue |  Medium


In this lab, you upload images to Cloud Storage and use them to train a custom model to recognize whether the image is of Dog or Cat.

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

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

For our lab, we have created a storage bucket named “cloud-vision-rjv2”.

Task 2. Upload training images to Cloud Storage

In order to train a model to classify images of dogs and cats, you need to provide labeled training data so the model can develop an understanding of the image features. In this example, our model will learn to classify between dogs and cats. To use AutoML Vision you need to put your training images in Cloud Storage.

  1. Open cloudshell and clone the images from github repo:
git clone

2. Now copy the contents from git repo to storage bucket:

3. The content of data.csv should look like below:

4. Verify that data has been uploaded successfully to storage bucket:

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 and has already been updated with bucket name.

  1. Navigate back to the AutoML Vision datasets page.

At the top of the Cloud Console, click + New dataset.

Type cat_dog_dataset for the dataset name.

Leave Single-label Classification checked.

Click Create dataset to continue.

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

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.

  1. 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

Next, proceed with a brief examination of the images.

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. Press Done after reviewing the list.

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.

To train your clouds model, go to the Train tab and click Start training.

Enter a name for your model, or use the default auto-generated name.

Leave Cloud hosted selected and click Continue.

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.

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 set up and tear down. To get full credit for the lab you do not need to wait for training to complete and can simply review at the below screenshots from Evalution and Prediction.

Task 6. Evaluate your model

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:

You can also adjust the Confidence threshold slider to see its impact.

Finally, scroll down to take a look at the Confusion matrix.

Confusion Matrix:

This tab provides some common machine learning metrics to evaluate your model accuracy and see where you can improve your training data. 

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 some images !!

First, download some images of cats and dogs to your local machine.

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.

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 Cat and Dog Correctly !!


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.

Happy Learning !!

Share At:
0 0 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
1 day ago

I may need your help. I’ve been doing research on gate io recently, and I’ve tried a lot of different things. Later, I read your article, and I think your way of writing has given me some innovative ideas, thank you very much.

2 days ago

panelvan kiralama

4 days ago

panelvan araç kiralama

Heets Marketi
6 days ago

IQOS Heets Marketi

Saniya Wade
7 days ago

web sitesi yaptırmak

Inscription à Binance US

Your article helped me a lot, is there any more related content? Thanks!

Зарегистрироваться в binance

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

vds satın al
2 months ago

vds satın al ile ilgili tüm bilgiler vds satın al

marka host
2 months ago

sanal sunucu , vds , reseller hosting , wordpress hosting , linux hosting , kurumsal hosting , vds satın al ve benzeri tüm makaleler web sitemizde markahost wordpress

Back To Top

Contact Us