快捷方式

clips_at_random_indices

torchcodec.samplers.clips_at_random_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[原始碼]

在隨機索引處取樣 clips

引數:
  • decoder (VideoDecoder) – 要從中取樣 clips 的 VideoDecoder 例項。

  • num_clips (int, 可選) – 要返回的 clips 數量。預設為:1。

  • num_frames_per_clip (int, 可選) – 每個 clip 的幀數。預設為:1。

  • num_indices_between_frames (int, 可選) – clip *內* 幀之間的索引數量。預設為:1,表示幀是連續的。這有時被稱為“擴張”。

  • sampling_range_start (int, 可選) – 取樣範圍的開始,它定義了 clip 可能*開始*的第一個索引。預設為:0,即影片的開頭。

  • sampling_range_end (intNone, 可選) – 取樣範圍的結束,它定義了 clip 可能*開始*的最後一個索引。此值是獨佔的,即 clip 只能在 [sampling_range_start, sampling_range_end) 範圍內開始。如果為 None(預設),則會自動設定該值,以便 clip 從不超出影片末尾。例如,如果影片中的最後一個有效索引是 99,而 clip 跨度為 10 幀,則此值設定為 99 - 10 + 1 = 90。負值是接受的,並且等同於 len(video) - val。當 clip 超出影片末尾時,policy 引數定義瞭如何構造這樣的 clip。

  • policy (str, 可選) –

    定義如何構造超出影片末尾的 clips。最好的方式是透過示例來描述:假設影片中的最後一個有效索引是 99,並且一個 clip 被取樣以從索引 95 開始,num_frames_per_clip=5,num_indices_between_frames=2,那麼 clip 中的幀的索引應該是 [95, 97, 99, 101, 103]。但 101 和 103 是無效索引,因此 policy 引數定義瞭如何用有效索引替換這些幀。

    • “repeat_last”:重複 clip 的最後一幀。我們會得到 [95, 97, 99, 99, 99]。

    • “wrap”:迴圈到 clip 的開頭。我們會得到 [95, 97, 99, 95, 97]。

    • “error”:引發錯誤。

    預設為“repeat_last”。請注意,當 sampling_range_end=None(預設)時,此 policy 引數不太可能相關。

返回:

取樣到的 clips,作為 5D FrameBatchdata 欄位的形狀為 (num_clips, num_frames_per_clip, …),其中 … 是 (H, W, C) 或 (C, H, W),具體取決於 VideoDecoderdimension_order 引數。pts_secondsduration_seconds 欄位的形狀為 (num_clips, num_frames_per_clip)。

返回型別:

FrameBatch

使用 clips_at_random_indices 的示例

精確與近似搜尋模式:效能和準確性比較

精確與近似搜尋模式:效能和準確性比較

如何取樣影片片段

如何取樣影片片段

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

為初學者和高階開發者提供深入的教程

檢視教程

資源

查詢開發資源並讓您的問題得到解答

檢視資源