Hello 图片数据:设置项目和环境

如果您计划使用 Python 版 Vertex AI SDK,请确保初始化客户端的服务账号具有 Vertex AI Service Agent (roles/aiplatform.serviceAgent) IAM 角色。

您需要设置 Google Cloud 项目以使用 Vertex AI。然后创建 Cloud Storage 存储桶并复制图片文件以用于训练 AutoML 图片分类模型。

本教程包含多个页面:

  1. 设置您的项目和环境。

  2. 创建图片分类数据集并导入图片。

  3. 训练 AutoML 图片分类模型。

  4. 评估和分析模型性能。

  5. 将模型部署到端点并发送预测。

  6. 清理您的项目。

每个页面均假定您已经按照本教程中之前页面的说明操作。

须知事项

在使用 Vertex AI 功能之前,完成以下步骤。

  1. In the Google Cloud console, go to the project selector page.

    Go to project selector

  2. Select or create a Google Cloud project.

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

  4. 打开 Cloud Shell。 Cloud Shell 是 Google Cloud 的互动式 shell 环境,可让您通过网络浏览器管理项目和资源。
  5. 转到 Cloud Shell
  6. 在 Cloud Shell 中,将当前项目设置为您的 Google Cloud项目 ID,并将其存储在 projectid shell 变量中:
      gcloud config set project PROJECT_ID &&
      projectid=PROJECT_ID &&
      echo $projectid
    PROJECT_ID 替换为您的项目 ID。您可以在 Google Cloud 控制台中找到项目 ID。如需了解详情,请参阅查找项目 ID
  7. Enable the IAM, Compute Engine, Notebooks, Cloud Storage, and Vertex AI APIs.

    Enable the APIs

  8. Make sure that you have the following role or roles on the project: roles/aiplatform.user, roles/storage.admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 选择项目。
    3. 点击 授予访问权限
    4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

    5. 选择角色列表中,选择一个角色。
    6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
    7. 点击 Save(保存)。
    Vertex AI User (roles/aiplatform.user) IAM 角色提供使用 Vertex AI 中所有资源的权限。借助 Storage Admin (roles/storage.admin) 角色,您可以将文档的训练数据集存储在 Cloud Storage 中。

    后续步骤

    按照本教程的下一页,使用Google Cloud 控制台创建图片分类数据集并导入托管在 Cloud Storage 公共存储分区中的图片。