
    kh                     l    d dl Z d dlZ e j                  d       d Zd Zd ZddZd Zd Zdd	Z	d
 Z
y)    NzThe 'torchvision.transforms._functional_video' module is deprecated since 0.12 and will be removed in the future. Please use the 'torchvision.transforms.functional' module instead.c                     t        j                  |       st        dt        |       z        | j	                         dk(  st        d| j                         z        y)Nzclip should be Tensor. Got %s   zclip should be 4D. Got %dDT)torch	is_tensor	TypeErrortype
ndimension
ValueErrordimclips    d/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/transforms/_functional_video.py_is_tensor_video_clipr      sL    ??4 7$t*DEE??!5
BCC    c                 t    t        | j                               dk7  rt        d      | d|||z   |||z   f   S )z[
    Args:
        clip (torch.tensor): Video clip to be cropped. Size is (C, T, H, W)
    r   zclip should be a 4D tensor.)lensizer
   )r   ijhws        r   cropr      sE    
 499;1566QQYAE	)**r   c                     t        |      dk7  rt        d|       t        j                  j                  j                  | ||d      S )N   z9target size should be tuple (height, width), instead got F)r   modealign_corners)r   r
   r   nn
functionalinterpolate)r   target_sizeinterpolation_modes      r   resizer"       sJ    
;1TU`Tabcc88**4kHZjo*ppr   c                 j    t        |       st        d      t        | ||||      } t        | ||      } | S )a  
    Do spatial cropping and resizing to the video clip
    Args:
        clip (torch.tensor): Video clip to be cropped. Size is (C, T, H, W)
        i (int): i in (i,j) i.e coordinates of the upper left corner.
        j (int): j in (i,j) i.e coordinates of the upper left corner.
        h (int): Height of the cropped region.
        w (int): Width of the cropped region.
        size (tuple(int, int)): height and width of resized clip
    Returns:
        clip (torch.tensor): Resized and cropped clip. Size is (C, T, H, W)
     clip should be a 4D torch.tensor)r   r
   r   r"   )r   r   r   r   r   r   r!   s          r   resized_cropr%   &   s>     !&;<<aAq!D$01DKr   c                 ,   t        |       st        d      | j                  d      | j                  d      }}|\  }}||k  s||k  rt        d      t        t	        ||z
  dz              }t        t	        ||z
  dz              }t        | ||||      S )Nr$   z2height and width must be no smaller than crop_sizeg       @)r   r
   r   introundr   )r   	crop_sizer   r   thtwr   r   s           r   center_cropr.   :   s     &;<<99R=$))B-qAFB2vRMNNE1r6S.!"AE1r6S.!"AaB##r   c                     t        |        | j                  t        j                  k(  s!t	        dt        | j                        z        | j                         j                  dddd      dz  S )a  
    Convert tensor data type from uint8 to float, divide value by 255.0 and
    permute the dimensions of clip tensor
    Args:
        clip (torch.tensor, dtype=torch.uint8): Size is (T, H, W, C)
    Return:
        clip (torch.tensor, dtype=torch.float): Size is (C, T, H, W)
    z/clip tensor should have data type uint8. Got %s   r      r   g     o@)r   dtyper   uint8r   strfloatpermuter   s    r   	to_tensorr7   G   sZ     $::$ICPTPZPZO[\\::<1a+e33r   c                 j   t        |       st        d      |s| j                         } t        j                  || j
                  | j                        }t        j                  || j
                  | j                        }| j                  |dddddf         j                  |dddddf          | S )a  
    Args:
        clip (torch.tensor): Video clip to be normalized. Size is (C, T, H, W)
        mean (tuple): pixel RGB mean. Size is (3)
        std (tuple): pixel standard deviation. Size is (3)
    Returns:
        normalized clip (torch.tensor): Size is (C, T, H, W)
    r$   )r2   deviceN)	r   r
   cloner   	as_tensorr2   r9   sub_div_)r   meanstdinplaces       r   	normalizerA   V   s     !&;<<zz|??4tzz$++FD
//#TZZ
DCIId1dD$&'(--c!T42E.FGKr   c                 P    t        |       st        d      | j                  d      S )z
    Args:
        clip (torch.tensor): Video clip to be normalized. Size is (C, T, H, W)
    Returns:
        flipped clip (torch.tensor): Size is (C, T, H, W)
    r$   r(   )r   r
   flipr   s    r   hfliprD   i   s&     !&;<<99R=r   )bilinear)F)warningsr   warnr   r   r"   r%   r.   r7   rA   rD    r   r   <module>rI      sJ      I+q(
$4&	r   