
    kh"                    .   d dl mZ d dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZ d dlZd dlZd dlmZ d dlmZ d dlmZmZmZ d dlmZmZmZ d d	l m!Z!m"Z" dd
Z#ddZ$ddZ%ddZ&d Z'ddZ(ddZ)ddZ*d dZ+d!dZ,d"dZ-d#dZ.d$dZ/d%dZ0d%dZ1y)&    )annotationsN)suppress)	AnyCallableDictListLiteralSequenceTupleTypeUnion)
tv_tensors)sequence_to_str)_check_sequence_input_setup_angle_setup_size)get_dimensionsget_sizeis_pure_tensor)	_FillType_FillTypeJITc                t   t        | t        t        t        f      st	        | dt        |              t        | t              r't        |       dvrt        d| dt        |              t        | t              r6| D ]1  }t        |t        t        f      rt        | dt        |              t        | t        t        f      rt        |       t        |       g} | S t        | t              rHt        |       dk(  rt        | d         t        | d         g} | S t        | d         t        | d         g} | S )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      \/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/transforms/v2/_utils.py_setup_number_or_seqr&      s1   cC124& RSWX[S\R]^__#x SXV%;3tf$TUXY\U]T^_``#x  	aGgU|4 D6)OPTU\P]!_``	a #U|$Sz5:& J 
C	"s8q=Q=%A-0C J Q=%A-0CJ    c                    t        | t              r!| j                         D ]  }t        |        y | 1t        | t        j
                  t        t        f      st        d      y y )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+   )   sZ    $[[] 	#EE"	# JtgnneT5R$Slmm %Tr'   c                    | | S t        | t        t        f      s!t        |       D cg c]  }t        |       } }| S c c}w N)r   r   r   r/   )r0   vs     r%   _convert_fill_argr5   2   sA    
 |dS%L)"&t*-Qa--K .s   >c                    t        |        t        | t              r(| j                         D ]  \  }}t	        |      | |<    | S dt	        |       iS )Nothers)r+   r   r)   itemsr5   )r0   kr4   s      r%   _setup_fill_argr:   ?   sQ    D$JJL 	+DAq'*DG	++D122r'   c                >    || v r| |   S d| v r| d   S t        d       y )Nr7   zWThis should never happen, please open an issue on the torchvision repo if you hit this.)RuntimeError)	fill_dict	inpt_types     r%   	_get_fillr?   J   s1    I##	Y	""nor'   c                    d|  d}t        | t        t        f      r+t        |       dvst	        d | D              st        |      y t        | t              st        |      y )NzEPadding must be an int or a 1, 2, or 4 element of tuple or list, got .)r   r      c              3  <   K   | ]  }t        |t                y wr3   )r   r   ).0ps     r%   	<genexpr>z%_check_padding_arg.<locals>.<genexpr>W   s     3X1Jq#4F3Xs   )r   r.   r/   r    allr!   r   )paddingerr_msgs     r%   _check_padding_argrJ   S   sf    UV]U^^_`G'E4=)w<y(3XPW3X0XW%% 1Y%!! &r'   c                "    | dvrt        d      y )N)constantedgereflect	symmetriczBPadding mode should be either constant, edge, reflect or symmetric)r!   )padding_modes    r%   _check_padding_mode_argrQ   _   s    GG]^^ Hr'   c                   t        | t        t        f      r| d   } t        |       r| S t        | t        j
                  j                        st        d|  d      d}t        t              5  t        d | j                         D              }ddd       |8t        t              5  t        d | j                         D              }ddd       |t        d      | |   S # 1 sw Y   UxY w# 1 sw Y   'xY w)ap  
    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  H   K   | ]  }|j                         d k(  s|  yw)labelsNlowerrD   keys     r%   rF   z1_find_labels_default_heuristic.<locals>.<genexpr>   s     USSYY[H=TSUs   ""c              3  F   K   | ]  }d |j                         v s|  yw)labelNrU   rW   s     r%   rF   z1_find_labels_default_heuristic.<locals>.<genexpr>   s      XCIIKAW Xs   !!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_heuristicrc   d   s      &5$-( ffkoo556FFLXYX
 	

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

 -  V V	Y 	Ys   -!C"'!C."C+.C7c                Z    | dk(  rt         S t        |       r| S | d S t        d|  d      )Ndefaultc                     y r3    )_s    r%   <lambda>z&_parse_labels_getter.<locals>.<lambda>   s    r'   zGlabels_getter should either be 'default', a callable, or None, but got rA   )rc   callabler!   )labels_getters    r%   _parse_labels_getterrl      sB    	!--	-	 		bcpbqqrsttr'   c                X    	 t        d | D              S # t        $ r t        d      w xY w)zgReturn the Bounding Boxes in the input.

    Assumes only one ``BoundingBoxes`` object is present.
    c              3  V   K   | ]!  }t        |t        j                        s| # y wr3   )r   r   BoundingBoxes)rD   inpts     r%   rF   z%get_bounding_boxes.<locals>.<genexpr>   s     _TJtZE]E]4^D_s   ))z*No bounding boxes were found in the sample)r_   r^   r!   )flat_inputss    r%   get_bounding_boxesrr      s6    G_[___ GEFFGs    )c           
        | D ch c]^  }t        |t        t        j                  t        j                  j                  t        j
                  f      rt        t        |            ` }}|st        d      t        |      dkD  r t        dt        t        |                   |j                         \  }}}|||fS c c}w )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)rq   rp   chwschws         r%   	query_chwr~      s      d^Z-=-=syyPZP`P`ab 	nT"#D 
 CDD	TQJ?[abf[gKhJijkkhhjGAq!a7Ns   A#B>c                   | D ch c]|  }t        |t        t        j                  t        j                  j                  t        j
                  t        j                  t        j                  f      rt        t        |            ~ }}|st        d      t        |      dkD  r t        dt        t        |                   |j                         \  }}||fS c c}w )zReturn Height and Width.z=No image, video, mask or bounding box was found in the sampler   z-Found multiple HxW dimensions in the sample: )rt   r   r   ru   rv   rw   Maskro   r.   r   r   r    r!   r   rx   ry   )rq   rp   sizesr|   r}   s        r%   
query_sizer      s        		  ((

 	htnE  WXX	UaHY_`eYfIgHhijj99;DAqa4K)s   BCc                d    |D ]+  }t        |t              rt        | |      s  y ||       s+ y yNTFr   r   )objtypes_or_checkstype_or_checks      r%   rt   rt      s<    ( -7t-L:c=) S``cRd r'   c                .    | D ]  }t        ||      s y yr   )rt   )rq   r   rp   s      r%   has_anyr      s#     dO, r'   c                r    |D ]2  }| D ]*  }t        |t              rt        ||      s n	 ||      s* 1  y y)NFTr   )rq   r   r   rp   s       r%   has_allr      sI    (  	D2<]D2Qz$.WdeiWj	  r'   )r"   z.Union[int, float, Sequence[Union[int, float]]]r#   strreturnzSequence[float])r0   3Union[_FillType, Dict[Union[Type, str], _FillType]]r   None)r0   r   r   r   )r0   r   r   z$Dict[Union[Type, str], _FillTypeJIT])rH   zUnion[int, Sequence[int]]r   r   )rP   z3Literal['constant', 'edge', 'reflect', 'symmetric']r   r   )ra   r   r   ztorch.Tensor)rk   z&Union[str, Callable[[Any], Any], None]r   zCallable[[Any], Any])rq   	List[Any]r   ztv_tensors.BoundingBoxes)rq   r   r   zTuple[int, int, int])rq   r   r   zTuple[int, int])r   r   r   z.Tuple[Union[Type, Callable[[Any], bool]], ...]r   bool)rq   r   r   z"Union[Type, Callable[[Any], bool]]r   r   )2
__future__r   collections.abcr[   r,   
contextlibr   typingr   r   r   r   r	   r
   r   r   r   	PIL.Imagerv   torchtorchvisionr   torchvision._utilsr   !torchvision.transforms.transformsr   r   r   $torchvision.transforms.v2.functionalr   r   r   +torchvision.transforms.v2.functional._utilsr   r   r&   r+   r5   r:   r?   rJ   rQ   rc   rl   rr   r~   r   rt   r   r   rg   r'   r%   <module>r      s    "    S S S   " . ^ ^ Y Y O(n
3p"_
)!Xu	G2r'   