MCPcopy Create free account
hub / github.com/ChenHsing/SVFormer / temporal_sampling

Function temporal_sampling

timesformer/datasets/decoder.py:10–27  ·  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

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

Callers 1

decodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected