_temporal.py 971 B

12345678910111213141516171819202122232425262728
  1. from typing import Any, Dict
  2. import torch
  3. from torchvision.transforms.v2 import functional as F, Transform
  4. class UniformTemporalSubsample(Transform):
  5. """[BETA] Uniformly subsample ``num_samples`` indices from the temporal dimension of the video.
  6. .. v2betastatus:: UniformTemporalSubsample transform
  7. Videos are expected to be of shape ``[..., T, C, H, W]`` where ``T`` denotes the temporal dimension.
  8. When ``num_samples`` is larger than the size of temporal dimension of the video, it
  9. will sample frames based on nearest neighbor interpolation.
  10. Args:
  11. num_samples (int): The number of equispaced samples to be selected
  12. """
  13. _transformed_types = (torch.Tensor,)
  14. def __init__(self, num_samples: int):
  15. super().__init__()
  16. self.num_samples = num_samples
  17. def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:
  18. return self._call_kernel(F.uniform_temporal_subsample, inpt, self.num_samples)