| 15 | |
| 16 | |
| 17 | class 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) |
nothing calls this directly
no outgoing calls
no test coverage detected