本頁說明如何使用 Vertex AI 代管資料集訓練自訂模型。代管資料集具備下列優點:
- 集中管理資料集。
- 建立標籤和多個註解集。
- 使用整合式資料標籤功能,為人工標籤建立工作。
- 追蹤模型沿襲,以便進行管理和疊代開發。
- 使用相同資料集訓練 AutoML 和自訂模型,比較模型成效。
- 生成資料統計資料和視覺化內容。
- 自動將資料拆分為訓練集、測試集和驗證集。
事前準備
如要在訓練應用程式中使用代管資料集,請先建立資料集。您必須在相同地區中建立用於訓練的資料集和訓練管道。您必須使用可用的 Dataset 資源區域。
從訓練應用程式存取資料集
建立自訂訓練管道時,您可以指定訓練應用程式使用 Vertex AI 資料集。
在執行階段,Vertex AI 會在訓練容器中設定下列環境變數,將資料集的中繼資料傳遞至訓練應用程式。
AIP_DATA_FORMAT:資料集匯出格式。可能的值包括:jsonl、csv或bigquery。AIP_TRAINING_DATA_URI:訓練資料的 BigQuery URI,或訓練資料檔案的 Cloud Storage URI。AIP_VALIDATION_DATA_URI:驗證資料的 BigQuery URI,或是驗證資料檔案的 Cloud Storage URI。AIP_TEST_DATA_URI:測試資料的 BigQuery URI 或測試資料檔案的 Cloud Storage URI。
如果資料集的 AIP_DATA_FORMAT 為 jsonl 或 csv,資料 URI 值會參照 Cloud Storage URI,例如 gs://bucket_name/path/training-*。為確保每個資料檔案的大小相對較小,Vertex AI 會將資料集分割成多個檔案。由於訓練、驗證或測試資料可能會分成多個檔案,因此 URI 會以萬用字元格式提供。
進一步瞭解如何使用 Cloud Storage 程式碼範例下載物件。
如果 AIP_DATA_FORMAT 為 bigquery,資料 URI 值會參照 BigQuery URI,例如 bq://project.dataset.table。
資料集格式
請參閱下列各節,進一步瞭解 Vertex AI 在將資料集傳遞至訓練應用程式時,如何格式化資料。
圖片資料集
圖片資料集會以 JSON Lines 格式傳遞至訓練應用程式。 選取資料集目標的對應分頁,進一步瞭解 Vertex AI 如何格式化資料集。
單一標籤分類
匯出單一標籤圖片分類資料集時,Vertex AI 會使用下列可公開存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"imageGcsUri": "gs://bucket/filename.ext",
"classificationAnnotation": {
"displayName": "LABEL",
"annotationResourceLabels": {
"aiplatform.googleapis.com/annotation_set_name": "displayName",
"env": "prod"
}
},
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training/test/validation"
}
}田野筆記:
imageGcsUri:這張圖片的 Cloud Storage URI。annotationResourceLabels:包含任意數量的鍵/值字串組合。Vertex AI 會使用這個欄位指定註解集。dataItemResourceLabels- 包含任意數量的鍵/值字串組合。指定資料項目的機器學習用途,例如訓練、測試或驗證。
JSON Lines 範例
{"imageGcsUri": "gs://bucket/filename1.jpeg", "classificationAnnotation": {"displayName": "daisy"}, "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "test"}}
{"imageGcsUri": "gs://bucket/filename2.gif", "classificationAnnotation": {"displayName": "dandelion"}, "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename3.png", "classificationAnnotation": {"displayName": "roses"}, "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename4.bmp", "classificationAnnotation": {"displayName": "sunflowers"}, "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename5.tiff", "classificationAnnotation": {"displayName": "tulips"}, "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "validation"}}
...多標籤分類
匯出多標籤圖片分類資料集時,Vertex AI 會使用下列公開可存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"imageGcsUri": "gs://bucket/filename.ext",
"classificationAnnotations": [
{
"displayName": "LABEL1",
"annotationResourceLabels": {
"aiplatform.googleapis.com/annotation_set_name":"displayName",
"label_type": "flower_type"
}
},
{
"displayName": "LABEL2",
"annotationResourceLabels": {
"aiplatform.googleapis.com/annotation_set_name":"displayName",
"label_type": "image_shot_type"
}
}
],
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training/test/validation"
}
}田野筆記:
imageGcsUri:這張圖片的 Cloud Storage URI。annotationResourceLabels:包含任意數量的鍵/值字串組合。Vertex AI 會使用這個欄位指定註解集。dataItemResourceLabels- 包含任意數量的鍵/值字串組合。指定資料項目的機器學習用途,例如訓練、測試或驗證。
JSON Lines 範例
{"imageGcsUri": "gs://bucket/filename1.jpeg", "classificationAnnotations": [{"displayName": "daisy"}, {"displayName": "full_shot"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "test"}}
{"imageGcsUri": "gs://bucket/filename2.gif", "classificationAnnotations": [{"displayName": "dandelion"}, {"displayName": "medium_shot"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename3.png", "classificationAnnotations": [{"displayName": "roses"}, {"displayName": "extreme_closeup"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename4.bmp", "classificationAnnotations": [{"displayName": "sunflowers"}, {"displayName": "closeup"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename5.tiff", "classificationAnnotations": [{"displayName": "tulips"}, {"displayName": "extreme_closeup"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "validation"}}
...物件偵測
匯出物件偵測資料集時,Vertex AI 會使用下列公開可存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/dataset/ioformat/image_bounding_box_io_format_1.0.0.yaml
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"imageGcsUri": "gs://bucket/filename.ext",
"boundingBoxAnnotations": [
{
"displayName": "OBJECT1_LABEL",
"xMin": "X_MIN",
"yMin": "Y_MIN",
"xMax": "X_MAX",
"yMax": "Y_MAX",
"annotationResourceLabels": {
"aiplatform.googleapis.com/annotation_set_name": "displayName",
"env": "prod"
}
},
{
"displayName": "OBJECT2_LABEL",
"xMin": "X_MIN",
"yMin": "Y_MIN",
"xMax": "X_MAX",
"yMax": "Y_MAX"
}
],
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "test/train/validation"
}
}田野筆記:
imageGcsUri:這張圖片的 Cloud Storage URI。annotationResourceLabels:包含任意數量的鍵/值字串組合。Vertex AI 會使用這個欄位指定註解集。dataItemResourceLabels- 包含任意數量的鍵/值字串組合。指定資料項目的機器學習用途,例如訓練、測試或驗證。
JSON Lines 範例
{"imageGcsUri": "gs://bucket/filename1.jpeg", "boundingBoxAnnotations": [{"displayName": "Tomato", "xMin": "0.3", "yMin": "0.3", "xMax": "0.7", "yMax": "0.6"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "test"}}
{"imageGcsUri": "gs://bucket/filename2.gif", "boundingBoxAnnotations": [{"displayName": "Tomato", "xMin": "0.8", "yMin": "0.2", "xMax": "1.0", "yMax": "0.4"},{"displayName": "Salad", "xMin": "0.0", "yMin": "0.0", "xMax": "1.0", "yMax": "1.0"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename3.png", "boundingBoxAnnotations": [{"displayName": "Baked goods", "xMin": "0.5", "yMin": "0.7", "xMax": "0.8", "yMax": "0.8"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"imageGcsUri": "gs://bucket/filename4.tiff", "boundingBoxAnnotations": [{"displayName": "Salad", "xMin": "0.1", "yMin": "0.2", "xMax": "0.8", "yMax": "0.9"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "validation"}}
...表格型資料集
Vertex AI 會以 CSV 格式,或以 BigQuery 資料表或檢視區塊的 URI,將表格資料傳遞至訓練應用程式。如要進一步瞭解資料來源格式和規定,請參閱「準備匯入來源」。如要進一步瞭解資料集結構定義,請參閱 Google Cloud 控制台中的資料集。
文字資料集
文字資料集會以 JSON Lines 格式傳遞至訓練應用程式。 選取資料集目標的對應分頁,進一步瞭解 Vertex AI 如何格式化資料集。
單一標籤分類
匯出單一標籤文字分類資料集時,Vertex AI 會使用下列公開可存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"classificationAnnotation": {
"displayName": "label"
},
"textContent": "inline_text",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}
{
"classificationAnnotation": {
"displayName": "label2"
},
"textGcsUri": "gcs_uri_to_file",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}多標籤分類
匯出多標籤文字分類資料集時,Vertex AI 會使用下列公開可存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"classificationAnnotations": [{
"displayName": "label1"
},{
"displayName": "label2"
}],
"textGcsUri": "gcs_uri_to_file",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}
{
"classificationAnnotations": [{
"displayName": "label2"
},{
"displayName": "label3"
}],
"textContent": "inline_text",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}實體擷取
匯出實體擷取資料集時,Vertex AI 會使用下列可公開存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/dataset/ioformat/text_extraction_io_format_1.0.0.yaml.
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"textSegmentAnnotations": [
{
"startOffset":number,
"endOffset":number,
"displayName": "label"
},
...
],
"textContent": "inline_text",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}
{
"textSegmentAnnotations": [
{
"startOffset":number,
"endOffset":number,
"displayName": "label"
},
...
],
"textGcsUri": "gcs_uri_to_file",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}情緒分析
Vertex AI 匯出情緒分析資料集時,會使用下列公開可存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_text_sentiment_1.0.0.yaml
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"sentimentAnnotation": {
"sentiment": number,
"sentimentMax": number
},
"textContent": "inline_text",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}
{
"sentimentAnnotation": {
"sentiment": number,
"sentimentMax": number
},
"textGcsUri": "gcs_uri_to_file",
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "training|test|validation"
}
}影片資料集
影片資料集會以 JSON Lines 格式傳遞至訓練應用程式。 選取資料集目標的對應分頁,進一步瞭解 Vertex AI 如何格式化資料集。
動作識別
匯出動作辨識資料集時,Vertex AI 會使用下列可公開存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/dataset/ioformat/video_action_recognition_io_format_1.0.0.yaml
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"videoGcsUri': "gs://bucket/filename.ext",
"timeSegments": [{
"startTime": "start_time_of_fully_annotated_segment",
"endTime": "end_time_of_segment"}],
"timeSegmentAnnotations": [{
"displayName": "LABEL",
"startTime": "start_time_of_segment",
"endTime": "end_time_of_segment"
}],
"dataItemResourceLabels": {
"ml_use": "train|test"
}
}注意:這裡的時間區段用於計算動作的時間戳記。timeSegmentAnnotations 的 startTime 和 endTime 可以相等,並對應至動作的關鍵影格。
JSON Lines 範例
{"videoGcsUri": "gs://demo/video1.mp4", "timeSegmentAnnotations": [{"displayName": "cartwheel", "startTime": "1.0s", "endTime": "12.0s"}], "dataItemResourceLabels": {"ml_use": "training"}}
{"videoGcsUri": "gs://demo/video2.mp4", "timeSegmentAnnotations": [{"displayName": "swing", "startTime": "4.0s", "endTime": "9.0s"}], "dataItemResourceLabels": {"ml_use": "test"}}
...分類
Vertex AI 會在匯出分類資料集時,使用下列可公開存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/dataset/ioformat/video_classification_io_format_1.0.0.yaml
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"videoGcsUri": "gs://bucket/filename.ext",
"timeSegmentAnnotations": [{
"displayName": "LABEL",
"startTime": "start_time_of_segment",
"endTime": "end_time_of_segment"
}],
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "train|test"
}
}JSON Lines 範例 - 影片分類:
{"videoGcsUri": "gs://demo/video1.mp4", "timeSegmentAnnotations": [{"displayName": "cartwheel", "startTime": "1.0s", "endTime": "12.0s"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{"videoGcsUri": "gs://demo/video2.mp4", "timeSegmentAnnotations": [{"displayName": "swing", "startTime": "4.0s", "endTime": "9.0s"}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "test"}}
...物件追蹤
匯出物件追蹤資料集時,Vertex AI 會使用下列公開可存取的結構定義。這個結構定義會決定資料匯出檔案的格式。結構定義的架構遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/dataset/ioformat/object_tracking_io_format_1.0.0.yaml
匯出資料集中的每個資料項目都採用下列格式。 為了方便閱讀,這個範例包含換行符號。
{
"videoGcsUri": "gs://bucket/filename.ext",
"TemporalBoundingBoxAnnotations": [{
"displayName": "LABEL",
"xMin": "leftmost_coordinate_of_the_bounding box",
"xMax": "rightmost_coordinate_of_the_bounding box",
"yMin": "topmost_coordinate_of_the_bounding box",
"yMax": "bottommost_coordinate_of_the_bounding box",
"timeOffset": "timeframe_object-detected"
"instanceId": "instance_of_object
"annotationResourceLabels": "resource_labels"
}],
"dataItemResourceLabels": {
"aiplatform.googleapis.com/ml_use": "train|test"
}
}JSON Lines 範例
{'videoGcsUri': 'gs://demo-data/video1.mp4', 'temporal_bounding_box_annotations': [{'displayName': 'horse', 'instance_id': '-1', 'time_offset': '4.000000s', 'xMin': '0.668912', 'yMin': '0.560642', 'xMax': '1.000000', 'yMax': '1.000000'}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "training"}}
{'videoGcsUri': 'gs://demo-data/video2.mp4', 'temporal_bounding_box_annotations': [{'displayName': 'horse', 'instance_id': '-1', 'time_offset': '71.000000s', 'xMin': '0.679056', 'yMin': '0.070957', 'xMax': '0.801716', 'yMax': '0.290358'}], "dataItemResourceLabels": {"aiplatform.googleapis.com/ml_use": "test"}}
...後續步驟
- 瞭解如何建立訓練管道,在自訂訓練中使用代管資料集。