Hello 自訂訓練:設定專案和環境

本頁將逐步說明如何設定 Google Cloud 專案以使用 Vertex AI,以及下載一些用於訓練的 TensorFlow 程式碼。您也會下載網頁應用程式的程式碼,用於取得預測結果。

本教學課程包含多個頁面:

  1. 設定專案和環境。

  2. 訓練自訂圖片分類模型。

  3. 透過自訂圖片分類模型提供預測結果。

  4. 清除專案所用資源。

各頁面都假設您已按照本教學課程先前頁面的指示操作。

事前準備

在本教學課程中,請使用 Google Cloud 控制台和 Cloud Shell 與 Google Cloud互動。或者,您也可以使用已安裝 Google Cloud CLI 的其他 Bash 殼層,而不使用 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. Verify that billing is enabled for your Google Cloud project.

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

    Enable the APIs

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

    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.

    Enable the APIs

  8. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

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

  9. 如果 Cloud Shell 的提示未顯示 (PROJECT_ID)$ (其中 PROJECT_ID 會替換為您的 Google Cloud 專案 ID),請執行下列指令,將 Cloud Shell 設定為使用您的專案:

    gcloud config set project PROJECT_ID
    
  10. 建立 Cloud Storage 值區

    us-central1 地區建立 Cloud Storage 地區值區,以供本教學課程的其餘部分使用。按照本教學課程操作時,請將這個 bucket 用於下列用途:

    • 儲存訓練程式碼,供 Vertex AI 用於自訂訓練工作。
    • 儲存自訂訓練工作輸出的模型構件。
    • 代管可從 Vertex AI 端點取得預測結果的網頁應用程式。

    如要建立 Cloud Storage bucket,請在 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 目錄有四個項目:

    • trainer/:用於訓練花朵分類模型的 TensorFlow Keras 程式碼目錄。

    • setup.py:用於將 trainer/ 目錄封裝至 Python 來源發布套件的設定檔,供 Vertex AI 使用。

    • function/:Python 程式碼的目錄,適用於可接收及預先處理來自網頁瀏覽器的預測要求、將要求傳送至 Vertex AI、處理預測回應,以及將回應傳回瀏覽器的 Cloud Run 函式

    • webapp/:這個目錄包含網頁應用程式的程式碼和標記,可從 Vertex AI 取得花卉分類預測結果。

    後續步驟

    請按照本教學課程的下一頁操作,在 Vertex AI 上執行自訂訓練工作。