Classify Images of Cats and Dogs using Transfer Learning

Join Sign in

Classify Images of Cats and Dogs using Transfer Learning

1 hour 1 Credit


Google Cloud self-paced labs logo


TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML powered applications.

This lab uses transfer learning to train your machine. In transfer learning, when you build a new model to classify your original dataset, you reuse the feature extraction part and re-train the classification part with your dataset. This method uses less computational resources and training time. Deep learning from scratch can take days, but transfer learning can be done in short order.

What you'll do

  • Examine and understand your image data
  • Build an input pipeline using Keras ImageDataGenerator
  • Use a pre-trained model for feature extraction
  • Fine-tune a pre-trained model


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).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud Console

  1. 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
  2. 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.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. 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.
  5. 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.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left. Navigation menu icon

Task 1. Launch AI platform notebooks

An managed notebook instance using the latest TensorFlow Enterprise image was pre-provisioned using Vertex AI Workbench for this lab.

To access your notebook instance, follow these steps:

  1. Click on the Navigation Menu. Navigate to Vertex AI, then to Workbench.
  1. In the following page, you should see the qwiklabs-tensorflow-notebook instance with a green check mark by it.
Note: If you do not see any instances appear, wait a minute and refresh the page.
  1. Click Open JupyterLab. A JupyterLab window will open in a new tab.

Launcher window displaying action tiles under the Notebook, Console and Other sections

Task 2. Download lab notebook

To download the transfer_learning notebook in your JupyterLab instance:

  1. In JupyterLab, click the Terminal icon to open a new terminal.

The Launcher window with the Terminal tile highlighted in the Other section

  1. At the command-line prompt, type in the following command and press Enter:
curl --output transfer_learning.ipynb
  1. Run this command to clear all outputs in the transfer_learning notebook's cells:
jupyter nbconvert --clear-output --inplace transfer_learning.ipynb

Click Check my progress to verify the objective. Download lab notebook

Task 3. Open and execute the notebook

  1. From within the Jupyter console, select transfer_learning.ipynb to begin the lab. Now you're ready to start!
  1. From here, read the instructions in the notebook to complete the lab.

  2. Execute the cells one by one and observe the results. A convenient way to progress through the cells is by clicking in a cell, then click Shift + Enter, waiting for each cell to complete before progressing.

  3. Read the instructions and the comments in the code blocks carefully. You will be asked to edit some of the code blocks before running them. For example, you will be setting environment variables in the notebook, so add your bucket name and project ID before running the cell.


You've compiled a model which accurately classifies images of dogs and cats within a reasonable amount of time!

Finish your quest

This self-paced lab is part of the Google Cloud Solutions ll: Data and Machine Learning and Intermediate ML: TensorFlow on Google Cloud quests. A quest is a series of related labs that form a learning path. Completing a quest earns you the badge above, 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 any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.

Take your next lab

Continue your quest with Creating an Object Detection Application Using TensorFlow, or try one of these suggestions:

Next steps / learn more

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 September 13, 2022

Lab last tested June 08, 2021

Copyright 2023 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.