除了串流處理之外,您也可以選擇批次處理,以便從資料中取得資訊。這個非串流處理模式可讓您建構應用程式,以支援其他媒體類型。
您可以使用特定模型,批次處理儲存在 Cloud Storage 中的圖片檔案。輸出內容會儲存在 Cloud Storage 中。
支援的模型
下列模型支援批次處理:
- 標記辨識工具
- 產品辨識工具
支援的資料類型
本頁說明如何批次處理下列類型的資料:
- 圖片資料
事前準備
- 請參閱本頁所述批次處理作業的支援模型和支援資料類型。
- 如果您使用產品辨識工具模型,請建立
Catalog
和ProductRecognitionIndex
,以便在建立產品辨識工具模型時使用,用於批次處理。或者,請找出要使用的現有產品辨識工具索引或產品辨識工具模型。 - 如果您使用標記辨識工具模型,請按照標記辨識工具模型指南建立模型。
- 如果您使用產品辨識工具模型,請建立
- 建立一或多個 Cloud Storage 值區,用於批次處理輸入和輸出內容。
- 找出支援的檔案,並將這些檔案上傳至 Cloud Storage 輸入值區進行處理。
使用者歷程
如要批次處理圖片資料,請完成下列一般步驟:
啟用 Vertex AI Vision API。
建立支援的處理器 (產品辨識器或標記辨識器)。
建立應用程式。
輸入:新增通用輸入節點,指定要處理的 Cloud Storage 檔案。
處理:新增模型節點。
輸出:新增輸出儲存節點,指定處理後的資料在 Cloud Storage 中的儲存位置。
建立應用程式的批次執行個體,每個執行個體對應至 Cloud Storage 值區輸入位置。
部署應用程式和應用程式執行個體。
批次處理例項完成後,請檢查儲存在 Cloud Storage 中的輸出內容。
批次處理圖片
傳送批次處理要求的步驟會因模型而異。按照目標模型的操作說明,批次處理圖片。
產品辨識器模型
使用這些範例,透過產品辨識工具模型批次處理圖片。
控制台
在 Google Cloud 控制台中建立圖片批次處理要求。
建立新的應用程式
開啟 Vertex AI Vision 資訊主頁的「Applications」分頁。
按一下「Create」按鈕。
輸入應用程式名稱,然後選擇所在區域。
按一下「繼續」。
選擇結帳方式。如要進一步瞭解按使用付費和月結的差異,請參閱定價頁面。
按一下 [建立]。
指定批次處理作業的輸入內容
在圖表應用程式建構工具頁面中,按一下「通用輸入」節點。
在側邊的「通用輸入」窗格中,按一下「選取輸入來源」。
在「選取輸入來源」頁面中,選取
「批次預測」。按一下「繼續」。
在「來源」窗格中,按一下位置挑選器欄位中的「瀏覽」,指出檔案在 Cloud Storage 中的所在位置。
(非必要) 如要指定更多來源,請按一下「新增項目」,然後重複上一個步驟。
按一下「提交」。
新增模型
在圖表應用程式建構工具頁面中,按一下「專用模型」部分的「產品辨識工具」模型節點。
在「產品辨識工具」窗格中,按一下「選取模型」。
選取「
選取現有的產品辨識工具模型」。如果您需要建立新模型或索引,請選取對應的選項來建立資源。
從清單中選擇模型。
按一下 [選取]。
(非必要) 修改可信度門檻。
按一下「套用設定」。
新增輸出目的地
在圖表應用程式建構工具頁面中,按一下「Output」部分的「Cloud Storage」模型節點。
在「Cloud Storage」窗格中,按一下「Browse」,在 Cloud Storage 中選取批次預測輸出目的地。
部署應用程式
- 在圖表應用程式建構工具頁面中,按一下 「Deploy」。
REST 和指令列
請完成下列步驟,傳送圖片批次處理要求。
使用
projects.locations.processors.create
方法建立產品辨識工具模型。這項要求包含
Catalog
和ProductRecognitionIndex
資源的參照項目。如要瞭解如何建立Catalog
和ProductRecognitionIndex
資源,請參閱產品辨識器模型指南。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", } } }'
使用新建立的產品辨識工具模型建立應用程式。這項要求會使用
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'
使用
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'
部署應用程式。
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'
取得應用程式執行個體。這項資訊會告訴您批次處理作業何時完成。
具體來說,
state
欄位會顯示處理完成的時間:"state": "FINISHED"
。執行個體完成後,您就無法修改。您可以使用
projects.locations.applications.instances.list
方法追蹤例項。同樣地,如要從這份清單中移除執行個體,請使用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 和指令列
請完成下列步驟,傳送圖片批次處理要求。
使用
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" } }'
使用新建立的標記辨識工具模型建立應用程式。這項要求會使用
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'
使用
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'
部署應用程式。
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'
取得應用程式執行個體。這項資訊會告訴您批次處理作業何時完成。
具體來說,
state
欄位會顯示處理完成的時間:"state": "FINISHED"
。執行個體完成後,您就無法修改。您可以使用
projects.locations.applications.instances.list
方法追蹤例項。同樣地,如要從這份清單中移除執行個體,請使用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" } }