MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / temporal_sampling

Function temporal_sampling

slowfast/datasets/decoder.py:11–28  ·  view source on GitHub ↗

Given the start and end frame index, sample num_samples frames between the start and end with equal interval. Args: frames (tensor): a tensor of video frames, dimension is `num video frames` x `channel` x `height` x `width`. start_idx (int): the index of the

(frames, start_idx, end_idx, num_samples)

Source from the content-addressed store, hash-verified

9
10
11def temporal_sampling(frames, start_idx, end_idx, num_samples):
12 """
13 Given the start and end frame index, sample num_samples frames between
14 the start and end with equal interval.
15 Args:
16 frames (tensor): a tensor of video frames, dimension is
17 `num video frames` x `channel` x `height` x `width`.
18 start_idx (int): the index of the start frame.
19 end_idx (int): the index of the end frame.
20 num_samples (int): number of frames to sample.
21 Returns:
22 frames (tersor): a tensor of temporal sampled video frames, dimension is
23 `num clip frames` x `channel` x `height` x `width`.
24 """
25 index = torch.linspace(start_idx, end_idx, num_samples)
26 index = torch.clamp(index, 0, frames.shape[0] - 1).long()
27 frames = torch.index_select(frames, 0, index)
28 return frames
29
30
31def get_start_end_idx(

Callers 1

decodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected