Hello custom training: Setting up your project and environment

This page walks through setting up your Google Cloud project to use Vertex AI and downloading some TensorFlow code for training. You will also download code for a web app that gets predictions.

This document is part of the "Hello custom training" tutorial, which walks you through using Vertex AI to train an image classification model and serve predictions using the model. In this tutorial, you use Vertex AI's custom training feature to run a TensorFlow Keras training application in one of Vertex AI's pre-built container environments. This custom training job trains a machine learning (ML) model to classify images of flowers by their type. After you train the ML model, the tutorial shows you how to create an endpoint and serve predictions from that endpoint to a simple web app.

This tutorial has several pages:

  1. Setting up your project and environment.

  2. Training a custom image classification model.

  3. Serving predictions from a custom image classification model.

  4. Cleaning up your project.

Each page assumes that you have already performed the instructions from the previous pages of the tutorial.

Before you begin

Throughout this tutorial, use Google Cloud Console and Cloud Shell to interact with Google Cloud. Alternatively, you can use another Bash shell with the Cloud SDK installed instead of Cloud Shell.

  1. 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.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. Enable the Vertex AI and Cloud Functions APIs.

    Enable the APIs

  5. In the Cloud Console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Cloud Console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Cloud SDK already installed, including the gcloud command-line tool, and with values already set for your current project. It can take a few seconds for the session to initialize.

  6. If Cloud Shell does not display (PROJECT_ID)$ in its prompt (where PROJECT_ID is replaced by your Google Cloud project ID), then run the following command to configure Cloud Shell to use your project:

    gcloud config set project PROJECT_ID
    

1. Create a Cloud Storage bucket

Create a regional Cloud Storage bucket in the us-central1 region to use for the rest of this tutorial. As you follow the tutorial, use the bucket for several purposes:

  • Store training code for Vertex AI to use in a custom training job.
  • Store the model artifacts that your custom training job outputs.
  • Host the web app that gets predictions from your Vertex AI endpoint.

To create the Cloud Storage bucket, run the following command in your Cloud Shell session:

gsutil mb -p PROJECT_ID -l us-central1 gs://BUCKET_NAME

Replace the following:

  • PROJECT_ID: The ID of your Google Cloud project.
  • BUCKET_NAME: A name that you choose for your bucket. For example, hello_custom_PROJECT_ID. Learn about requirements for bucket names.

2. Download sample code

Download sample code to use for the rest of the tutorial. Run the following commands in your Cloud Shell session to download, unzip, and navigate to the directory with sample code for this tutorial:

gsutil cp gs://cloud-samples-data/ai-platform/hello-custom/hello-custom-sample-v1.tar.gz - | tar -xzv
cd hello-custom-sample

Optionally, run the following command to examine the sample code:

ls -lpR

The hello-custom-sample directory has four items:

  • trainer/: A directory of TensorFlow Keras code for training the flower classification model.

  • setup.py: A configuration file for packaging the trainer/ directory into a Python source distribution that Vertex AI can use.

  • function/: A directory of Python code for a Cloud Function that can receive and preprocess prediction requests from a web browser, send them to Vertex AI, process the prediction responses, and send them back to the browser.

  • webapp/: A directory with code and markup for a web app that gets flower classification predictions from Vertex AI.

What's next

Follow the next page of this tutorial to run a custom training job on Vertex AI.