下列目標部分包含資料需求、輸入/輸出結構定義檔案,以及結構定義所定義的資料匯入檔案格式 (JSON 行 和 CSV)。
單一標籤分類
資料條件
- 訓練資料:訓練模型時支援下列圖片格式。Vertex AI API 預先處理這些匯入的圖片後,就會將這些圖片做為訓練模型的資料。每張圖片的檔案大小上限為 30 MB。
- JPEG
- GIF
- PNG
- BMP
- ICO
- 預測資料:向模型要求 (查詢) 預測時,支援下列圖片格式。檔案大小上限為 1.5 MB。
- JPEG
- GIF
- PNG
- WEBP
- BMP
- TIFF
- ICO
- AutoML 模型已針對真實物件的相片進行最佳化。
- 訓練資料應儘可能貼近要用來進行預測的資料。舉例來說,如果您的用途主要是模糊和低解析度的圖片 (例如監視攝影機拍攝的圖片),則訓練資料也應為模糊和低解析度的圖片。一般來說,您也應考慮為訓練圖片提供多個角度、解析度和背景。
- Vertex AI 模型通常無法預測人類無法指派的標籤。因此,如果無法訓練人類在觀看圖片 1-2 秒後指派標籤,則可能也無法訓練模型這麼做。
- 建議您為每個標籤提供約 1,000 張訓練圖片。每個標籤的影片數量下限為 10 部。一般來說,如果每張圖片有多個標籤,每個標籤就需要更多範例才能訓練模型,而且分數結果會更難解讀。
- 當最常見標籤適用的圖片數量較最少見標籤適用的圖片數量最高多出 100 倍時,即可達到最佳模型訓練效果。建議移除使用頻率非常低的標籤。
- 請考慮納入與任何已定義的標籤都不相符的 None_of_the_above 標籤和圖片。例如,在花朵資料集中,納入品種標籤以外的花朵圖片,並加上 None_of_the_above 的標籤。
訓練 AutoML 模型時使用圖片資料的最佳做法
以下最佳做法適用於使用 AutoML 訓練模型的資料集。
YAML 結構定義檔案
使用下列可公開存取的結構定義檔案,匯入單標籤圖像分類註解。這個結構定義檔案會決定資料輸入檔案的格式。這個檔案的結構會遵循 OpenAPI 結構定義。
gs://google-cloud-aiplatform/schema/dataset/ioformat/image_classification_single_label_io_format_1.0.0.yaml
完整結構定義檔案
title: ImageClassificationSingleLabel description: > Import and export format for importing/exporting images together with single-label classification annotation. Can be used in Dataset.import_schema_uri field. type: object required: - imageGcsUri properties: imageGcsUri: type: string description: > A Cloud Storage URI pointing to an image. Up to 30MB in size. Supported file mime types: `image/jpeg`, `image/gif`, `image/png`, `image/webp`, `image/bmp`, `image/tiff`, `image/vnd.microsoft.icon`. classificationAnnotation: type: object description: Single classification Annotation on the image. properties: displayName: type: string description: > It will be imported as/exported from AnnotationSpec's display name, i.e. the name of the label/class. annotationResourceLabels: description: Resource labels on the Annotation. type: object additionalProperties: type: string dataItemResourceLabels: description: Resource labels on the DataItem. type: object additionalProperties: type: string
輸入檔案
JSON 行
每行 JSON:
{ "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
:唯一的必填欄位。annotationResourceLabels
:可包含任意數量的鍵/值字串組合。系統保留的唯一鍵/值組合如下:- "aiplatform.googleapis.com/annotation_set_name" : "value"
其中 value 是資料集中現有註解集的其中一個顯示名稱。
dataItemResourceLabels
:可包含任意數量的鍵/值字串組合。唯一的系統保留鍵/值組為下列項目,可指定資料項目的機器學習用途集:- "aiplatform.googleapis.com/ml_use" : "training/test/validation"
JSON 行範例 - image_classification_single_label.jsonl
:
{"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"}} ...
CSV
CSV 格式:
[ML_USE],GCS_FILE_PATH,[LABEL]
ML_USE
(選用) - 用於訓練模型時的分割資料用途。使用 TRAINING、TEST 或 VALIDATION。如要進一步瞭解手動分割資料,請參閱「AutoML 模型資料分割作業簡介」。GCS_FILE_PATH
:這個欄位包含圖片的 Cloud Storage URI。Cloud Storage URI 會區分大小寫。LABEL
(選用) - 標籤開頭必須是字母,且只能含有字母、數字和底線。
CSV 範例 - image_classification_single_label.csv
:
test,gs://bucket/filename1.jpeg,daisy training,gs://bucket/filename2.gif,dandelion gs://bucket/filename3.png gs://bucket/filename4.bmp,sunflowers validation,gs://bucket/filename5.tiff,tulips ...
多標籤分類
資料條件
- 訓練資料:訓練模型時支援下列圖片格式。Vertex AI API 預先處理這些匯入的圖片後,就會將這些圖片做為訓練模型的資料。每張圖片的檔案大小上限為 30 MB。
- JPEG
- GIF
- PNG
- BMP
- ICO
- 預測資料:向模型要求 (查詢) 預測時,支援下列圖片格式。檔案大小上限為 1.5 MB。
- JPEG
- GIF
- PNG
- WEBP
- BMP
- TIFF
- ICO
- AutoML 模型已針對真實物件的相片進行最佳化。
- 訓練資料應儘可能貼近要用來進行預測的資料。舉例來說,如果您的用途主要是模糊和低解析度的圖片 (例如監視攝影機拍攝的圖片),則訓練資料也應為模糊和低解析度的圖片。一般來說,您也應考慮為訓練圖片提供多個角度、解析度和背景。
- Vertex AI 模型通常無法預測人類無法指派的標籤。因此,如果無法訓練人類在觀看圖片 1-2 秒後指派標籤,則可能也無法訓練模型這麼做。
- 建議您為每個標籤提供約 1,000 張訓練圖片。每個標籤的影片數量下限為 10 部。一般來說,如果每張圖片有多個標籤,每個標籤就需要更多範例才能訓練模型,而且分數結果會更難解讀。
- 當最常見標籤適用的圖片數量較最少見標籤適用的圖片數量最高多出 100 倍時,即可達到最佳模型訓練效果。建議移除使用頻率非常低的標籤。
- 請考慮納入與任何已定義的標籤都不相符的 None_of_the_above 標籤和圖片。例如,在花朵資料集中,納入品種標籤以外的花朵圖片,並加上 None_of_the_above 的標籤。
訓練 AutoML 模型時使用圖片資料的最佳做法
以下最佳做法適用於使用 AutoML 訓練模型的資料集。
YAML 結構定義檔案
使用下列可公開存取的結構定義檔案,匯入多標籤圖像分類註解。這個結構定義檔案會決定資料輸入檔案的格式。這個檔案的結構會遵循 OpenAPI 結構定義。
完整結構定義檔案
title: ImageClassificationMultiLabel description: > Import and export format for importing/exporting images together with multi-label classification annotations. Can be used in Dataset.import_schema_uri field. type: object required: - imageGcsUri properties: imageGcsUri: type: string description: > A Cloud Storage URI pointing to an image. Up to 30MB in size. Supported file mime types: `image/jpeg`, `image/gif`, `image/png`, `image/webp`, `image/bmp`, `image/tiff`, `image/vnd.microsoft.icon`. classificationAnnotations: type: array description: Multiple classification Annotations on the image. items: type: object description: Classification annotation. properties: displayName: type: string description: > It will be imported as/exported from AnnotationSpec's display name, i.e. the name of the label/class. annotationResourceLabels: description: Resource labels on the Annotation. type: object additionalProperties: type: string dataItemResourceLabels: description: Resource labels on the DataItem. type: object additionalProperties: type: string
輸入檔案
JSON 行
每行 JSON:
{ "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
:唯一的必填欄位。annotationResourceLabels
:可包含任意數量的鍵/值字串組合。系統保留的唯一鍵/值組合如下:- "aiplatform.googleapis.com/annotation_set_name" : "value"
其中 value 是資料集中現有註解集的其中一個顯示名稱。
dataItemResourceLabels
:可包含任意數量的鍵/值字串組合。唯一的系統保留鍵/值組為下列項目,可指定資料項目的機器學習用途集:- "aiplatform.googleapis.com/ml_use" : "training/test/validation"
JSON 行範例 - image_classification_multi_label.jsonl
:
{"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"}} ...
CSV
CSV 格式:
[ML_USE],GCS_FILE_PATH,[LABEL1,LABEL2,...LABELn]
ML_USE
(選用) - 用於訓練模型時的分割資料用途。使用 TRAINING、TEST 或 VALIDATION。如要進一步瞭解手動分割資料,請參閱「AutoML 模型資料分割作業簡介」。GCS_FILE_PATH
:這個欄位包含圖片的 Cloud Storage URI。Cloud Storage URI 會區分大小寫。LABEL
(選用) - 標籤開頭必須是字母,且只能含有字母、數字和底線。
CSV 範例 - image_classification_multi_label.csv
:
test,gs://bucket/filename1.jpeg,daisy,full_shot training,gs://bucket/filename2.gif,dandelion,medium_shot gs://bucket/filename3.png gs://bucket/filename4.bmp,sunflowers,closeup validation,gs://bucket/filename5.tiff,tulips,extreme_closeup ...