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)
| 9 | |
| 10 | |
| 11 | def 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 | |
| 31 | def get_start_end_idx( |