Hello カスタム トレーニング: プロジェクトと環境を設定する

このページでは、Vertex AI を使用するための Google Cloud プロジェクトの設定と、トレーニングに使用する TensorFlow のコードのダウンロードを行う手順について説明します。また、予測に使用するウェブアプリのコードもダウンロードします。

このチュートリアルには複数のページが含まれます。

  1. プロジェクトと環境の設定

  2. カスタム画像分類モデルのトレーニング

  3. カスタム画像分類モデルによる予測情報のサービング

  4. プロジェクトのクリーンアップ

各ページは、前のページのチュートリアルの手順をすでに実施していることを前提としています。

始める前に

このチュートリアルでは、 Google Cloud コンソールと Cloud Shell を使用して Google Cloudを操作します。Cloud Shell の代わりに、Google Cloud CLI がインストールされている別の Bash シェルを使用することもできます。

  1. Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI and Cloud Run functions APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI and Cloud Run functions APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  8. Google Cloud コンソールで Cloud Shell をアクティブにします。

    Cloud Shell をアクティブにする

    Google Cloud コンソールの下部にある Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。Cloud Shell はシェル環境です。Google Cloud CLI がすでにインストールされており、現在のプロジェクトの値もすでに設定されています。セッションが初期化されるまで数秒かかることがあります。

  9. Cloud Shell のプロンプトに (PROJECT_ID)$ が表示されない場合(PROJECT_ID は Google Cloud プロジェクト ID に置き換えられています)、次のコマンドを実行して、このプロジェクトを使用するように Cloud Shell を構成します。

    gcloud config set project PROJECT_ID
    

Cloud Storage バケットを作成する

このチュートリアルの残りの部分で使用するリージョン Cloud Storage バケットを us-central1 リージョンに作成します。このチュートリアルを進めていくなかで、このバケットをいくつかの目的で使用します。

  • カスタム トレーニング ジョブに使用する Vertex AI 用のトレーニング コードを保存する。
  • カスタム トレーニング ジョブで出力されるモデル アーティファクトを保存する。
  • Vertex AI エンドポイントから予測を取得するウェブアプリをホストする。

Cloud Storage バケットを作成するには、Cloud Shell セッションで次のコマンドを実行します。

gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_ID --location=us-central1

次のように置き換えます。

  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • BUCKET_NAME: バケットに付ける名前。例: hello_custom_PROJECT_IDバケット名の要件をご覧ください。

サンプルコードをダウンロードする

チュートリアルの残りの部分で使用するサンプルコードをダウンロードします。

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

必要に応じて、次のコマンドを実行して、サンプルコード ファイルを表示します。

ls -lpR hello-custom-sample

hello-custom-sample ディレクトリには 4 つの項目があります。

  • trainer/: 花の分類モデルをトレーニングするための TensorFlow Keras コードのディレクトリ。

  • setup.py: Vertex AI が使用できる Python ソース ディストリビューションに trainer/ ディレクトリをパッケージ化するための構成ファイル。

  • function/: ウェブブラウザから予測リクエストを受信し、前処理、Vertex AI への送信、予測レスポンスの処理を行ってブラウザに送り返す Cloud Run 関数の Python コードのディレクトリ。

  • webapp/: Vertex AI から花の分類予測を取得するウェブアプリのコードとマークアップを含むディレクトリ。

次のステップ

このチュートリアルの次のページの手順に沿って Vertex AI でカスタム トレーニング ジョブを実行する。