[docs]classBatchVideos(TATensor):""":class:`torch.Tensor` subclass for batch of videos. Args: data: Any data that can be turned into a tensor with :func:`torch.as_tensor`. dtype: Desired data type. If omitted, will be inferred from ``data``. device: Desired device. If omitted and ``data`` is a :class:`torch.Tensor`, the device is taken from it. Otherwise, the video is constructed on the CPU. requires_grad: Whether autograd should record operations. If omitted and ``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``. """def__new__(cls,data:Any,*,dtype:Optional[dtype]=None,device:Optional[Union[device,str,int]]=None,requires_grad:Optional[bool]=None,)->BatchVideos:tensor=cls._to_tensor(data,dtype=dtype,device=device,requires_grad=requires_grad)ifdata.ndim<5:raiseValueErrorreturntensor.as_subclass(cls)
[docs]@classmethoddefcat(cls,video_batches:Sequence[BatchVideos])->BatchVideos:"""Concatenates the sequence of images batches into a single batch."""attrs=["requires_grad","device","dtype",]forbatch_videosinvideo_batches:ifnotisinstance(batch_videos,BatchVideos):raiseValueError("All batches must be of type BatchVideos.")forattrinattrs:ifgetattr(batch_videos,attr)!=getattr(video_batches[0],attr):raiseValueError(f"All batches of images must have the same {attr} attribute.")returncls(torch.cat([images.dataforimagesinvideo_batches],0))
[docs]defto_samples(self)->list[Video]:"""Get the tensors."""return[Video(video.clone())forvideoinself]