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 (int 或 None, 可选) – 采样范围的结束,它定义了 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
FrameBatch
。data
字段的形状为 (num_clips
,num_frames_per_clip
, …),其中 … 是 (H, W, C) 或 (C, H, W),具体取决于VideoDecoder
的dimension_order
参数。pts_seconds
和duration_seconds
字段的形状为 (num_clips
,num_frames_per_clip
)。- 返回类型:
使用
clips_at_random_indices
的示例