
    x h"                    "   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#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Z,y)'    )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                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      |/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/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*   )r+   vs     r    _convert_fill_argr0   3   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$   itemsr0   )r+   kr/   s      r    _setup_fill_argr5   @   sQ    D$JJL 	+DAq'*DG	++D122r"   c                >    || v r| |   S d| v r| d   S t        d       y )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   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r.   )r   r   ).0ps     r    	<genexpr>z%_check_padding_arg.<locals>.<genexpr>X   s     3X1Jq#4F3Xs   )r   r)   r*   r   allr   r   )paddingerr_msgs     r    _check_padding_argrE   T   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_argrL   `   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r?   keys     r    rA   z1_find_labels_default_heuristic.<locals>.<genexpr>   s     USSYY[H=TSUs   ""c              3  F   K   | ]  }d |j                         v s|  yw)labelNrP   rR   s     r    rA   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_heuristicr^   e   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 r.    )_s    r    <lambda>z&_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_getterrg      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r.   )r   r	   BoundingBoxes)r?   inpts     r    rA   z%get_bounding_boxes.<locals>.<genexpr>   s     _TJtZE]E]4^D_s   ))z*No bounding boxes were found in the sample)rZ   rY   r   )flat_inputss    r    get_bounding_boxesrm      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)rl   rk   chwschws         r    	query_chwry      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                  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.zGNo image, video, mask, bounding box of keypoint was found in the sampler   z-Found multiple HxW dimensions in the sample: )ro   r   r	   rp   rq   rr   Maskrj   	KeyPointsr)   r   r   r   r   r
   rs   rt   )rl   rk   sizesrw   rx   s        r    
query_sizer~      s        		  (($$
 	htnE   abb	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    ro   ro      s<    ( -7t-L:c=) S``cRd r"   c                .    | D ]  }t        ||      s y yr   )ro   )rl   r   rk   s      r    has_anyr      s#     dO, r"   c                r    |D ]2  }| D ]*  }t        |t              rt        ||      s n	 ||      s* 1  y y)NFTr   )rl   r   r   rk   s       r    has_allr      sI    (  	D2<]D2Qz$.WdeiWj	  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])rC   zint | Sequence[int]r   r   )rK   z3Literal['constant', 'edge', 'reflect', 'symmetric']r   r   )r\   r   r   ztorch.Tensor)rf   z!str | Callable[[Any], Any] | Noner   zCallable[[Any], Any])rl   	list[Any]r   ztv_tensors.BoundingBoxes)rl   r   r   ztuple[int, int, int])rl   r   r   ztuple[int, int])r   r   r   z(tuple[type | Callable[[Any], bool], ...]r   bool)rl   r   r   ztype | Callable[[Any], bool]r   r   )-
__future__r   collections.abcrV   r'   r   
contextlibr   typingr   r   r   	PIL.Imagerq   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:   rE   rL   r^   rg   rm   ry   r~   ro   r   r   rb   r"   r    <module>r      s    "   $  ) )   " . ^ ^ Y Y O(n
3p"_
)!Xu	G4r"   