clips_at_regular_indices¶
- torchcodec.samplers.clips_at_regular_indices(decoder: VideoDecoder, *, num_clips: int = 1, num_frames_per_clip: int = 1, num_indices_between_frames: int = 1, sampling_range_start: int = 0, sampling_range_end: Optional[int] = None, policy: Literal['repeat_last', 'wrap', 'error'] = 'repeat_last') FrameBatch[原始碼]¶
在規則的(等距)索引處取樣片段。
- 引數:
decoder (VideoDecoder) – 用於從中取樣片段的
VideoDecoder例項。num_clips (int, 可選) – 要返回的 clips 數量。預設為:1。
num_frames_per_clip (int, 可選) – 每個 clip 的幀數。預設為:1。
num_indices_between_frames (int, 可選) – 片段內幀之間的索引數。預設為 1,表示幀是連續的。這有時被稱為“擴張”。
sampling_range_start (int, 可選) – 取樣範圍的開始,它定義了一個片段可能開始的第一個索引。預設為 0,即影片的開頭。
sampling_range_end (int 或 None, 可選) – 取樣範圍的結束,它定義了一個片段可能開始的最後一個索引。此值是排他的,即片段只能在 [
sampling_range_start,sampling_range_end) 中開始。如果為 None(預設),則自動設定該值,以便片段永遠不會超出影片的末尾。例如,如果影片的最後一個有效索引是 99,並且片段跨越 10 幀,則此值設定為 99 - 10 + 1 = 90。接受負值,並且等同於len(video) - val。當片段超出影片末尾時,policy引數定義如何構造此類片段。policy (str, 可選) –
定義如何構造超出影片末尾的片段。以下示例可以更好地說明這一點:假設影片的最後一個有效索引是 99,並且一個片段被取樣為從索引 95 開始,
num_frames_per_clip=5和num_indices_between_frames=2,那麼片段中的幀索引應為 [95, 97, 99, 101, 103]。但 101 和 103 是無效索引,因此policy引數定義瞭如何用有效索引替換這些幀。“repeat_last”:重複片段的最後一幀。我們將得到 [95, 97, 99, 99, 99]。
“wrap”:環繞到片段的開頭。我們將得到 [95, 97, 99, 95, 97]。
“error”:引發錯誤。
預設為“repeat_last”。請注意,當
sampling_range_end=None(預設)時,此 policy 引數不太可能相關。
- 返回:
取樣的片段,作為 5D
FrameBatch。data欄位的形狀為(num_clips,num_frames_per_clips, ...),其中 ... 是 (H, W, C) 或 (C, H, W),具體取決於VideoDecoder的dimension_order引數。pts_seconds和duration_seconds欄位的形狀為(num_clips,num_frames_per_clips)。- 返回型別:
使用
clips_at_regular_indices的示例