
    \h"                    >   S SK Jr  S SKrS SKrS SKJr  S SKJr  S SKJ	r	J
r
Jr  S SKrS SKrS SKJr  S SKJr  S SKJrJrJr  S S	KJrJrJr  S S
KJrJr  SS jrSS jrSS jr SS jr!S r"SS jr#SS jr$S S jr%S!S jr&S"S jr'S#S jr(S$S jr)S%S jr*S&S jr+S&S jr,g)'    )annotationsN)Sequence)suppress)AnyCallableLiteral)
tv_tensors)sequence_to_str)_check_sequence_input_setup_angle_setup_size)get_dimensionsget_sizeis_pure_tensor)	_FillType_FillTypeJITc                   [        U [        [        [        45      (       d  [	        U S[        U 5       35      e[        U [        5      (       a)  [        U 5      S;  a  [        SU S[        U 5       35      e[        U [        5      (       a=  U  H7  n[        U[        [        45      (       a  M   [        U S[        U5       35      e   [        U [        [        45      (       a  [        U 5      [        U 5      /n U $ [        U [        5      (       aI  [        U 5      S:X  a  [        U S   5      [        U S   5      /n U $ [        U S   5      [        U S   5      /n U $ )Nz2 should be a number or a sequence of numbers. Got )      zIf z0 is a sequence its length should be 1 or 2. Got z& should be a sequence of numbers. Got r   r   )
isinstanceintfloatr   	TypeErrortypelen
ValueError)argnameelements      Z/var/www/fran/franai/venv/lib/python3.13/site-packages/torchvision/transforms/v2/_utils.py_setup_number_or_seqr!      s<   cC1224& RSWX[S\R]^__#x  SXV%;3tf$TUXY\U]T^_``#x  GgU|44 D6)OPTU\P]!_``  #U|$$Sz5:& J 
C	"	"s8q=Q=%A-0C J Q=%A-0CJ    c                    [        U [        5      (       a#  U R                  5        H  n[        U5        M     g U b6  [        U [        R
                  [        [        45      (       d  [        S5      eg g )NzNGot inappropriate fill arg, only Numbers, tuples, lists and dicts are allowed.)	r   dictvalues_check_fill_argnumbersNumbertuplelistr   )fillvalues     r    r&   r&   *   s[    $[[]EE" # JtgnneT5R$S$Slmm %Tr"   c                    U c  U $ [        U [        [        45      (       d$  [        U 5       Vs/ s H  n[        U5      PM     n nU $ s  snf N)r   r   r   r*   )r+   vs     r    _convert_fill_argr0   3   sE    
 |dS%L))"&t*-*Qa*-K .s   Ac                    [        U 5        [        U [        5      (       a(  U R                  5        H  u  p[	        U5      X'   M     U $ S[	        U 5      0$ )Nothers)r&   r   r$   itemsr0   )r+   kr/   s      r    _setup_fill_argr5   @   sK    D$JJLDA'*DG !+D122r"   c                B    X;   a  X   $ SU ;   a  U S   $ [        S5        g )Nr2   zWThis should never happen, please open an issue on the torchvision repo if you hit this.)RuntimeError)	fill_dict	inpt_types     r    	_get_fillr:   K   s-    ##	Y	""nor"   c                    SU  S3n[        U [        [        45      (       a2  [        U 5      S;  d  [	        S U  5       5      (       d  [        U5      eg [        U [        5      (       d  [        U5      eg )NzEPadding must be an int or a 1, 2, or 4 element of tuple or list, got .)r   r      c              3  B   #    U  H  n[        U[        5      v   M     g 7fr.   )r   r   ).0ps     r    	<genexpr>%_check_padding_arg.<locals>.<genexpr>X   s     3XPW1Jq#4F4FPWs   )r   r)   r*   r   allr   r   )paddingerr_msgs     r    _check_padding_argrF   T   so    UV]U^^_`G'E4=))w<y(3XPW3X0X0XW%% 1Y%%!! &r"   c                &    U S;  a  [        S5      eg )N)constantedgereflect	symmetriczBPadding mode should be either constant, edge, reflect or symmetric)r   )padding_modes    r    _check_padding_mode_argrM   `   s    GG]^^ Hr"   c                (   [        U [        [        45      (       a  U S   n [        U 5      (       a  U $ [        U [        R
                  R                  5      (       d  [        SU  S35      eSn[        [        5         [        S U R                  5        5       5      nSSS5        Uc8  [        [        5         [        S U R                  5        5       5      nSSS5        Uc  [        S5      eX   $ ! , (       d  f       N[= f! , (       d  f       N1= f)aD  
This heuristic covers three cases:

1. The input is tuple or list whose second item is a labels tensor. This happens for already batched
   classification inputs for MixUp and CutMix (typically after the Dataloder).
2. The input is a tuple or list whose second item is a dictionary that contains the labels tensor
   under a label-like (see below) key. This happens for the inputs of detection models.
3. The input is a dictionary that is structured as the one from 2.

What is "label-like" key? We first search for an case-insensitive match of 'labels' inside the keys of the
dictionary. This is the name our detection models expect. If we can't find that, we look for a case-insensitive
match of the term 'label' anywhere inside the key, i.e. 'FooLaBeLBar'. If we can't find that either, the dictionary
contains no "label-like" key.
r   zWhen using the default labels_getter, the input passed to forward must be a dictionary or a two-tuple whose second item is a dictionary or a tensor, but got z	 instead.Nc              3  P   #    U  H  oR                  5       S :X  d  M  Uv   M     g7f)labelsNlowerr?   keys     r    rA   1_find_labels_default_heuristic.<locals>.<genexpr>   s     UMSYY[H=TSSMs   &	&c              3  R   #    U  H  nS UR                  5       ;   d  M  Uv   M     g7f)labelNrQ   rS   s     r    rA   rU      s      XCIIKAWs   '	'zCould not infer where the labels are in the sample. Try passing a callable as the labels_getter parameter?If there are no labels in the sample by design, pass labels_getter=None.)r   r)   r*   r   collectionsabcMappingr   r   StopIterationnextkeys)inputscandidate_keys     r    _find_labels_default_heuristicr`   e   s      &5$-(( ffkoo5566FFLXYX
 	

 M	-	 UFKKMUU 
!m$  X XXM %W
 	

    
!	  %$s   <!C27!D2
D 
Dc                h    U S:X  a  [         $ [        U 5      (       a  U $ U c  S $ [        SU  S35      e)Ndefaultc                    g r.    )_s    r    <lambda>&_parse_labels_getter.<locals>.<lambda>   s    r"   zGlabels_getter should either be 'default', a callable, or None, but got r<   )r`   callabler   )labels_getters    r    _parse_labels_getterrj      sE    	!--	-	 	 		bcpbqqrsttr"   c                Z     [        S U  5       5      $ ! [         a    [        S5      ef = f)z_Return the Bounding Boxes in the input.

Assumes only one ``BoundingBoxes`` object is present.
c              3  h   #    U  H(  n[        U[        R                  5      (       d  M$  Uv   M*     g 7fr.   )r   r	   BoundingBoxes)r?   inpts     r    rA   %get_bounding_boxes.<locals>.<genexpr>   s!     _[TJtZE]E]4^DD[s   #2	2z*No bounding boxes were found in the sample)r\   r[   r   )flat_inputss    r    get_bounding_boxesrq      s6    G_[___ GEFFGs    *c           
        U  Vs1 s Hf  n[        U[        [        R                  [        R                  R                  [        R
                  45      (       d  MR  [        [        U5      5      iMh     nnU(       d  [        S5      e[        U5      S:  a   [        S[        [        U5      5       35      eUR                  5       u  p4nX4U4$ s  snf )z"Return Channel, Height, and Width.z)No image or video was found in the sampler   z/Found multiple CxHxW dimensions in the sample: )
check_typer   r	   ImagePILVideor)   r   r   r   r   r
   sortedpop)rp   rn   chwschws         r    	query_chwr}      s      Dd^Z-=-=syyPZP`P`ab 	$nT"# 	 
 CDD	TQJ?[abf[gKhJijkkhhjGA!7Ns   ACCc                   U  Vs1 s H  n[        U[        [        R                  [        R                  R                  [        R
                  [        R                  [        R                  [        R                  45      (       d  M  [        [        U5      5      iM     nnU(       d  [        S5      e[        U5      S:  a   [        S[        [        U5      5       35      eUR!                  5       u  p4X44$ s  snf )zReturn Height and Width.zGNo image, video, mask, bounding box of keypoint was found in the sampler   z-Found multiple HxW dimensions in the sample: )rs   r   r	   rt   ru   rv   Maskrm   	KeyPointsr)   r   r   r   r   r
   rw   rx   )rp   rn   sizesr{   r|   s        r    
query_sizer      s      D  		  (($$
 	htn 
   abb	UaHY_`eYfIgHhijj99;DA4K+s   A>C7C7c                    U H<  n[        U[        5      (       a  [        X5      (       d  M*     gU" U 5      (       d  M<    g   gNTFr   r   )objtypes_or_checkstype_or_checks      r    rs   rs      s>    (-7t-L-L:c)) S``cRdRd ) r"   c                :    U  H  n[        X!5      (       d  M    g   gr   )rs   )rp   r   rn   s      r    has_anyr      s    d,,  r"   c                    U HD  nU  H;  n[        U[        5      (       a  [        X25      (       d  M*  OU" U5      (       d  M:    MB       g   g)NFTr   )rp   r   r   rn   s       r    has_allr      sF    (D2<]D2Q2Qz$..WdeiWjWj    ) r"   )r   z#int | float | Sequence[int | float]r   strreturnzSequence[float])r+   '_FillType | dict[type | str, _FillType]r   None)r+   r   r   r   )r+   r   r   zdict[type | str, _FillTypeJIT])rD   zint | Sequence[int]r   r   )rL   z3Literal['constant', 'edge', 'reflect', 'symmetric']r   r   )r^   r   r   ztorch.Tensor)ri   z!str | Callable[[Any], Any] | Noner   zCallable[[Any], Any])rp   	list[Any]r   ztv_tensors.BoundingBoxes)rp   r   r   ztuple[int, int, int])rp   r   r   ztuple[int, int])r   r   r   z(tuple[type | Callable[[Any], bool], ...]r   bool)rp   r   r   ztype | Callable[[Any], bool]r   r   )-
__future__r   collections.abcrX   r'   r   
contextlibr   typingr   r   r   	PIL.Imageru   torchtorchvisionr	   torchvision._utilsr
   !torchvision.transforms.transformsr   r   r   $torchvision.transforms.v2.functionalr   r   r   +torchvision.transforms.v2.functional._utilsr   r   r!   r&   r0   r5   r:   rF   rM   r`   rj   rq   r}   r   rs   r   r   rd   r"   r    <module>r      s    "   $  ) )   " . ^ ^ Y Y O(n
3p"_
)!Xu	G4r"   