
    Ph"                    :   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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Z0d%dZ1d%dZ2y)&    )annotationsN)suppress)
AnyCallableDictListLiteralOptional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      kC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchvision/transforms/v2/_utils.py_setup_number_or_seqr'      s*   cC124& RSWX[S\R]^__#x SXV%;3tf$TUXY\U]T^_``#x GgU|4 D6)OPTU\P]!_``  #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,   )   sU    $[[]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   r0   )r1   vs     r&   _convert_fill_argr6   2   sB    
 |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*   itemsr6   )r1   kr5   s      r&   _setup_fill_argr;   ?   sL    D$JJLDAq'*DG !+D122r(   c                >    || v r| |   S d| v r| d   S t        d       y )Nr8   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                    t        | t        j                  t        t        f      st        d      t        | t        t        f      r&t        |       dvrt        dt        |        d      y y )NzGot inappropriate padding arg)r   r      z<Padding must be an int or a 1, 2, or 4 element tuple, not a z element tuple)r   r-   r.   r/   r0   r   r!   r"   )paddings    r&   _check_padding_argrD   S   sc    gt<=788'E4=)c'l).KWX[\cXdWeestuu /L)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_argrK   ]   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.0keys     r&   	<genexpr>z1_find_labels_default_heuristic.<locals>.<genexpr>   s     UMSSYY[H=TSMs   ""c              3  F   K   | ]  }d |j                         v s|  yw)labelNrO   rQ   s     r&   rT   z1_find_labels_default_heuristic.<locals>.<genexpr>   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/   r0   r   collectionsabcMappingr"   r   StopIterationnextkeys)inputscandidate_keys     r&   _find_labels_default_heuristicr_   b   s      &5$-( ffkoo556FFLXYX
 	

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

 -   
!	  %$s   -!C"'!C."C+.C7c                Z    | dk(  rt         S t        |       r| S | d S t        d|  d      )Ndefaultc                     y r4    )_s    r&   <lambda>z&_parse_labels_getter.<locals>.<lambda>   s    r(   zGlabels_getter should either be 'default', a callable, or None, but got .)r_   callabler"   )labels_getters    r&   _parse_labels_getterri      sD     	!--	-	 		bcpbqqrsttr(   c                X    	 t        d | D              S # t        $ r t        d      w xY w)Nc              3  V   K   | ]!  }t        |t        j                        s| # y wr4   )r   r   BoundingBoxes)rR   inpts     r&   rT   z%get_bounding_boxes.<locals>.<genexpr>   s      _[TJtZE]E]4^D[s   ))z*No bounding boxes were found in the sample)r[   rZ   r"   )flat_inputss    r&   get_bounding_boxesro      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 )Nz)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)rn   rm   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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 )Nz=No image, video, mask or bounding box was found in the sampler   z-Found multiple HxW dimensions in the sample: )rq   r   r   rr   rs   rt   Maskrl   r/   r   r   r!   r"   r   ru   rv   )rn   rm   sizesry   rz   s        r&   
query_sizer      s      D  		  ((

 	htn 
  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&   rq   rq      s7    (-7t-L:c=) S``cRd ) r(   c                .    | D ]  }t        ||      s y yr   )rq   )rn   r   rm   s      r&   has_anyr      s    dO,  r(   c                r    |D ]2  }| D ]*  }t        |t              rt        ||      s n	 ||      s* 1  y y)NFTr   )rn   r   r   rm   s       r&   has_allr      s?    (D2<]D2Qz$.WdeiWj    ) r(   )r#   z.Union[int, float, Sequence[Union[int, float]]]r$   strreturnzSequence[float])r1   3Union[_FillType, Dict[Union[Type, str], _FillType]]r   None)r1   r   r   r   )r1   r   r   z$Dict[Union[Type, str], _FillTypeJIT])rC   zUnion[int, Sequence[int]]r   r   )rJ   z3Literal['constant', 'edge', 'reflect', 'symmetric']r   r   )r]   r   r   ztorch.Tensor)rh   z9Union[str, Callable[[Any], Optional[torch.Tensor]], None]r   z'Callable[[Any], Optional[torch.Tensor]])rn   	List[Any]r   ztv_tensors.BoundingBoxes)rn   r   r   zTuple[int, int, int])rn   r   r   zTuple[int, int])r   r   r   z.Tuple[Union[Type, Callable[[Any], bool]], ...]r   bool)rn   r   r   z"Union[Type, Callable[[Any], bool]]r   r   )3
__future__r   collections.abcrW   r-   
contextlibr   typingr   r   r   r   r	   r
   r   r   r   r   	PIL.Imagers   torchtorchvisionr   torchvision._utilsr   !torchvision.transforms.transformsr   r   r   $torchvision.transforms.v2.functionalr   r   r   +torchvision.transforms.v2.functional._utilsr   r   r'   r,   r6   r;   r@   rD   rK   r_   ri   ro   r{   r   rq   r   r   rc   r(   r&   <module>r      s    "    ] ] ]   " . ^ ^ Y Y O(n
3pv_
)!X
uL
u,
uG0r(   