Vertex AI Vision 是一个由 AI 赋能的平台,可用于注入、分析和存储视频 数据。借助 Vertex AI Vision,您可以构建和部署 AI 应用。您可以利用 Vertex AI Vision 与其他产品组件的集成,构建端到端 Vertex AI Vision 解决方案。
如需开始使用 Vertex AI Vision 平台实现解决方案,请查看以下 Vertex AI Vision 概念和组件:
数据流:表示解决方案中的视频流式传输层。数据流来源可以是实时视频(例如 IP 摄像头)或视频文件(例如 MP4 文件)。
应用:实现数据流与 AI 处理器之间的连接,以便对视频执行机器学习操作。例如,您可以将摄像头画面连接到 AI 模型,以便统计从摄像头前经过的人数。
媒体仓库:将数据流注入的视频存储到 Google Cloud 存储空间。将数据存储到此目标位置后,您可以查询对提取的数据流中的数据使用的 AI 处理器的分析输出和元数据。
目标
本教程介绍了如何执行以下操作:
- 创建入座率统计应用。
- 部署应用以供使用。
- 设置远程机器以流式传输视频。
- 将流式视频提取到应用中的数据流节点。
- 在存储 Vertex AI Vision 的媒体仓库中搜索视频。
费用
在本文档中,您将使用的以下收费组件: Google Cloud
- Vertex AI Vision (Streams - Data ingested, Streams - Data consumed, Models - Occupancy analytics suite, Warehouse - Video storage)
- Compute Engine
您可使用 价格计算器 根据您的预计使用情况来估算费用。
完成本文档中描述的任务后,您可以通过删除所创建的资源来避免继续计费。如需了解详情,请参阅清理。
准备工作
- 登录您的 Google Cloud 账号。 如果您是新手,请创建一个账号来评估我们的产品在实际场景中的表现。 Google Cloud新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Compute Engine and Vision AI APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the following roles to the service account: Vision AI > Vision AI Editor, Compute Engine > Compute Instance Admin (beta), Storage > Storage Object Viewer†.
To grant a role, find the Select a role list, then select the role.
To grant additional roles, click Add another role and add each additional role.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Compute Engine and Vision AI APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the following roles to the service account: Vision AI > Vision AI Editor, Compute Engine > Compute Instance Admin (beta), Storage > Storage Object Viewer†.
To grant a role, find the Select a role list, then select the role.
To grant additional roles, click Add another role and add each additional role.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
† 仅当您从 Cloud Storage 存储桶复制示例视频文件时才需要此角色。
创建入座率统计应用
设置环境后,第一步是创建用于处理数据的应用。 应用可以视为连接以下各项的自动化流水线:
- 数据注入:将视频 Feed 注入到数据流中。
- 数据分析:提取后可以添加 AI 模型。可以对提取的视频信息执行任何计算机视觉操作。
- 数据存储:视频 Feed 的两个版本(原始数据流和 AI 模型处理的数据流)可以存储在媒体仓库中。
在 Google Cloud 控制台中,应用以图表的形式表示。 此外,在 Vertex AI Vision 中,应用图必须至少包含两个节点:一个视频源节点(数据流),以及 至少 一个其他节点(处理模型或输出目标位置)。
创建空应用
您必须先创建一个空应用,然后才能填充应用图表。
控制台
在 Google Cloud 控制台中创建应用。
打开 Vertex AI Vision 信息中心的应用 标签页。
点击加号创建 按钮。
输入
occupancy-count-app作为应用名称,然后选择您的区域。点击创建 。
添加应用组件节点
创建空应用后,您可以将以下三个节点添加到应用图表中:
- 注入节点:注入您创建的 Compute Engine 虚拟机实例发送的数据的数据流资源。
- 处理节点:对提取的数据执行操作的入座率分析模型。
- 存储节点:存储已处理视频的媒体仓库, 同时也是元数据存储区。仓库允许生成有关提取的视频数据的分析 信息,并存储 AI 模型推断出的有关数据的信息。
控制台
在控制台中向应用添加组件节点。
打开 Vertex AI Vision 信息中心的应用 标签页。
在
occupancy-count-app行中,选择 查看图表。系统会将您转至处理流水线的图表可视化界面。
添加数据注入节点
如需添加输入数据流节点,请选择侧边菜单的连接器 部分中的数据流 选项。
在打开的信息流 菜单的来源 部分中,选择 添加信息流。
在添加数据流 菜单中,选择 注册新的 数据流 ,然后添加
occupancy-count-stream作为数据流名称。如需将数据流添加到应用图表,请点击添加数据流 。
添加数据处理节点
如需添加入座率统计模型节点,请选择侧边菜单的专用模型 部分中的入座率分析 选项。
保留默认选择 人员 和 车辆。
添加数据存储节点
如需添加输出目标位置(存储)节点,请选择侧边菜单的 连接器部分中的 Vertex AI Vision 的媒体仓库选项。
在 Vertex AI Vision 的媒体仓库 菜单中,点击 连接仓库。
在连接仓库 菜单中,选择 创建新 仓库。将仓库命名为
occupancy-count-warehouse,并将 TTL 时长保留 14 天。点击创建 按钮以添加仓库。
部署应用以供使用
使用所有必要组件构建端到端应用后,使用应用的最后一步是部署应用。控制台
打开 Vertex AI Vision 信息中心的应用 标签页。
在列表中,选择
occupancy-count-app应用旁边的查看图表 。在应用图表构建器页面中,点击 部署 按钮。
在以下确认对话框中,选择部署 。
部署操作可能需要几分钟才能完成。部署完成后,节点旁边会显示绿色对勾标记。
设置远程机器以流式传输视频
现在,您已部署入座率统计应用,该应用已准备好接收、处理和存储流式数据,您必须将视频数据实际流式传输到应用中。
在本教程中,您将创建一个托管视频的 Compute Engine 虚拟机实例,并从该虚拟机发送流式视频数据。
创建一个 Linux VM
从 Compute Engine 虚拟机实例发送视频的第一步是创建虚拟机实例。
控制台
设置虚拟机环境
虚拟机启动后,您可以使用控制台在浏览器中建立 SSH 连接。建立此连接后,您可以下载 vaictl 命令行工具,以便将视频注入到应用中。
控制台
与虚拟机建立 SSH 连接
在控制台中,进入虚拟机实例 页面。
在您创建的实例行的连接 部分中,点击 SSH 。这会在新的浏览器窗口中打开 SSH 连接。

下载 vaictl 命令行工具
在 SSH-in-browser 窗口中,使用以下命令下载 Vertex AI Vision (
vaictl) 命令行工具:wget https://github.com/google/visionai/releases/download/v0.0.5/visionai_0.0-5_amd64.deb请运行以下命令来安装命令行工具:
sudo apt install ./visionai_0.0-5_amd64.deb您可以运行以下命令来测试安装:
vaictl --help
将视频文件提取到应用中
设置虚拟机环境后,您可以复制示例视频文件,然后使用 vaictl 将视频数据流式传输到入座率统计应用。
SSH-in-browser
将示例视频复制到虚拟机
- 在虚拟机的 SSH-in-browser 窗口中,使用以下
gcloud storage cp命令复制示例视频。替换以下变量:- SOURCE:要使用的视频文件的位置。您可以使用自己的视频文件来源(例如
gs://BUCKET_NAME/FILENAME.mp4),也可以使用以下示例视频之一:
gcloud storage cp SOURCE .
- SOURCE:要使用的视频文件的位置。您可以使用自己的视频文件来源(例如
从虚拟机流式传输视频并将数据注入到应用中
- 如需将此本地视频文件发送到应用输入数据流,请使用以下命令。您必须进行以下变量替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:您的位置 ID。例如,
us-central1。如需了解详情,请参阅 Cloud 位置。 - LOCAL_FILE.EXT:本地视频文件的文件名。
例如,
my-video.mp4。 --loop标志:可选。循环文件数据以模拟 流式传输。
此命令会将视频文件流式传输到数据流。如果您使用
--loop标志,则视频会循环到数据流中,直到您 停止该命令为止:vaictl -p PROJECT_ID \ -l LOCATION_ID \ -c application-cluster-0 \ --service-endpoint visionai.googleapis.com \ send video-file to streams 'occupancy-count-stream' --file-path LOCAL_FILE.EXT --loop
从启动 vaictl 注入操作到视频显示在信息中心内,可能需要大约 100 秒。
数据流提取可用后,您可以在 Vertex AI Vision 信息中心的数据流 标签页中选择 occupancy-count-stream 数据流,以查看视频 Feed。
在存储仓库中搜索视频内容
将视频数据注入到处理应用后,您可以查看分析后的视频数据,并根据入座率分析信息搜索数据。
控制台
打开 Vertex AI Vision 信息中心的仓库 标签页。
在列表中找到
occupancy-count-warehouse仓库,然后点击 查看资产。在人数统计 或车辆数统计 部分中,将最小值 设置为
1,并将最大值 设置为5。如需过滤存储在 Vertex AI Vision 的媒体仓库中的已处理视频数据,请点击搜索 。
在控制台中查看符合搜索条件的存储视频数据。 Google Cloud 视频来源: Elizabeth Mavor(已应用搜索条件)。
清理
为避免因本教程中使用的资源导致您的 Google Cloud 账号产生费用,请删除包含这些资源的项目,或者保留项目但删除各个资源。
删除项目
- 在 Google Cloud 控制台中,前往 管理资源 页面。
- 在项目列表中,选择要删除的项目,然后点击删除。
- 在对话框中输入项目 ID,然后点击 关闭以删除项目。
删除各个资源
删除 Compute Engine 虚拟机实例
- 在 Google Cloud 控制台中,进入 虚拟机实例 页面。
- 选中要删除的实例对应的复选框。
- 如需删除实例,请依次点击 更多操作 和删除,然后按照说明操作。
删除仓库
- 在 Google Cloud 控制台中,进入 仓库 页面。
-
找到
您的
occupancy-count-warehouse仓库。 - 如需删除仓库,请依次点击 操作和删除仓库 ,然后按照说明操作。
删除数据流
- 在 Google Cloud 控制台中,进入 数据流 页面。
-
找到您的
occupancy-count-stream数据流。 - 如需删除数据流,请依次点击 操作 和删除数据流 ,然后按照说明操作。
删除应用
- 在 Google Cloud 控制台中,进入 应用 页面。
-
找到
您的
occupancy-count-app应用。 - 如需删除应用,请依次点击 操作 和删除应用 ,然后按照说明操作。
后续步骤
- 详细了解 Responsible AI 实践。
- 了解可在 构建应用中向应用添加的其他组件。
- 如需了解其他输出存储和处理选项,请参阅 将应用输出连接到数据目标位置 。
- 了解如何在控制台中 搜索仓库数据。
- 探索有关 Google Cloud 的参考架构、图表和最佳实践。 查看我们的 Cloud 架构中心。