ウェアハウス ストレージを使用して顔のぼかしアプリを作成する


Vertex AI Vision は、動画 データの取り込み、分析、保存に使用できる AI を活用したプラットフォームです。Vertex AI Vision を使用すると、AI アプリケーションを構築してデプロイできます。Vertex AI Vision と他のプロダクト コンポーネントの統合を活用して、エンドツーエンドの Vertex AI Vision ソリューションを構築できます。

Vertex AI Vision プラットフォームを使用してソリューションの実装を開始するには、次の Vertex AI Vision のコンセプトとコンポーネントを確認してください。

  • ストリーム: ソリューションの動画ストリーミング レイヤを表します。ストリーム ソースは、ライブ動画(IP カメラなど)または動画ファイル(MP4 ファイルなど)にできます。

  • アプリケーション: ストリームと AI プロセッサ間の接続を有効にして、動画に対して ML オペレーションを実行します。たとえば、カメラ ストリームを、カメラの前を通り過ぎる人の数をカウントする AI モデルに接続できます。

  • メディア ウェアハウス: ストリームによって取り込まれた動画をGoogle Cloud ストレージに保存します。この宛先にデータを保存すると、取り込まれたストリームのデータで使用される AI プロセッサから分析出力とメタデータをクエリできます。

目標

このチュートリアルでは、次の方法を説明します。

  • データ入力ストリーム リソースを作成します。
  • このストリーム リソースへの動画データのストリーミングを開始します。
  • 空のアプリケーションを作成します。
  • アプリケーションにノードを追加して、データのストリーミング、データの変更、データの保存を行います。
  • アプリをデプロイして使用できるようにします。
  • Google Cloud コンソールで処理済みデータの出力を表示します。

このチュートリアルを開始する前に、Vertex AI Vision アプリにデータを送信するストリーミング動画リソースが必要です。このリソースは、ローカル動画または RTSP フィードのいずれかになります。この動画データには、サンプルアプリでぼかし処理できる人間の顔が含まれている必要があります。

料金

このドキュメントでは、課金対象である次の Google Cloudコンポーネントを使用します。

  • Vertex AI Vision (Streams - Data ingested, Streams - Data consumed, Models - Person / face blur, Warehouse - Video storage)

料金計算ツールを使うと、予想使用量に基づいて費用の見積もりを生成できます。

新規の Google Cloud ユーザーは無料トライアルをご利用いただける場合があります。

このドキュメントに記載されているタスクの完了後、作成したリソースを削除すると、それ以上の請求は発生しません。詳細については、クリーンアップをご覧ください。

始める前に

  1. ストリーミング動画ソースの場所(ローカル(./sample_video.mp4 など)またはライブ RTSP フィードの IP アドレス(rtsp://192.168.1.180:540 など))を取得します。ストリーム リソースを作成した後、ストリームへのデータの取り込みを開始するには、この情報が必要です。
  2. 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.
  3. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  4. Make sure that billing is enabled for your Google Cloud project.

  5. Enable the Vision AI API.

    Enable the API

  6. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. 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.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  7. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  8. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to 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.

  9. Install the Google Cloud CLI.

  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  13. Make sure that billing is enabled for your Google Cloud project.

  14. Enable the Vision AI API.

    Enable the API

  15. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. 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.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  16. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  17. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to 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.

  18. Install the Google Cloud CLI.

  19. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  20. To initialize the gcloud CLI, run the following command:

    gcloud init
  21. vaictl ツールをインストールしてデータをストリームに取り込む(OS: Debian GNU/Linux、CPU アーキテクチャ: x86_64):
    1. 必要なパッケージをダウンロードします。
      wget https://github.com/google/visionai/releases/download/v0.0.5/visionai_0.0-5_amd64.deb
    2. パッケージをダウンロードしたら、ファイルをダウンロードしたディレクトリで次のコマンドを実行します。
      sudo apt install ./visionai_0.0-5_amd64.deb
    3. インストールを確認します。
      vaictl --help

ストリームの作成

ストリーミング動画分析アプリを作成するには、まずストリーム リソースを作成して登録する必要があります。ユーザーから動画データを受け取るリソースとして、Vertex AI Vision を使用して構築するシナリオではストリームが必要です。

コンソール

Google Cloud コンソールで新しいストリームを作成する手順は次のとおりです。

  1. Vertex AI Vision ダッシュボードの [ストリーム] タブを開きます。

    [ストリーム] タブに移動

  2. [登録] をクリックします。

  3. ストリーム名として input-stream を入力し、ストリームを作成するリージョンを選択します。

  4. [登録] をクリックして、1 つ以上のストリームを作成します。

    UI でストリーム オプションを登録する

動画をストリームに取り込む

ストリーム リソースを作成したら、vaictl コマンドライン ツールを使用して動画データをストリームに送信できます。

IP カメラ

ライブ IP カメラを使用してテストする場合は、カメラの IP アドレスを取得する必要があります。この情報は、他の変数置換とともにリクエストで指定する必要があります。

  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • LOCATION_ID: ロケーション ID。例: us-central1。詳細については、クラウドのロケーションをご覧ください。
  • RTSP_ADDRESS: リアルタイム ストリーミング プロトコル(RTSP)フィードのアドレス。例: rtsp://192.168.1.180:540

このコマンドは、RTSP フィードをストリームに送信します。このコマンドは、RTSP フィードに直接アクセスできるネットワークで実行する必要があります。

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

ローカル動画ファイル

ライブ動画フィードの代わりに、動画ファイルデータをストリームに送信することもできます。このオプションは、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 秒かかることがあります。

ストリームの取り込みが完了すると、Vertex AI Vision ダッシュボードの [ストリーム] タブで input-stream ストリームを選択して、動画フィードを確認できます。

[ストリーム] タブに移動

UI でライブ動画がストリーミングされている様子
Google Cloud コンソールでストリームに取り込まれる動画のライブビュー。動画クレジット: PexelsTima Miroshnichenko(ピクセル化を追加)。

顔のぼかしアプリケーションを作成する

ストリームを作成してストリームにデータを取り込んだら、データを処理する Vertex AI Vision アプリを作成します。アプリは、次のものを接続する自動化されたパイプラインと考えることができます。

  • データの取り込み: 動画フィードがストリームに取り込まれます。
  • データ分析: 取り込み後に AI モデルを追加できます。取り込まれた動画情報に対して、任意のコンピュータ ビジョン オペレーションを実行できます。
  • データ ストレージ: 2 つのバージョンの動画フィード(元のストリームと AI モデルで処理されたストリーム)をメディア ウェアハウスに保存できます。

Google Cloud コンソールでは、アプリはグラフとして表されます。また、Vertex AI Vision では、アプリグラフに少なくとも 2 つのノード(動画ソースノード(ストリーム)と、少なくとも 1 つのノード(処理モデルまたは出力先))が必要です。

空のアプリケーションを作成する

アプリグラフにデータを入力する前に、まず空のアプリを作成する必要があります。

コンソール

Google Cloud コンソールでアプリを作成します。

  1. Vertex AI Vision ダッシュボードの [アプリケーション] タブを開きます。

    [アプリケーション] タブに移動

  2. [作成] ボタンをクリックします。

  3. アプリ名として「person-blur-app」と入力し、地域を選択します。

  4. [作成] をクリックします。

    UI の [新しいアプリを作成] ダイアログ

アプリ コンポーネント ノードを追加する

空のアプリケーションを作成したら、次の 3 つのノードをアプリグラフに追加できます。

  1. 取り込みノード: データをすでに取り込んでいるストリーム リソース。
  2. 処理ノード: 取り込まれたデータに対して動作する人物ぼかしモデル。
  3. ストレージ ノード: 処理済みの動画を保存し、メタデータ ストアとしても機能するメディア ウェアハウス。このウェアハウスでは、取り込まれた動画データに関する分析情報を生成できるほか、AI モデルによってデータから推測された情報も保存できます。

コンソール

コンソールでアプリにコンポーネント ノードを追加します。

  1. Vertex AI Vision ダッシュボードの [アプリケーション] タブを開きます。

    [アプリケーション] タブに移動

  2. person-blur-app 行で、グラフを表示を選択します。これで、処理パイプラインのグラフ ビジュアリゼーションが表示されます。

データ取り込みノードを追加する

  1. 入力ストリーム ノードを追加するには、サイドメニューの [コネクタ] セクションで [ストリーム] オプションを選択します。

  2. [ストリーム] メニューの [ソース] セクションで、[ストリームを追加] を選択します。

  3. [ストリームを追加] メニューで、 [既存のストリームから選択] を選択し、ストリーム リソースのリストから person-blur-app を選択します。

    UI にストリーム メニューを追加

  4. ストリームをアプリグラフに追加するには、[ストリームを追加] をクリックします。

データ処理ノードを追加する

  1. 人物ぼかしモデルノードを追加するには、サイドメニューの [一般的なプロセッサ] セクションで [人物ぼかし] オプションを選択します。

  2. 表示された [人物のぼかし] オプション メニューで、完全に隠す を選択したまま、顔のみをぼかす オプションを有効にします。

    UI に顔のぼかしモデルを追加

データ ストレージ ノードを追加する

  1. 出力先(ストレージ)ノードを追加するには、サイドメニューの [コネクタ] セクションで [Vertex AI Vision の Media Warehouse] オプションを選択します。

  2. [Vertex AI Vision のメディア ウェアハウス] メニューで、[ウェアハウスを接続] をクリックします。

  3. [ウェアハウスを接続] メニューで、[新しいウェアハウスを作成] を選択します。ウェアハウスに person-blur-app という名前を付け、TTL の期間を 14 日のままにします。

  4. ウェアハウスを追加するには、[作成] をクリックします。

    UI でウェアハウス ノードを追加する

アプリケーションをデプロイする

必要なコンポーネントをすべて使用してエンドツーエンドのアプリを構築したら、アプリを使用するための最後のステップとして、アプリをデプロイします。

コンソール

  1. Vertex AI Vision ダッシュボードの [アプリケーション] タブを開きます。

    [アプリケーション] タブに移動

  2. リスト内の person-blur-app アプリの横にある [グラフを表示] を選択します。

  3. アプリケーション グラフ ビルダーのページで、 [デプロイ] ボタンをクリックします。

  4. 次の確認ダイアログで、[デプロイ] を選択します。

    デプロイ オペレーションが完了するまでに数分かかることがあります。デプロイが完了すると、ノードの横に緑色のチェックマークが表示されます。

    UI にデプロイされたアプリ

処理された出力データを表示する

コンソール

  1. Vertex AI Vision ダッシュボードの [ウェアハウス] タブを開きます。

    [ウェアハウス] タブに移動

  2. リストで person-blur-output-storage ウェアハウスを見つけて、[アセットを表示] をクリックします。

    UI でアプリの出力を表示する

クリーンアップ

このチュートリアルで使用したリソースについて、Google Cloud アカウントに課金されないようにするには、リソースを含むプロジェクトを削除するか、プロジェクトを維持して個々のリソースを削除します。

プロジェクトの削除

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

リソースを個別に削除する

ウェアハウスを削除する

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

    Go to the Warehouses tab

  2. Locate your person-blur-output-storage warehouse.
  3. To delete the warehouse, click Actions, click Delete warehouse, and then follow the instructions.

ストリームを削除する

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

    Go to the Streams tab

  2. Locate your input-stream stream.
  3. To delete the stream, click Actions, click Delete stream, and then follow the instructions.

アプリを削除する

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

    Go to the Applications tab

  2. Locate your person-blur-app app.
  3. To delete the app, click Actions, click Delete application, and then follow the instructions.

次のステップ