本頁面說明如何準備影片訓練資料,以便在 Vertex AI 資料集中使用,訓練影片動作識別模型。
以下各節將說明資料需求、結構定義檔案,以及結構定義所定義的資料匯入檔案格式 (JSONL 和 CSV)。
或者,您也可以匯入未標註的影片,然後使用 Google Cloud 控制台標註影片 (請參閱「使用 Google Cloud 控制台標註」)。
資料條件
下列規定適用於用於訓練 AutoML 或自訂訓練模型的資料集。
Vertex AI 支援以下列影片格式,可用於訓練模型或要求預測 (為影片加上註解)。
- .MOV
- .MPEG4
- .MP4
- .AVI
如要在網路控制台中查看影片內容或為影片加上註解,影片必須採用瀏覽器原生支援的格式。由於並非所有瀏覽器都能原生處理 .MOV 或 .AVI 內容,建議您使用 .MPEG4 或 .MP4 影片格式。
檔案大小上限為 50 GB (長度上限為 3 小時)。不支援容器中具有格式錯誤或空白時間戳記的個別影片檔案。
每個資料集的標籤數上限為 1,000。
您可以為匯入檔案中的影片指派「ML_USE」標籤。在訓練期間,您可以選擇使用這些標籤將影片和相應的註解分割成「訓練」或「測試」集。就動作辨識而言,使用 VAR 標記控制台時有限制,也就是說,如果要使用標記工具標記動作,就必須標記該影片中的所有動作。
用於訓練 AutoML 模型的影片資料最佳做法
下列做法適用於用於訓練 AutoML 模型的資料集。
訓練資料應儘可能貼近要用來進行預測的資料。例如,如果您使用的資料樣本含有模糊和低解析的影片 (例如監視攝影機拍攝的影片),則訓練資料應該也要含有模糊和低解析影片。通常,您應該還要考慮為訓練影片提供多個角度、解析度和背景。
Vertex AI 模型通常無法預測人類無法指派的標籤。如果無法訓練人類在觀看影片 1-2 秒後指派標籤,則可能也無法訓練模型這麼做。
最常見標籤適用的影片數量最多比最不常見標籤的影片數多 100 倍時,模型的訓練效果最佳。建議移除使用頻率偏低的標籤。針對動作辨識,請注意下列事項:
- 建議每個標籤提供 100 個以上的訓練影片影格。
- 如果是解析度遠大於 1024 x 1024 像素的視訊窗格,Vertex AI 在進行窗格正規化程序時,可能會造成一些影像失真。
結構定義檔案
建立用於匯入註解的 jsonl 檔案時,請使用下列可公開存取的結構定義檔。這個結構定義檔案會決定資料輸入檔案的格式。檔案結構遵循 OpenAPI 架構測試。
動作辨識結構定義檔案:
gs://google-cloud-aiplatform/schema/dataset/ioformat/video_action_recognition_io_format_1.0.0.yaml
完整結構定義檔案
title: VideoActionRecognition description: > Import and export format for importing/exporting videos together with action recognition 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`. timeSegments: type: array description: Multiple fully-labeled segments. items: type: object description: A time period inside the video. properties: 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 timeSegmentAnnotations: type: array description: > Multiple action recognition 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 means 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. Overrides values set in ImportDataConfig at import time. Can set a user-defined label or the predefined `aiplatform.googleapis.com/ml_use` label, which is used to determine the data split and can be set to `training` and `test`. type: object additionalProperties: type: string
輸入檔案
影片動作辨識訓練資料的格式如下。
如要匯入資料,請建立 JSONL 或 CSV 檔案。
JSONL
每行 JSON:
詳情請參閱 動作識別 YAML 檔案。
注意:此處的時段用於計算動作的時間戳記。timeSegmentAnnotations
的 startTime
和 endTime
可以相等,並對應至動作的關鍵影格。
{ "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" } }
JSONL 範例 - 影片動作辨識:
{"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"}} ...
CSV
資料欄清單- 驗證資料(選填)
TRAINING
,TEST
規格。 - 要分類或註解的內容。這個欄位含有影片的 Cloud Storage URI。Cloud Storage URI 會區分大小寫。
- 識別影片分類方法的標籤。標籤開頭必須是字母,且只能含有字母、數字和底線。您可以在 CSV 檔案中新增多個資料列,每個資料列識別同一個影片片段,不同的資料列使用不同的標籤,以這種方法為影片指定多個標籤。
- 影片片段的開始和結束時間。這是兩個以半形逗號分隔的欄位,識別要分析的影片片段的開始和結束時間 (以秒為單位)。開始時間必須早於結束時間。這兩個值都不能是負值,且必須在影片的時間範圍內,例如
0.09845,1.3600555
,其中第一個值 (0.09845) 是開始時間,第二個值 (1.3600555) 則是您要標示的影片片段結束時間。如要使用完整的影片內容,請將開始時間指定為0
,將結束時間指定為影片的完整長度或「inf」。例如:0,inf
。 - 註解:註解是含有影格時間戳記或時間片段的標籤。
每個資料列都必須是下列其中一種:
VIDEO_URI, TIME_SEGMENT_START, TIME_SEGMENT_END, LABEL, ANNOTATION_FRAME_TIMESTAMP
VIDEO_URI, , , LABEL, ANNOTATION_FRAME_TIMESTAMP
VIDEO_URI, TIME_SEGMENT_START, TIME_SEGMENT_END, LABEL, ANNOTATION_SEGMENT_START, ANNOTATION_SEGMENT_END
VIDEO_URI, , , LABEL, ANNOTATION_SEGMENT_START, ANNOTATION_SEGMENT_END
以下提供一些範例:
標記兩個不同時間點的動作:
gs://folder/video1.avi,kick,12.90,,
gs://folder/video1.avi,catch,19.65,,
這兩個時間範圍內沒有任何相關動作。注意:最後一列表示已標示完整的區隔可能不含任何動作。
gs://folder/video1.avi,,,10.0,20.0
gs://folder/video1.avi,,,25.0,40.0
訓練資料至少需帶有一個標籤和一個完整標註的片段。
同樣地,您無需指定驗證資料即可驗證已訓練模型的結果。Vertex AI 會將指定用於訓練的資料列自動分成訓練和驗證資料。80% 用於訓練,20% 用於驗證。
將內容儲存為 Cloud Storage 值區中的 CSV 檔案。