MCPcopy Create free account
hub / github.com/dcharatan/flowmap / FrameSamplerPretrain

Class FrameSamplerPretrain

flowmap/frame_sampler/frame_sampler_pretrain.py:17–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class FrameSamplerPretrain(FrameSampler[FrameSamplerPretrainCfg]):
18 def sample(
19 self,
20 num_frames_in_video: int,
21 device: torch.device,
22 ) -> Int64[Tensor, " frame"]:
23 # If the video doesn't have enough frames, just repeat the last frame.
24 if num_frames_in_video < self.cfg.num_frames:
25 indices = torch.arange(self.cfg.num_frames, device=device)
26 indices[indices >= num_frames_in_video] = num_frames_in_video - 1
27 return indices
28
29 # If the video has enough frames, pick a random starting point.
30 start = torch.randint(0, num_frames_in_video - self.cfg.num_frames + 1, tuple())
31 return torch.arange(start, start + self.cfg.num_frames, device=device)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected