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

本頁面將逐步說明如何設定 Google Cloud 專案,以便使用 Gemini Enterprise Agent Platform,並下載一些 TensorFlow 程式碼進行訓練。您也會下載網頁應用程式的程式碼,用於取得預測結果。

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

  1. 設定專案和環境。

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

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

  4. 清理專案。

每個頁面都假設您已執行本教學課程前幾頁的操作說明。

事前準備

在本教學課程中,您將使用 Google Cloud 控制台和 Cloud Shell 與 Google Cloud互動。或者,您也可以使用其他已安裝 Google Cloud CLI 的 Bash 殼層,而非 Cloud Shell。

  1. 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎 建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $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 Gemini Enterprise Agent Platform and Cloud Run functions APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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 Gemini Enterprise Agent Platform and Cloud Run functions APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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 bucket

在 us-central1 區域建立區域 Cloud Storage bucket,用於本教學課程的其餘部分。在教學課程中,您會將 bucket 用於多種用途:

  • 儲存訓練程式碼,供 Agent Platform 在自訂訓練工作中使用。
  • 儲存自訂訓練工作輸出的模型構件。
  • 託管網頁應用程式,從 Agent Platform 端點取得預測結果。

如要建立 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:您為 bucket 選擇的名稱。例如:hello_custom_PROJECT_ID。瞭解bucket 名稱規定。

下載程式碼範例

下載教學課程其餘部分會用到的程式碼範例。

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/ 目錄封裝成 Agent Platform 可使用的 Python 來源發行版本。

  • function/:Cloud Run 函式的 Python 程式碼目錄,可接收及預先處理網路瀏覽器的預測要求、將要求傳送至 Agent Platform、處理預測回應,並將回應傳回瀏覽器。

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

後續步驟

請按照本教學課程下一頁的說明,在 Agent Platform 執行自訂訓練工作。