Temporally crop the given frame indices at a random location. Args: size (int): Desired length of frames will be seen in the model.
| 451 | # --------------------- Sampling --------------------------- |
| 452 | # ------------------------------------------------------------ |
| 453 | class TemporalRandomCrop(object): |
| 454 | """Temporally crop the given frame indices at a random location. |
| 455 | |
| 456 | Args: |
| 457 | size (int): Desired length of frames will be seen in the model. |
| 458 | """ |
| 459 | |
| 460 | def __init__(self, size): |
| 461 | self.size = size |
| 462 | |
| 463 | def __call__(self, total_frames): |
| 464 | rand_end = max(0, total_frames - self.size - 1) |
| 465 | begin_index = random.randint(0, rand_end) |
| 466 | end_index = min(begin_index + self.size, total_frames) |
| 467 | return begin_index, end_index |
| 468 | |
| 469 | |
| 470 | class DatasetFromCSV(torch.utils.data.Dataset): |