以下各節將說明資料需求、結構定義檔案,以及結構定義所定義的資料匯入檔案格式 (JSONL 和 CSV)。
或者,您也可以匯入未標註的影片,然後使用 Google Cloud 控制台標註影片 (請參閱「使用 Google Cloud 控制台標註」)。
資料條件
下列規定適用於用於訓練 AutoML 或自訂訓練模型的資料集。
Vertex AI 支援以下列影片格式,可用於訓練模型或要求預測 (為影片加上註解)。
- .MOV
- .MPEG4
- .MP4
- .AVI
如要在網路控制台中查看影片內容或為影片加上註解,影片必須採用瀏覽器原生支援的格式。由於並非所有瀏覽器都能原生處理 .MOV 或 .AVI 內容,建議您使用 .MPEG4 或 .MP4 影片格式。
檔案大小上限為 50 GB (長度上限為 3 小時)。不支援容器中具有格式錯誤或空白時間戳記的個別影片檔案。
每個資料集的標籤數上限為 1,000。
您可以為匯入檔案中的影片指派「ML_USE」標籤。在訓練期間,您可以選擇使用這些標籤將影片和相應的註解分割成「訓練」或「測試」集。針對影片分類,請注意下列事項:
- 訓練模型時,至少需要兩個不同的類別。例如「新聞」和「MTV」,或「遊戲」和「其他」。
- 請考慮納入與任何已定義的類別都不相符的「None_of_the_above」類別和影片片段。
用於訓練 AutoML 模型的影片資料最佳做法
下列做法適用於用於訓練 AutoML 模型的資料集。
訓練資料應儘可能貼近要用來進行預測的資料。例如,如果您使用的資料樣本含有模糊和低解析的影片 (例如監視攝影機拍攝的影片),則訓練資料應該也要含有模糊和低解析影片。通常,您應該還要考慮為訓練影片提供多個角度、解析度和背景。
Vertex AI 模型通常無法預測人類無法指派的標籤。如果無法訓練人類在觀看影片 1-2 秒後指派標籤,則可能也無法訓練模型這麼做。
最常見標籤適用的影片數量最多比最不常見標籤的影片數多 100 倍時,模型的訓練效果最佳。建議移除使用頻率偏低的標籤。就影片分類而言,每個標籤的建議訓練影片數量約為 1,000 部。每個標籤的影片數量下限為 10 部,進階模型則為 50 部。一般來說,如果一部影片含有多個標籤,每個標籤就需要更多範例才能訓練模型,而且分數結果會更難解讀。
結構定義檔案
建立用於匯入註解的 jsonl 檔案時,請使用下列可公開存取的結構定義檔案。這個結構定義檔案會決定資料輸入檔案的格式。檔案的結構會遵循 OpenAPI 模式測試。
影片分類結構定義檔案:
gs://google-cloud-aiplatform/schema/dataset/ioformat/video_classification_io_format_1.0.0.yaml
完整結構定義檔案
title: VideoClassification description: > Import and export format for importing/exporting videos together with classification annotations with time segment. Can be used in Dataset.import_schema_uri field. type: object required: - videoGcsUri properties: videoGcsUri: type: string description: > A Cloud Storage URI pointing to a video. Up to 50 GB in size and up to 3 hours in duration. Supported file mime types: `video/mp4`, `video/avi`, `video/quicktime`. timeSegmentAnnotations: type: array description: > Multiple classification annotations. Each on a time segment of the video. items: type: object description: Annotation with a time segment on media (e.g., video). properties: displayName: type: string description: > It will be imported as/exported from AnnotationSpec's display name. startTime: type: string description: > The start of the time segment. Expressed as a number of seconds as measured from the start of the video, with "s" appended at the end. Fractions are allowed, up to a microsecond precision. default: 0s endTime: type: string description: > The end of the time segment. Expressed as a number of seconds as measured from the start of the video, with "s" appended at the end. Fractions are allowed, up to a microsecond precision, and "Infinity" is allowed, which corresponds to the end of the video. default: Infinity annotationResourceLabels: description: Resource labels on the Annotation. type: object additionalProperties: type: string dataItemResourceLabels: description: Resource labels on the DataItem. type: object additionalProperties: type: string
輸入檔案
影片分類訓練資料的格式如下。
如要匯入資料,請建立 JSONL 或 CSV 檔案。
JSONL
每行 JSON:
詳情請參閱分類結構定義 (全域) 檔案。
{ "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" } }
JSONL 範例 - 影片分類:
{"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"}} ...
CSV
CSV 中的列格式:
[ML_USE,]VIDEO_URI,LABEL,START,END
資料欄清單
-
ML_USE
(選填)。訓練模型時用於資料分割。請使用「訓練」或「測試」。 VIDEO_URI
:這個欄位包含影片的 Cloud Storage URI。Cloud Storage URI 會區分大小寫。LABEL
. 標籤開頭必須是字母,且只能含有字母、數字和底線。您可以在 CSV 檔案中新增多個資料列,每個資料列識別同一個影片片段,不同的資料列使用不同的標籤,以這種方法為影片指定多個標籤。START,END
:這兩個欄位分別為 START 和 END,分別代表要分析的影片片段開始和結束時間 (以秒為單位)。開始時間必須早於結束時間。這兩個值都不能是負值,且必須在影片的時間範圍內,例如:0.09845,1.36005
。如要使用完整的影片內容,請將開始時間指定為0
,將結束時間指定為影片的完整長度或「inf」,例如0,inf
。
CSV 範例 - 使用單一標籤的分類
同一個影片片段的單一標籤:
TRAINING,gs://YOUR_VIDEO_PATH/vehicle.mp4,mustang,0,5.4 ...
CSV 範例 - 多個標籤:
同一個影片片段的多個標籤:
gs://YOUR_VIDEO_PATH/vehicle.mp4,fiesta,0,8.285 gs://YOUR_VIDEO_PATH/vehicle.mp4,ranger,0,8.285 gs://YOUR_VIDEO_PATH/vehicle.mp4,explorer,0,8.285 ...
CSV 範例 - 不含標籤:
您也可以不在資料檔案中指定任何標籤,直接提供影片。然後,您必須在訓練模型之前使用 Google Cloud 控制台將標籤套用至您的資料。如要進行這項操作,您只須提供影片的 Cloud Storage URI,後面加上三個逗號,如以下範例所示。
gs://YOUR_VIDEO_PATH/vehicle.mp4,,, ...