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 处理器的分析输出和元数据。
目标
本教程介绍了如何执行以下操作:
- 创建数据输入流资源。
- 开始将视频数据流式传输到此数据流资源。
- 创建空应用。
- 向应用添加节点,以流式传输数据、修改数据和存储数据。
- 部署应用以供您使用。
- 在 Google Cloud 控制台中查看已处理的数据输出。
在开始本教程之前,您必须拥有一个流式视频资源,以便将数据发送到 Vertex AI Vision 应用。此资源可以是本地视频,也可以是 RTSP Feed。此视频数据必须包含人脸,以便示例应用随后可以模糊处理这些数据。
费用
在本文档中,您将使用的以下收费组件: Google Cloud
- Vertex AI Vision (Streams - Data ingested, Streams - Data consumed, Models - Person / face blur, Warehouse - Video storage)
您可使用 价格计算器 根据您的预计使用情况来估算费用。
完成本文档中描述的任务后,您可以通过删除所创建的资源来避免继续计费。如需了解详情,请参阅清理。
准备工作
- 获取流式视频来源的位置,可以是本地位置
(例如
./sample_video.mp4),也可以是实时 RTSP Feed 的 IP 地址(例如rtsp://192.168.1.180:540)。创建 数据流资源后,您需要 此信息才能开始将数据提取到数据流中。 - 登录您的 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 Vision AI API.
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 Vision AI > Vision AI Editor role to the service account.
To grant the role, find the Select a role list, then select Vision AI > Vision AI Editor.
- 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.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
安装 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 Vision AI API.
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 Vision AI > Vision AI Editor role to the service account.
To grant the role, find the Select a role list, then select Vision AI > Vision AI Editor.
- 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.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init - 安装
vaictl工具以将数据注入数据流中 (操作系统:Debian GNU/Linux,CPU 架构:x86_64):- 下载所需的软件包:
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
- 下载所需的软件包:
创建数据流
如需创建流式视频分析应用,您必须先创建并注册流资源。作为接收用户视频数据的资源,在您使用 Vertex AI Vision 构建的任何场景中,都需要使用数据流。控制台
如需在 Google Cloud 控制台中创建新数据流,请按照以下步骤操作。
打开 Vertex AI Vision 信息中心的数据流 标签页。
点击 注册 。
输入
input-stream作为数据流名称,然后选择要在其中创建数据流的区域。点击注册 以创建一个或多个数据流。
将视频注入数据流中
创建数据流资源后,您可以使用 vaictl 命令行工具将视频数据发送到数据流。
IP 摄像头
如果您使用实时 IP 摄像头进行测试,则需要获取 摄像头的 IP 地址。您必须在请求中提供此信息,以及 其他变量替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:您的位置 ID。例如,
us-central1。如需了解详情,请参阅 Cloud 位置。 - RTSP_ADDRESS:您的实时流式传输
协议 (RTSP) Feed 的地址。例如,
rtsp://192.168.1.180:540.
此命令会将 RTSP Feed 发送到数据流中。您必须在可以直接访问 RTSP Feed 的网络中运行此命令。
vaictl -p PROJECT_ID \
-l LOCATION_ID \
-c application-cluster-0 \
--service-endpoint visionai.googleapis.com \
send rtsp to streams input-stream --rtsp-uri RTSP_ADDRESS
如果命令成功运行,您将获得以下输出:
[...] Waiting for long running operation projects/your-project/locations/us-central1/operations/operation-1651364156981-5dde82db7e4a9-dfb17ca5-1051eb20 ⠙ I20220430 21:16:28.024988 211449 gstvaisink.cc:417] cluster-id=application-cluster-0 I20220430 21:16:28.025032 211449 gstvaisink.cc:418] cluster-endpoint=c8khq35ftg78mn61ef50.us-central1.visionai.goog I20220430 21:16:28.025040 211449 gstvaisink.cc:419] event-id=ev-1651364114183255223 I20220430 21:16:28.025048 211449 gstvaisink.cc:420] stream-id=input-stream I20220430 21:16:28.025053 211449 gstvaisink.cc:421] series-id=ev-1651364114183255223--input-stream I20220430 21:16:28.025060 211449 gstvaisink.cc:422] Sending data
本地视频文件
您还可以将视频文件数据发送到数据流,而不是实时视频 Feed。如果您无法访问 IP 摄像头,此选项可能会很有用。
此选项的唯一区别在于 vaictl 命令
参数。您需要传递本地视频文件的路径,而不是传递 IP 摄像头信息。
进行以下变量
替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION_ID:您的位置 ID。例如,
us-central1。了解 详情。 - 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 'input-stream' --file-path LOCAL_FILE.EXT --loop
从启动 vaictl 注入操作到视频显示在信息中心内,可能需要大约 100 秒。
数据流提取可用后,您可以通过选择 input-stream 数据流,在 Vertex AI Vision 信息中心的数据流 标签页中查看视频 Feed。
创建人脸模糊处理应用
创建数据流并将数据注入数据流中后,接下来需要创建 Vertex AI Vision 应用来处理数据。您可以将应用视为连接以下各项的自动化流水线:
- 数据注入:将视频 Feed 注入到数据流中。
- 数据分析:提取完成后,您可以添加 AI 模型。您可以对提取的视频信息执行任何计算机视觉操作。
- 数据存储:您可以将视频 Feed 的两个版本(原始数据流和 AI 模型处理的数据流)存储在媒体仓库中。
在 Google Cloud 控制台中,应用以图表的形式表示。 此外,在 Vertex AI Vision 中,应用图必须至少包含两个节点:一个视频来源节点(数据流),以及至少一个其他节点(处理模型或输出目标位置)。
创建空应用
在填充应用图表之前,您必须先创建一个空应用。控制台
在 Google Cloud 控制台中创建应用。
打开 Vertex AI Vision 信息中心的应用 标签页。
点击 创建 按钮。
输入
person-blur-app作为应用名称,然后选择您的区域。点击创建 。
添加应用组件节点
创建空应用后,您可以向应用图表添加以下三个节点:
- 注入节点:已注入数据的数据流资源。
- 处理节点:对提取的数据执行操作的人脸模糊处理模型。
- 存储节点:存储已处理视频的媒体仓库,同时 也是元数据存储区。仓库允许生成有关提取的视频数据的分析信息,并存储 AI 模型推断出的有关数据的信息。
控制台
在控制台中向应用添加组件节点。
打开 Vertex AI Vision 信息中心的应用 标签页。
在
person-blur-app行中,选择 查看图表。系统会将您转至处理流水线的图表可视化页面。
添加数据注入节点
如需添加输入数据流节点,请选择侧边菜单的连接器 部分中的数据流 选项。
在打开的信息流 菜单的来源 部分中,选择 添加信息流。
在添加数据流 菜单中,选择 从现有数据流中选择 ,然后从数据流 资源列表中选择
person-blur-app。
如需将数据流添加到应用图表,请点击添加数据流 。
添加数据处理节点
如需添加人脸模糊处理模型节点,请选择侧边菜单的常规处理器 部分中的人脸模糊处理 选项。
在打开的“人脸模糊处理”选项菜单中,保留 完全遮挡 处于选中状态,并启用 仅模糊处理人脸选项。

添加数据存储节点
如需添加输出目标位置(存储)节点,请选择侧边菜单的连接器 部分中的 Vertex AI Vision 的媒体仓库 选项。
在 Vertex AI Vision 的媒体仓库 菜单中,点击 连接仓库。
在连接仓库 菜单中,选择 创建新 仓库。将仓库命名为
person-blur-app,并将 TTL 时长保留 14 天。如需添加仓库,请点击创建 。

部署应用
使用所有必要组件构建端到端应用后,使用应用的最后一步是部署应用。控制台
打开 Vertex AI Vision 信息中心的应用 标签页。
在列表中,选择
person-blur-app应用旁边的查看图表 。在应用图表构建器页面中,点击 部署 按钮。
在以下确认对话框中,选择部署 。
部署操作可能需要几分钟才能完成。部署完成后,节点旁边会显示绿色对勾标记。
查看已处理的输出数据
控制台
打开 Vertex AI Vision 信息中心的仓库 标签页。
在列表中找到
person-blur-output-storage仓库,然后点击 查看资产。
清理
为避免因本教程中使用的资源导致您的 Google Cloud 账号产生费用,请删除包含这些资源的项目,或者保留项目但删除各个资源。
删除项目
- 在 Google Cloud 控制台中,前往 管理资源 页面。
- 在项目列表中,选择要删除的项目,然后点击删除。
- 在对话框中输入项目 ID,然后点击 关闭以删除项目。
删除各个资源
删除仓库
- 在 Google Cloud 控制台中,前往 仓库 页面。
-
找到
您的
person-blur-output-storage仓库。 - 如需删除仓库,请依次点击 操作和删除仓库 ,然后按照说明操作。
删除数据流
- 在 Google Cloud 控制台中,前往 数据流 页面。
-
找到您的
input-stream数据流。 - 如需删除数据流,请依次点击 操作 和删除数据流 ,然后按照说明操作。
删除应用
- 在 Google Cloud 控制台中,前往 应用 页面。
-
找到
您的
person-blur-app应用。 - 如需删除应用,请依次点击 操作 和删除应用 ,然后按照说明操作。
后续步骤
- 详细了解 Responsible AI 实践。
- 了解可在 构建应用中向应用添加的其他组件。
- 如需了解其他输出存储和处理选项,请参阅 将应用输出连接到数据目标位置 。
- 了解如何在控制台中 搜索仓库数据。
- 探索有关 Google Cloud 的参考架构、图表和最佳实践。 查看我们的 Cloud 架构中心。