
    %`iS$                    ,   d dl 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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#dAd!Z$dBd%Z%dCd)Z&dDd-Z'dEd/Z(dFd1Z)dGd3Z*dHd8Z+dId:Z,dId;Z-dS )J    )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_FillTypeJITarg#int | float | Sequence[int | float]namestrreturnSequence[float]c                :   t          | t          t          t          f          s!t	          | dt          |                      t          | t                    r3t          |           dvr"t          d| dt          |                      t          | t                    rB| D ]?}t          |t          t          f          s!t          | dt          |                     @t          | t          t          f          rt          |           t          |           g} n}t          | t                    rht          |           dk    r+t          | d                   t          | d                   g} n*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)r   r   elements      t/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchvision/transforms/v2/_utils.py_setup_number_or_seqr%      s   cC122 `4^^SWX[S\S\^^___#x   aSXXV%;%;_t__UXY\U]U]__```#x   a 	a 	aGgU|44 a D!_!_PTU\P]P]!_!_```a #U|$$ 1Szz5::&	C	"	" 1s88q==Q==%A--0CCQ==%A--0CJ    fill'_FillType | dict[type | str, _FillType]Nonec                    t          | t                    r(|                                 D ]}t          |           d S | 6t          | t          j        t          t          f          st          d          d S d S )NzNGot inappropriate fill arg, only Numbers, tuples, lists and dicts are allowed.)	r   dictvalues_check_fill_argnumbersNumbertuplelistr   )r'   values     r$   r-   r-   *   s    $ n[[]] 	# 	#EE""""	# 	# JtgneT5R$S$Slmmm r&   r   r   c                x    | | S t          | t          t          f          sd t          |           D             } | S )Nc                ,    g | ]}t          |          S  )r   ).0vs     r$   
<listcomp>z%_convert_fill_arg.<locals>.<listcomp><   s    ---Qa---r&   )r   r   r   r1   )r'   s    r$   _convert_fill_argr9   3   sB    
 |dS%L)) .--$t**---Kr&   dict[type | str, _FillTypeJIT]c                    t          |            t          | t                    r.|                                 D ]\  }}t	          |          | |<   | S dt	          |           iS )Nothers)r-   r   r+   itemsr9   )r'   kr7   s      r$   _setup_fill_argr?   @   si    D$ 3JJLL 	+ 	+DAq'**DGG+D1122r&   c                T    || v r| |         S d| v r| d         S t          d           d S )Nr<   zWThis should never happen, please open an issue on the torchvision repo if you hit this.)RuntimeError)	fill_dict	inpt_types     r$   	_get_fillrD   K   sC    I##	Y		""nooooor&   paddingint | Sequence[int]c                   d|  d}t          | t          t          f          r;t          |           dvst	          d | D                       st          |          d S t          | t                    st          |          d S )NzEPadding must be an int or a 1, 2, or 4 element of tuple or list, got .)r   r      c              3  @   K   | ]}t          |t                    V  d S N)r   r   )r6   ps     r$   	<genexpr>z%_check_padding_arg.<locals>.<genexpr>X   s,      3X3X1Jq#4F4F3X3X3X3X3X3Xr&   )r   r0   r1   r!   allr"   r   )rE   err_msgs     r$   _check_padding_argrP   T   s    `V]```G'E4=)) "w<<y((3X3XPW3X3X3X0X0X(W%%% )(%% "!!!" "r&   padding_mode3Literal['constant', 'edge', 'reflect', 'symmetric']c                ,    | dvrt          d          d S )N)constantedgereflect	symmetriczBPadding mode should be either constant, edge, reflect or symmetric)r"   )rQ   s    r$   _check_padding_mode_argrX   `   s&    GGG]^^^ HGr&   inputsr   torch.Tensorc                f   t          | t          t          f          r| d         } t          |           r| S t          | t          j        j                  st          d|  d          d}t          t                    5  t          d |                                 D                       }ddd           n# 1 swxY w Y   |Wt          t                    5  t          d |                                 D                       }ddd           n# 1 swxY w Y   |t          d          | |         S )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  J   K   | ]}|                                 d k    |V  dS )labelsNlowerr6   keys     r$   rM   z1_find_labels_default_heuristic.<locals>.<genexpr>   s4      UUSSYY[[H=T=TS=T=T=T=TUUr&   c              3  F   K   | ]}d |                                 v |V  dS )labelNr^   r`   s     r$   rM   z1_find_labels_default_heuristic.<locals>.<genexpr>   s4       X XCIIKKAWAWAWAWAWAW X Xr&   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   r0   r1   r   collectionsabcMappingr"   r   StopIterationnextkeys)rY   candidate_keys     r$   _find_labels_default_heuristicrk   e   s     &5$-((  f fko566 
XFLX X X
 
 	

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

 -  s$   >,B66B:=B:,DDDlabels_getter!str | Callable[[Any], Any] | NoneCallable[[Any], Any]c                n    | dk    rt           S t          |           r| S | d S t          d|  d          )Ndefaultc                    d S rK   r5   )_s    r$   <lambda>z&_parse_labels_getter.<locals>.<lambda>   s     r&   zGlabels_getter should either be 'default', a callable, or None, but got rH   )rk   callabler"   )rl   s    r$   _parse_labels_getterru      sS    	!!--	-	 	  u		~scpssstttr&   flat_inputs	list[Any]tv_tensors.BoundingBoxesc                p    	 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  N   K   | ] }t          |t          j                  |V  !d S rK   )r   r	   BoundingBoxesr6   inpts     r$   rM   z%get_bounding_boxes.<locals>.<genexpr>   s4      __TJtZE]4^4^_D______r&   z*No bounding boxes were found in the samplerh   rg   r"   rv   s    r$   get_bounding_boxesr      sS    G__[______ G G GEFFFG    5tv_tensors.KeyPointsc                p    	 t          d | D                       S # t          $ r t          d          w xY w)z^Return the keypoints in the input.

    Assumes only one ``KeyPoints`` object is present.
    c              3  N   K   | ] }t          |t          j                  |V  !d S rK   )r   r	   	KeyPointsr|   s     r$   rM   z get_keypoints.<locals>.<genexpr>   s4      [[TJtZEY4Z4Z[D[[[[[[r&   z%No keypoints were found in the sampler~   r   s    r$   get_keypointsr      sS    B[[[[[[[[[ B B B@AAABr   tuple[int, int, int]c                    d | D             }|st          d          t          |          dk    r,t          dt          t	          |                               |                                \  }}}|||fS )z"Return Channel, Height, and Width.c           	         h | ]Z}t          |t          t          j        t          j        j        t          j        f          >t          t          |                    [S r5   )
check_typer   r	   ImagePILVideor0   r   r|   s     r$   	<setcomp>zquery_chw.<locals>.<setcomp>   s\       d^Z-=syPZP`abbnT""##  r&   z)No image or video was found in the sampler   z/Found multiple CxHxW dimensions in the sample: r   r!   r"   r
   sortedpop)rv   chwschws        r$   	query_chwr      s       D
  lCDDD	TQj?[abf[g[gKhKhjjkkkhhjjGAq!a7Nr&   tuple[int, int]c                    d | D             }|st          d          t          |          dk    r,t          dt          t	          |                               |                                \  }}||fS )zReturn Height and Width.c                    h | ]{}t          |t          t          j        t          j        j        t          j        t          j        t          j        t          j        f          _t          t          |                    |S r5   )r   r   r	   r   r   r   Maskr{   r   r0   r   r|   s     r$   r   zquery_size.<locals>.<setcomp>   su        	 ($
 
htnn  r&   zGNo image, video, mask, bounding box of keypoint was found in the sampler   z-Found multiple HxW dimensions in the sample: r   )rv   sizesr   r   s       r$   
query_sizer      s       E   kabbb	UaiY_`eYfYfIgIgiijjj99;;DAqa4Kr&   objtypes_or_checks(tuple[type | Callable[[Any], bool], ...]boolc                x    |D ]6}t          |t                    rt          | |          rn ||           r dS 7dS NTFr   r    )r   r   type_or_checks      r$   r   r      sZ    (  -7t-L-L 	:c=)) 	 	R_R_`cRdRd 	445r&   type | Callable[[Any], bool]c                6    | D ]}t          ||          r dS dS r   )r   )rv   r   r}   s      r$   has_anyr      s4      dO,, 	44	5r&   c                    |D ]=}| D ]5}t          |t                    rt          ||          rn ||          r n6 dS >dS )NFTr   )rv   r   r   r}   s       r$   has_allr      su    (   	 	D2<]D2Q2Q z$..  WdWdeiWjWj 55  4r&   )r   r   r   r   r   r   )r'   r(   r   r)   )r'   r   r   r   )r'   r(   r   r:   )rE   rF   r   r)   )rQ   rR   r   r)   )rY   r   r   rZ   )rl   rm   r   rn   )rv   rw   r   rx   )rv   rw   r   r   )rv   rw   r   r   )rv   rw   r   r   )r   r   r   r   r   r   )rv   rw   r   r   r   r   ).
__future__r   collections.abcrd   r.   r   
contextlibr   typingr   r   r   	PIL.Imager   torchtorchvisionr	   torchvision._utilsr
   !torchvision.transforms.transformsr   r   r   $torchvision.transforms.v2.functionalr   r   r   +torchvision.transforms.v2.functional._utilsr   r   r%   r-   r9   r?   rD   rP   rX   rk   ru   r   r   r   r   r   r   r   r5   r&   r$   <module>r      sX   " " " " " "      $ $ $ $ $ $       ) ) ) ) ) ) ) ) ) )      " " " " " " . . . . . . ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Y Y Y Y Y Y Y Y Y Y O O O O O O O O   (n n n n
 
 
 
3 3 3 3p p p" " " "_ _ _ _
)! )! )! )!Xu u u u	G 	G 	G 	G	B 	B 	B 	B      4           r&   