下列目標章節包含資料需求、輸入/輸出結構定義檔案,以及結構定義定義的資料匯入檔案格式 (JSON Lines 和 CSV) 相關資訊。
權限
如要使用 Cloud Storage bucket 中的圖片,您必須將 bucket 的 Storage Object Viewer 角色授予 Agent Platform 服務代理。服務代理是由 Google 代管的服務帳戶,Agent Platform 會使用該帳戶代您存取資料。如需更詳細的說明,請參閱「服務代理」。
單一標籤分類
資料條件
- 訓練資料:訓練模型時,系統支援下列圖片格式。 Agent Platform API 會預先處理這些匯入的圖片,然後做為訓練模型的資料。每張圖片的大小上限為 30 MB。
- JPEG
- GIF
- PNG
- BMP
- ICO
- 預測資料:向模型要求預測 (查詢) 時,支援下列圖片格式。檔案大小上限為 1.5 MB。
- JPEG
- GIF
- PNG
- WEBP
- BMP
- TIFF
- ICO
- AutoML 模型已針對現實世界中的物體相片進行最佳化。
- 訓練資料應盡可能接近要預測的資料。舉例來說,如果您的用途涉及模糊和低解析度圖片 (例如監視攝影機拍攝的圖片),訓練資料應由模糊、低解析度的圖片組成。一般來說,您也應考慮為訓練圖片提供多個角度、解析度和背景。
- Gemini Enterprise Agent Platform 模型通常無法預測人類無法指派的標籤。因此,如果人類無法在看過圖片 1 到 2 秒後,就學會指派標籤,模型可能也無法學會。
- 建議每個標籤使用約 1000 張訓練圖片。每個標籤至少要有 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 Lines
每行 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 Lines 範例 - 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
...
多標籤分類
資料條件
- 訓練資料:訓練模型時,系統支援下列圖片格式。 Agent Platform API 會預先處理這些匯入的圖片,然後做為訓練模型的資料。每張圖片的大小上限為 30 MB。
- JPEG
- GIF
- PNG
- BMP
- ICO
- 預測資料:向模型要求預測 (查詢) 時,支援下列圖片格式。檔案大小上限為 1.5 MB。
- JPEG
- GIF
- PNG
- WEBP
- BMP
- TIFF
- ICO
- AutoML 模型已針對現實世界中的物體相片進行最佳化。
- 訓練資料應盡可能接近要預測的資料。舉例來說,如果您的用途涉及模糊和低解析度圖片 (例如監視攝影機拍攝的圖片),訓練資料應由模糊、低解析度的圖片組成。一般來說,您也應考慮為訓練圖片提供多個角度、解析度和背景。
- Gemini Enterprise Agent Platform 模型通常無法預測人類無法指派的標籤。因此,如果人類無法在看過圖片 1 到 2 秒後,就學會指派標籤,模型可能也無法學會。
- 建議每個標籤使用約 1000 張訓練圖片。每個標籤至少要有 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 Lines
每行 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 Lines 範例 - 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
...