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
的示例