画像バッチ処理

ストリーミング処理に加えて、データから情報を取得する方法としてバッチ処理を選択することもできます。この非ストリーミング処理モードを使用すると、他のメディアタイプをサポートするアプリケーションを構築できます。

選択したモデルを使用して、Cloud Storage に保存されている画像ファイルをバッチ処理できます。 出力は Cloud Storage に保存されます。

サポートされているモデル

次のモデルはバッチ処理をサポートしています。

  • タグ認識ツール
  • 商品認識

サポートされるデータタイプ

このページでは、次のタイプのデータをバッチ処理する方法について説明します。

  • 画像データ

始める前に

ユーザー ジャーニー

画像データをバッチ処理する一般的な手順は次のとおりです。

  1. Gemini Enterprise Agent Platform Vision API を有効にします。

  2. サポートされているプロセッサ(商品認識またはタグ認識ツール)を作成します。

  3. アプリケーションを作成します。

    1. 入力: Cloud Storage で処理するファイルを指定するユニバーサル入力ノードを追加します。

    2. 処理: モデルノードを追加します。

    3. 出力: 処理されたデータが Cloud Storage に保存される場所を指定する出力ストレージ ノードを追加します。

  4. アプリのバッチ インスタンスを作成します。各インスタンスは Cloud Storage バケットの入力ロケーションに対応します。

  5. アプリとアプリ インスタンスをデプロイします。

  6. バッチ処理インスタンスが完了したら、Cloud Storage に保存されている出力を確認します。

画像をバッチ処理する

バッチ処理リクエストを送信する手順は、モデルによって異なります。ターゲット モデルの手順に沿って画像をバッチ処理します。

商品認識モデル

次のサンプルを使用して、商品認識モデルで画像をバッチ処理します。

コンソール

コンソールで画像バッチ処理リクエストを作成します。 Google Cloud

新しいアプリケーションを作成する

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

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

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

  3. アプリ名を入力し、リージョンを選択します。

  4. [続行] をクリックします。

  5. お支払い方法を選択します。従量課金制 と月額課金の違いについては、料金ページをご覧ください。

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

バッチ処理の入力を指定する

  1. グラフアプリビルダー ページで、[ユニバーサル入力] ノードをクリックします。

  2. サイドの [ユニバーサル入力] ペインで、[入力ソースを選択] をクリックします。

  3. [**入力ソースを選択**] ページで、 [**バッチ予測**] を選択します。

  4. [続行] をクリックします。

  5. [ソース] ペインのロケーション ピッカー フィールドで [参照] をクリックして、Cloud Storage 内のファイルの場所を指定します。

  6. 省略可。ソースを追加するには、[アイテムを追加] をクリックして、前の手順を繰り返します。

  7. [送信] をクリックします。

モデルを追加する

  1. グラフアプリビルダー ページの [特殊モデル] セクションで、[商品認識] モデルノードをクリックします。

  2. [商品認識] ペインで、[モデルを選択] をクリックします。

  3. [**既存の商品認識モデルを選択**] を選択します。

    新しいモデルまたはインデックスを作成する必要がある場合は、対応するオプションを選択してリソースを作成します。

  4. リストからモデルを選択します。

  5. [選択] をクリックします。

  6. 省略可。[信頼度しきい値] を変更します。

  7. [設定を適用] をクリックします。

出力先を追加する

  1. グラフアプリビルダー ページの [出力] セクションで、[Cloud Storage] モデルノードをクリックします。

  2. [Cloud Storage] ペインで [参照] をクリックして、Cloud Storage でバッチ予測の出力先を選択します。

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

  1. グラフアプリビルダー ページで、 [Deploy] をクリックします。

REST とコマンドライン

画像バッチ処理リクエストを送信する手順は次のとおりです。

  1. projects.locations.processors.create メソッドを使用して、商品認識モデルを作成します。

    このリクエストには、Catalog リソースと ProductRecognitionIndex リソースへの参照が含まれています。 CatalogProductRecognitionIndex リソースの作成については、商品認識モデルガイドをご覧ください。

    curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json" \
     https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/processors?processor_id=product-recognition-model1 \
     -d '{
       "display_name": "DISPLAY_NAME",
       "model_type": PRODUCT_RECOGNIZER,
       "custom_processor_source_info": {
         "source_type": PRODUCT_RECOGNIZER,
         "product_recognizer_artifact": {
           "retail_product_recognition_index":"projects/PROJECT_ID/locations/LOCATION_ID/retailCatalogs/CATALOG_ID/retailProductRecognitionIndexes/INDEX_ID",
         }
       }
     }'
    
  2. 新しく作成した商品認識モデルを使用してアプリケーションを作成します。 このリクエストでは、 projects.locations.applications.create メソッドを使用します。

    リクエストの本文app.json):

    {
      "applicationConfigs": {
        "nodes": [
          {
            "displayName": "Universal Input",
            "name": "universal-input-0",
            "processor": "builtin:universal-input"
          },
          {
            "displayName": "Product Recognition",
            "name": "product-recognition",
            "nodeConfig": {
              "product_recognizer_config": {
                "recognition_confidence_threshold": 0.75
              }
            },
            "parents": [
              {
                "parentNode": "universal-input-0"
              }
            ],
            "processor": "projects/PROJECT_ID/locations/LOCATION_ID/processors/product-recognition-model1"
          },
          {
            "displayName": "Storage output",
            "name": "gcs-output",
            "nodeConfig": {
              "gcs_output_config": {
                "gcs_path":"gs://product_recognizer_app_output"
              }
            },
            "parents": [
              {
                "parentNode": "product-recognition"
              }
            ],
            "processor": "builtin:gcs-output"
          }
        ]
      }
    }
    

    リクエスト:

    curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      -d @app.json  \
      'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications?application_id=product-recognition-app'
    
  3. projects.locations.applications.createApplicationInstances メソッドを使用して、アプリケーションのインスタンスを作成します。

    リクエストの本文instances.json):

     {
       "applicationInstances": [
         {
           "instance": { 
             "instanceType": "BATCH_PREDICTION",
             "inputResources": [
               {
                 "consumerNode": "universal-input-0",
                 "dataType": "IMAGE",
                 "inputResource": "gs://product_recognition_input"
               }
             ]
           },
           "instanceId": "instance1"
         },
         {
           "instance": { 
             "instanceType":"BATCH_PREDICTION",
             "inputResources": [
               {
                 "consumerNode": "universal-input-0",
                 "dataType": "IMAGE",
                 "inputResource": "gs://product_recognition_input2"
               }
             ]
           },
           "instanceId": "instance2"
         }
       ]
     }
    

    リクエスト:

    curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      -d @instances.json \
      'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications/product-recognition-app:createApplicationInstances'
    
  4. アプリケーションをデプロイします。

     curl -X POST \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json" \
       -d '{}' \
       'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications/product-recognition-app:deploy'
    
  5. アプリ インスタンスを取得します。この情報から、バッチ処理が完了したタイミングを確認できます。

    特に、state フィールドには、処理が 完了したタイミングが"state": "FINISHED" と表示されます。インスタンスが完了すると、変更できなくなります。

    projects.locations.applications.instances.list メソッド を使用して、インスタンスを追跡できます。同様に、このリストからインスタンスを削除するには、 the projects.locations.applications.deleteApplicationInstances メソッドを使用します。

    リクエスト:

     curl -X GET \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json"  \
       'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications/product-recognition-app/instances'
    

    レスポンスの例:

     {
       "instances": [
         {
           "name": "projects/PROJECT_ID/locations/LOCATION_ID/applications/product-recognition-app/instances/instance1",
           "createTime": "2023-03-30T18:30:51.991004265Z",
           "inputResources": [
             {
               "inputResource": "gs://product_recognition_input",
               "consumerNode": "universal-input-0",
               "dataType": "IMAGE"
             }
           ],
           "outputResources": [
             {
               "outputResource": "gs://product_recognition_output/instance1",
               "producerNode": "product-recognition",
               "autogen": true
             }
           ],
           "updateTime": "2023-04-18T04:58:18.592092259Z",
           "state": "FINISHED",
           "instanceType": "BATCH_PREDICTION"
         }
     }
    

タグ認識ツールモデル

次のサンプルを使用して、タグ認識ツールモデルで画像をバッチ処理します。

REST とコマンドライン

画像バッチ処理リクエストを送信する手順は次のとおりです。

  1. projects.locations.processors.create メソッドを使用して、タグ認識ツールモデルを作成します。

    これには、Vertex AI プラットフォーム(vertex_model)でホストされている元のモデルのリソース名を指定する必要があります。

    curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json" \
     https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/processors?processor_id=tag-recognition-model1 \
     -d '{
       "display_name": "DISPLAY_NAME",
       "model_type": TAG_RECOGNIZER,
       "custom_processor_source_info": {
         "source_type": VERTEX_AUTOML,
         "vertex_model": "projects/PROJECT_ID/locations/LOCATION_ID/models/MODEL_ID"
       }
     }'
    
  2. 新しく作成したタグ認識ツールモデルを使用してアプリケーションを作成します。 このリクエストでは、 projects.locations.applications.create メソッドを使用します。

    リクエストの本文app.json):

     {
       "applicationConfigs": {
         "nodes": [
           {
             "displayName": "Universal Input",
             "name": "universal-input-0",
             "processor": "builtin:universal-input"
           },
           {
             "displayName": "Tag Recognition",
             "name": "tag-recognition",
             "nodeConfig": {
               "tag_recognizer_config": {
                 "tag_parsing_config": {
                   "entity_parsing_configs": [
                     {
                       "entity_class": "price",
                       "regex": "\\$\\d+\\.\\d{2}",
                       "entity_matching_strategy": "MAX_OVERLAP_AREA"
                     }
                   ]
                 },
                 "entity_detection_confidence_threshold": 0.0
               }
             },
             "parents": [
               {
                 "parentNode": "universal-input-0"
               }
             ],
             "processor": "projects/PROJECT_ID/locations/LOCATION_ID/processors/tag-recognition-model1"
           },
           {
             "displayName": "Storage output",
             "name": "gcs-output",
             "nodeConfig": {
               "gcs_output_config": {
                 "gcs_path": "gs://tag_recognizer_app_output"
               }
             },
             "parents": [
               {
                 "parentNode": "tag-recognition"
               }
             ],
             "processor": "builtin:gcs-output"
           }
         ]
       }
     }
    

    リクエスト:

    curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      -d @app.json  \
      'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications?application_id=tag-recognition-app'
    
  3. projects.locations.applications.createApplicationInstances メソッドを使用して、アプリケーションのインスタンスを作成します。

    リクエストの本文instances.json):

     {
       "applicationInstances": [
         {
           "instance": { 
             "instanceType": "BATCH_PREDICTION",
             "inputResources": [
               {
                 "consumerNode": "universal-input-0",
                 "dataType": "IMAGE",
                 "inputResource": "gs://tag_recognition_input"
               }
             ]
           },
           "instanceId": "instance1"
         },
         {
           "instance": { 
             "instanceType":"BATCH_PREDICTION",
             "inputResources": [
               {
                 "consumerNode": "universal-input-0",
                 "dataType": "IMAGE",
                 "inputResource": "gs://tag_recognition_input2"
               }
             ]
           },
           "instanceId": "instance2"
         }
       ]
     }
    

    リクエスト:

    curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      -d @instances.json \
      'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications/tag-recognition-app:createApplicationInstances'
    
  4. アプリケーションをデプロイします。

     curl -X POST \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json" \
       -d '{}' \
       'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications/tag-recognition-app:deploy'
    
  5. アプリ インスタンスを取得します。この情報から、バッチ処理が完了したタイミングを確認できます。

    特に、state フィールドには、処理が 完了したタイミングが"state": "FINISHED" と表示されます。インスタンスが完了すると、変更できなくなります。

    projects.locations.applications.instances.list メソッド を使用して、インスタンスを追跡できます。同様に、このリストからインスタンスを削除するには、 the projects.locations.applications.deleteApplicationInstances メソッドを使用します。

    リクエスト:

     curl -X GET \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json"  \
       'https://visionai.googleapis.com/v1alpha1/projects/PROJECT_ID/locations/LOCATION_ID/applications/tag-recognition-app/instances'
    

    レスポンスの例:

     {
       "instances": [
         {
           "name": "projects/PROJECT_ID/locations/LOCATION_ID/applications/tag-recognition-app/instances/instance1",
           "createTime": "2023-03-30T18:30:51.991004265Z",
           "inputResources": [
             {
               "inputResource": "gs://tag_recognition_input",
               "consumerNode": "universal-input-0",
               "dataType": "IMAGE"
             }
           ],
           "outputResources": [
             {
               "outputResource": "gs://tag_recognition_output/instance1",
               "producerNode": "tag-recognition",
               "autogen": true
             }
           ],
           "updateTime": "2023-04-18T04:58:18.592092259Z",
           "state": "FINISHED",
           "instanceType": "BATCH_PREDICTION"
         }
     }