+
    ~j                        ^ RI t ^ RIt^ RIHt ^ RIHtHt ^ RIHt ^ RI	H
t
Ht ^ RIt^ RIt^RIHtHtHtHtHtHtHtHtHt ^RIHtHtHtHtHtHt ^RI H!t! ]! 4       '       d   ^ RI"t#^ RI$t#]#PJ                  PL                  t']! 4       '       d   ^ R	I(H)t)H*t* ^ R
I+H,t, ^ RI-H.t. ]'P^                  ],P`                  ]'Pb                  ],Pb                  ]'Pd                  ],Pd                  ]'Pf                  ],Pf                  ]'Ph                  ],Ph                  ]'Pj                  ],Pj                  /t6]6Po                  4        U Uu/ uF  w  rWbK	  	  upp t8M/ t6/ t8]! 4       '       d   ^ RI9t9]Pt                  ! ];4      t<]R]Pz                  R]>R,          ]>]Pz                  ,          ]>R,          3,          t? ! R R]4      t@ ! R R]4      tA]B]C]D]C,          ]>]B,          ,          3,          tER tF ! R R]4      tGR tHR tIR R ltJR tKR tLR tMR R ltNRKR R lltORKR  R! lltPRKR" R# lltQR$ R% ltRRLR& R' lltSRLR( R) lltTRLR* R+ lltUR, R- ltVR. R/ ltW]@P                  3R0 R1 lltYR2 R3 ltZR4 R5 lt[R6 R7 lt\R8 R9 lt]RLR: R; llt^]!! RMR<7      RLR= R> ll4       t_RLR? R@ llt`RNRA RB llta ! RC RD4      tbRE RF ltcRG RH ltd]! 4        ! RI RJ4      4       teR# u upp i )O    N)Iterable)	dataclassfields)BytesIO)AnyUnion)	ExplicitEnumis_numpy_arrayis_torch_availableis_torch_tensoris_torchvision_availableis_vision_availableloggingrequires_backendsto_numpy)IMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STDIMAGENET_STANDARD_MEANIMAGENET_STANDARD_STDOPENAI_CLIP_MEANOPENAI_CLIP_STD)requires)ImageReadModedecode_image)InterpolationMode)pil_to_tensorPIL.Image.Imagetorch.Tensorc                       ] tR t^UtRtRtRtR# )ChannelDimensionchannels_firstchannels_last N)__name__
__module____qualname____firstlineno__FIRSTLAST__static_attributes__r#       m/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/transformers/image_utils.pyr    r    U   s    EDr+   r    c                       ] tR t^ZtRtRtRtR# )AnnotationFormatcoco_detectioncoco_panopticr#   N)r$   r%   r&   r'   COCO_DETECTIONCOCO_PANOPTICr*   r#   r+   r,   r.   r.   Z   s    %N#Mr+   r.   c                 n    \        4       ;'       d%    \        V \        P                  P                  4      # N)r   
isinstancePILImageimgs   &r,   is_pil_imager:   b   s"     EEZSYY__%EEr+   c                   "    ] tR t^ftRtRtRtRtR# )	ImageTypepillowtorchnumpyr#   N)r$   r%   r&   r'   r6   TORCHNUMPYr*   r#   r+   r,   r<   r<   f   s    
CEEr+   r<   c                     \        V 4      '       d   \        P                  # \        V 4      '       d   \        P                  # \        V 4      '       d   \        P                  # \        R \        V 4       24      h)zUnrecognized image type )	r:   r<   r6   r   r@   r
   rA   
ValueErrortypeimages   &r,   get_image_typerG   l   sX    E}}ue
/U}=
>>r+   c                 d    \        V 4      ;'       g    \        V 4      ;'       g    \        V 4      # r4   )r:   r
   r   r8   s   &r,   is_valid_imagerI   v   s'    KKs 3KKs7KKr+   c                $    V ^8  d   QhR\         /# )   images)list)formats   "r,   __annotate__rO   z   s     E ED Er+   c                 ~    T ;'       d5    \         ;QJ d    R  V  4       F  '       d   K   R# 	  R# ! R  V  4       4      # )c              3   8   "   T F  p\        V4      x  K  	  R # 5ir4   )rI   ).0rF   s   & r,   	<genexpr>*is_valid_list_of_images.<locals>.<genexpr>{   s     DVE.//V   FTall)rL   s   &r,   is_valid_list_of_imagesrX   z   s3    DDccDVDccDcDcDVDDDr+   c                 ~   \        V ^ ,          \        4      '       d   V  UUu. uF  q F  q"NK  	  K  	  upp# \        V ^ ,          \        P                  4      '       d   \        P                  ! V ^ R7      # \        V ^ ,          \
        P                  4      '       d   \
        P                  ! V ^ R7      # R# u uppi )r   axis)dimN)r5   rM   npndarrayconcatenater>   Tensorcat)
input_listsublistitems   &  r,   concatenate_listre   ~   s    *Q-&&$.CJ747JCC	JqM2::	.	.~~jq11	JqM5<<	0	0yy++ 
1 Ds   B9c                     \        V \        \        34      '       d    V  F  p\        V4      '       d   K   R # 	  R# \	        V 4      '       g   R # R# )FT)r5   rM   tuplevalid_imagesrI   )imgsr9   s   & r,   rh   rh      sC    $u&&C$$   D!!r+   c                 b    \        V \        \        34      '       d   \        V ^ ,          4      # R# )r   F)r5   rM   rg   rI   r8   s   &r,   
is_batchedrk      s%    #e}%%c!f%%r+   c                D    V ^8  d   QhR\         P                  R\        /# )rK   rF   return)r]   r^   bool)rN   s   "r,   rO   rO      s     5 52:: 5$ 5r+   c                    V P                   \        P                  8X  d   R# \        P                  ! V 4      ^ 8  ;'       d    \        P                  ! V 4      ^8*  # )zN
Checks to see whether the pixel values have already been rescaled to [0, 1].
F)dtyper]   uint8minmaxrE   s   &r,   is_scaled_imagert      sA     {{bhh 66%=A44"&&-1"44r+   c                F    V ^8  d   QhR\         R\        \        ,          /# )rK   expected_ndimsrm   )intrM   
ImageInput)rN   s   "r,   rO   rO      s     # # #D<L #r+   c           	     d   \        V 4      '       d   V # \        V 4      '       d   V .# \        V 4      '       db   V P                  V^,           8X  d   \	        V 4      p V # V P                  V8X  d   V .p V # \        RV^,            RV RV P                   R24      h\        R\        V 4       R24      h)a  
Ensure that the output is a list of images. If the input is a single image, it is converted to a list of length 1.
If the input is a batch of images, it is converted to a list of images.

Args:
    images (`ImageInput`):
        Image of images to turn into a list of images.
    expected_ndims (`int`, *optional*, defaults to 3):
        Expected number of dimensions for a single input image. If the input image has a different number of
        dimensions, an error is raised.
z%Invalid image shape. Expected either z or z dimensions, but got z dimensions.z]Invalid image type. Expected either PIL.Image.Image, numpy.ndarray, or torch.Tensor, but got .)rk   r:   rI   ndimrM   rC   rD   )rL   rv   s   &&r,   make_list_of_imagesr|      s     & Fxf;;.1,,&\F  [[N*XF 	 78J7K4P^O_ `KK=. 
 
ghlmshtguuvw r+   c                h    V ^8  d   QhR\         \        ,          \        ,          R\        R\        /# rK   rL   rv   rm   rM   rx   rw   )rN   s   "r,   rO   rO      s5     #L #Lz)#L#L #Lr+   c                p   \        V \        \        34      '       d   \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       dV   \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       d   V  UUu. uF  q" F  q3NK  	  K  	  upp# \        V \        \        34      '       d~   \	        V 4      '       dm   \        V ^ ,          4      '       g   V ^ ,          P                  V8X  d   V # V ^ ,          P                  V^,           8X  d   V  UUu. uF  q" F  q3NK  	  K  	  upp# \        V 4      '       dI   \        V 4      '       g   V P                  V8X  d   V .# V P                  V^,           8X  d   \        V 4      # \        RV  24      hu uppi u uppi )a  
Ensure that the output is a flat list of images. If the input is a single image, it is converted to a list of length 1.
If the input is a nested list of images, it is converted to a flat list of images.
Args:
    images (`Union[list[ImageInput], ImageInput]`):
        The input image.
    expected_ndims (`int`, *optional*, defaults to 3):
        The expected number of dimensions for a single input image.
Returns:
    list: A list of images or a 4d array of images.
c              3   N   "   T F  p\        V\        \        34      x  K  	  R # 5ir4   r5   rM   rg   rR   images_is   & r,   rS   +make_flat_list_of_images.<locals>.<genexpr>        KF
8dE]33F   #%FTc              3   V   "   T F  p\        V4      ;'       g    V'       * x  K!  	  R # 5ir4   rX   r   s   & r,   rS   r      %     YRXh'1AA\ARX   ))z*Could not make a flat list of images from 	r5   rM   rg   rW   rX   r:   r{   rI   rC   )rL   rv   img_listr9   s   &&  r,   make_flat_list_of_imagesr      sI   " 	6D%=))CKFKCCCKFKKKCYRXYCCCYRXYYY$*?FhshF??&4-((-DV-L-Lq	""fQinn&FM!9>>^a//(.CH(3C(CCCf6;;.#@8O;;.1,,<
A&J
KK @ Ds   F,/F2c                ~    V ^8  d   QhR\         \        ,          \        ,          R\        R\         \        ,          /# r~   r   )rN   s   "r,   rO   rO      s:     $v $vz)$v$v 
*$vr+   c                0   \        V \        \        34      '       dw   \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       d=   \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       d   V # \        V \        \        34      '       d   \	        V 4      '       dn   \        V ^ ,          4      '       g   V ^ ,          P                  V8X  d   V .# V ^ ,          P                  V^,           8X  d   V  Uu. uF  p\        V4      NK  	  up# \        V 4      '       dK   \        V 4      '       g   V P                  V8X  d   V ..# V P                  V^,           8X  d   \        V 4      .# \        R4      hu upi )aO  
Ensure that the output is a nested list of images.
Args:
    images (`Union[list[ImageInput], ImageInput]`):
        The input image.
    expected_ndims (`int`, *optional*, defaults to 3):
        The expected number of dimensions for a single input image.
Returns:
    list: A list of list of images or a list of 4d array of images.
c              3   N   "   T F  p\        V\        \        34      x  K  	  R # 5ir4   r   r   s   & r,   rS   -make_nested_list_of_images.<locals>.<genexpr>  r   r   FTc              3   V   "   T F  p\        V4      ;'       g    V'       * x  K!  	  R # 5ir4   r   r   s   & r,   rS   r     r   r   z]Invalid input type. Must be a single image, a list of images, or a list of batches of images.r   )rL   rv   rF   s   && r,   make_nested_list_of_imagesr      s*     	6D%=))CKFKCCCKFKKKCYRXYCCCYRXYYY &4-((-DV-L-Lq	""fQinn&F8O!9>>^a//-34VEDKV44 f6;;.#@H:;;.1,,L>!
t
uu 5s   Fc                8    V ^8  d   QhR\         P                  /# rK   rm   )r]   r^   )rN   s   "r,   rO   rO     s      2:: r+   c                    \        V 4      '       g   \        R \        V 4       24      h\        4       '       dA   \	        V \
        P                  P                  4      '       d   \        P                  ! V 4      # \        V 4      # )zInvalid image type: )
rI   rC   rD   r   r5   r6   r7   r]   arrayr   r8   s   &r,   to_numpy_arrayr     sY    #/S	{;<<C!A!Axx}C=r+   c                    V ^8  d   QhR\         P                  R\        \        \        R3,          ,          R,          R\        /# )rK   rF   num_channels.Nrm   )r]   r^   rw   rg   r    )rN   s   "r,   rO   rO      s?     $A $A::$A%(5c?%:T%A$A$Ar+   c                r   Ve   TMRp\        V\        4      '       d   V3MTpV P                  ^8X  d   ^ ^r2MBV P                  ^8X  d   ^^r2M-V P                  ^8X  d   ^^r2M\        RV P                   24      hV P                  V,          V9   dL   V P                  V,          V9   d4   \
        P                  RV P                   R24       \        P                  # V P                  V,          V9   d   \        P                  # V P                  V,          V9   d   \        P                  # \        R4      h)a7  
Infers the channel dimension format of `image`.

Args:
    image (`np.ndarray`):
        The image to infer the channel dimension of.
    num_channels (`int` or `tuple[int, ...]`, *optional*, defaults to `(1, 3)`):
        The number of channels of the image.

Returns:
    The channel dimension of the image.
z(Unsupported number of image dimensions: z4The channel dimension is ambiguous. Got image shape z. Assuming channels are the first dimension. Use the [input_data_format](https://huggingface.co/docs/transformers/main/internal/image_processing_utils#transformers.image_transforms.rescale.input_data_format) parameter to assign the channel dimension.z(Unable to infer channel dimension format      )
r5   rw   r{   rC   shapeloggerwarningr    r(   r)   )rF   r   	first_dimlast_dims   &&  r,   infer_channel_dimension_formatr      s    $0#;<L&0s&C&CL?LzzQ8	q8	q8CEJJ<PQQ{{9-%++h2G<2WB5;;-  PJ  K	
  %%%	Y	<	/%%%	X	,	.$$$
?
@@r+   c                t    V ^8  d   QhR\         P                  R\        \        ,          R,          R\        /# )rK   rF   input_data_formatNrm   )r]   r^   r    strrw   )rN   s   "r,   rO   rO   G  s8     F Fbjj FEUX[E[^bEb Fnq Fr+   c                    Vf   \        V 4      pV\        P                  8X  d   V P                  ^,
          # V\        P                  8X  d   V P                  ^,
          # \        RV 24      h)ar  
Returns the channel dimension axis of the image.

Args:
    image (`np.ndarray`):
        The image to get the channel dimension axis of.
    input_data_format (`ChannelDimension` or `str`, *optional*):
        The channel dimension format of the image. If `None`, will infer the channel dimension from the image.

Returns:
    The channel dimension axis of the image.
Unsupported data format: )r   r    r(   r{   r)   rC   )rF   r   s   &&r,   get_channel_dimension_axisr   G  sd      :5A,222zzA~	.33	3zzA~
01B0CD
EEr+   c                    V ^8  d   QhR\         P                  R\        R,          R\        \        \        3,          /# )rK   rF   channel_dimNrm   )r]   r^   r    rg   rw   )rN   s   "r,   rO   rO   ]  s=     D D"** D3Cd3J DV[\_ad\dVe Dr+   c                (   Vf   \        V 4      pV\        P                  8X  d'   V P                  R,          V P                  R,          3# V\        P                  8X  d'   V P                  R,          V P                  R,          3# \        RV 24      h)a]  
Returns the (height, width) dimensions of the image.

Args:
    image (`np.ndarray`):
        The image to get the dimensions of.
    channel_dim (`ChannelDimension`, *optional*):
        Which dimension the channel dimension is in. If `None`, will infer the channel dimension from the image.

Returns:
    A tuple of the image's height and width.
r   )r   r    r(   r   r)   rC   )rF   r   s   &&r,   get_image_sizer   ]  s{     4U;&,,,{{2B//	(--	-{{2B//4[MBCCr+   c          
          V ^8  d   QhR\         \        \        3,          R\        R\        R\         \        \        3,          /# )rK   
image_size
max_height	max_widthrm   )rg   rw   )rN   s   "r,   rO   rO   u  s@     ! !c3h!! ! 38_	!r+   c                    V w  r4W,          pW$,          p\        WV4      p\        W7,          4      p\        WG,          4      p	W3# )a  
Computes the output image size given the input image and the maximum allowed height and width. Keep aspect ratio.
Important, even if image_height < max_height and image_width < max_width, the image will be resized
to at least one of the edges be equal to max_height or max_width.

For example:
    - input_size: (100, 200), max_height: 50, max_width: 50 -> output_size: (25, 50)
    - input_size: (100, 200), max_height: 200, max_width: 500 -> output_size: (200, 400)

Args:
    image_size (`tuple[int, int]`):
        The image to resize.
    max_height (`int`):
        The maximum allowed height.
    max_width (`int`):
        The maximum allowed width.
)rr   rw   )
r   r   r   heightwidthheight_scalewidth_scale	min_scale
new_height	new_widths
   &&&       r,   #get_image_size_for_max_height_widthr   u  sH    , MF&L#KL.IV'(JE%&I  r+   c                \    V ^8  d   QhR\         \        ,          R\        \        ,          /# )rK   valuesrm   )r   r   rM   )rN   s   "r,   rO   rO     s"     8 8x} 8c 8r+   c                P    \        V !   Uu. uF  p\        V4      NK  	  up# u upi )zG
Return the maximum value across all indices of an iterable of values.
)ziprs   )r   values_is   & r,   max_across_indicesr     s$     +.v,7,hCM,777s   #c                    V ^8  d   QhR\         \        R\        P                  3,          ,          R\        \
        ,          R\         \        ,          /# )rK   rL   r   r   rm   )rM   r   r]   r^   r   r    rw   )rN   s   "r,   rO   rO     sA     # #~rzz123#HKN^H^#	#Y#r+   c                .   V\         P                  8X  d+   \        V  Uu. uF  q"P                  NK  	  up4      w  r4pWE3# V\         P                  8X  d+   \        V  Uu. uF  q"P                  NK  	  up4      w  rEpWE3# \        RV 24      hu upi u upi )z@
Get the maximum height and width across all images in a batch.
z"Invalid channel dimension format: )r    r(   r   r   r)   rC   )rL   r   r9   _r   r   s   &&    r,   get_max_height_widthr     s     ,222#5F6SFSyyF6S#T y
 ""	 
.33	3#5F6SFSyyF6S#T 
q "" =>O=PQRR	 7T6Ss   BBc                h    V ^8  d   QhR\         \        \        \        ,          3,          R\        /# rK   
annotationrm   dictr   rM   rg   rn   )rN   s   "r,   rO   rO     s(      4TE\8I3J t r+   c                    \        V \        4      '       do   R V 9   dh   RV 9   da   \        V R,          \        \        34      '       d>   \	        V R,          4      ^ 8X  g%   \        V R,          ^ ,          \        4      '       d   R# R# )image_idannotationsTFr5   r   rM   rg   lenr   s   &r,   "is_valid_annotation_coco_detectionr     si    :t$$*$Z'z-04-@@ 
=)*a/:j>WXY>Z\`3a3a r+   c                h    V ^8  d   QhR\         \        \        \        ,          3,          R\        /# r   r   )rN   s   "r,   rO   rO     s(      $sD5L7H2I d r+   c                    \        V \        4      '       dv   R V 9   do   RV 9   dh   RV 9   da   \        V R,          \        \        34      '       d>   \	        V R,          4      ^ 8X  g%   \        V R,          ^ ,          \        4      '       d   R# R# )r   segments_info	file_nameTFr   r   s   &r,   !is_valid_annotation_coco_panopticr     sq    :t$$*$z):%z/2T5MBB 
?+,1Z
?@[\]@^`d5e5e r+   c                ~    V ^8  d   QhR\         \        \        \        \        ,          3,          ,          R\
        /# rK   r   rm   r   r   r   rM   rg   rn   )rN   s   "r,   rO   rO     s2     O O(4TE\@Q;R2S OX\ Or+   c                 j    \         ;QJ d    R  V  4       F  '       d   K   R# 	  R# ! R  V  4       4      # )c              3   8   "   T F  p\        V4      x  K  	  R # 5ir4   )r   rR   anns   & r,   rS   3valid_coco_detection_annotations.<locals>.<genexpr>  s     N+31#66+rU   FTrV   r   s   &r,    valid_coco_detection_annotationsr     s+    3N+N33N3N3N+NNNr+   c                ~    V ^8  d   QhR\         \        \        \        \        ,          3,          ,          R\
        /# r   r   )rN   s   "r,   rO   rO     s2     N N$sD5L?P:Q1R NW[ Nr+   c                 j    \         ;QJ d    R  V  4       F  '       d   K   R# 	  R# ! R  V  4       4      # )c              3   8   "   T F  p\        V4      x  K  	  R # 5ir4   )r   r   s   & r,   rS   2valid_coco_panoptic_annotations.<locals>.<genexpr>  s     M#055rU   FTrV   r   s   &r,   valid_coco_panoptic_annotationsr     s+    3MM33M3M3MMMMr+   c                \    V ^8  d   QhR\         \        R3,          R\        R,          RR/# )rK   rF   r   timeoutNrm   r   r   float)rN   s   "r,   rO   rO     s5     * *''(*T\* *r+   c           
        \        \        R.4       \        V \        4      '       Ed:   V P	                  R4      '       g   V P	                  R4      '       dJ   \
        P                  P                  \        \        P                  ! WRR7      P                  4      4      p M\        P                  P                  V 4      '       d!   \
        P                  P                  V 4      p MV P	                  R4      '       d   V P                  R4      ^,          p  \         P"                  ! V P%                  4       4      p\
        P                  P                  \        V4      4      p M5\        V \
        P                  P                  4      '       g   \+        R4      h\
        P,                  P/                  V 4      p V P1                  R4      p V #   \&         d   p\)        RT  R	T 24      hR
p?ii ; i)a  
Loads `image` to a PIL Image.

Args:
    image (`str` or `PIL.Image.Image`):
        The image to convert to the PIL Image format.
    timeout (`float`, *optional*):
        The timeout value in seconds for the URL request.

Returns:
    `PIL.Image.Image`: A PIL Image.
visionhttp://https://Tr   follow_redirectsdata:image/,Incorrect image source. Must be a valid URL starting with `http://` or `https://`, a valid path to an image file, or a base64 encoded string. Got . Failed with NzuIncorrect format used for image. Should be an url linking to an image, a base64 string, a local path, or a PIL image.RGB)r   
load_imager5   r   
startswithr6   r7   openr   httpxgetcontentospathisfilesplitbase64decodebytesencode	ExceptionrC   	TypeErrorImageOpsexif_transposeconvert)rF   r   b64es   &&  r,   r   r     s     j8*-%I&&%*:*::*F*F IINN7599U^b+c+k+k#lmEWW^^E""IINN5)E..C(+((8		ws|4
 syy// D
 	
 LL''.EMM% EL    i  jo  ip  p~  @  ~A  B s   AG	 	G*G%%G*)backendsc                \    V ^8  d   QhR\         \        R3,          R\        R,          RR/# )rK   rF   r   r   Nrm   r   r   )rN   s   "r,   rO   rO     s5     *
 *
''(*
T\*
 *
r+   c                ,   ^ RI p\        V \        4      '       Edi   V P                  R4      '       g   V P                  R4      '       de   \        P
                  ! WRR7      P                  pVP                  ! \        V4      VP                  R7      p\        V\        P                  R7      # \        P                  P                  V 4      '       d   \        V \        P                  R7      # V P                  R4      '       d   V P!                  R	4      ^,          p  \"        P$                  ! V P'                  4       4      pTP                  ! \        T4      TP                  R7      p\        T\        P                  R7      # \        V \,        P.                  P.                  4      '       d:   \,        P0                  P3                  V 4      p \5        V P7                  R4      4      # \9        R4      h  \(         d   p\+        R
T  RT 24      hRp?ii ; i)aP  
Loads `image` directly to a `torch.Tensor` using torchvision.

Args:
    image (`str` or `PIL.Image.Image`):
        The image to convert to the PIL Image format.
    timeout (`float`, *optional*):
        The timeout value in seconds for the URL request.

Returns:
    `torch.Tensor`: A `[C, H, W]` uint8 tensor in RGB channel order.
Nr   r   Tr   )rp   )moder   r   r   r   r   z`Incorrect format used for image. Should be a URL, a local path, a base64 string, or a PIL image.)r>   r5   r   r   r   r   r   
frombuffer	bytearrayrq   r   r   r   r   r   r  r  r  r  r  r  rC   r6   r7   r  r	  r   r
  r  )rF   r   r>   rawbufr  s   &&    r,   load_image_as_tensorr    s   " %I&&%*:*::*F*F))ETJRRC""9S>EC-*;*;<<WW^^E""M,=,=>>..C(+((8
 ""9S>EC-*;*;<<	E399??	+	+++E2U]]5122n
 	
    i  jo  ip  p~  @  ~A  B s   $G2 2H=HHc                    V ^8  d   QhR\         \        \        \        R3,          R\        R,          R\         R\        R,          \        \        R,          ,          3,          /# )rK   rL   r   r   Nrm   )r   rM   rg   r   r   )rN   s   "r,   rO   rO   ,  sU     3 3$s$5563AF3
d#45tDAR<S7TTU3r+   c                l   \        V \        \        34      '       d~   \        V 4      '       dQ   \        V ^ ,          \        \        34      '       d.   V  UUu. uF  q" Uu. uF  p\	        W1R7      NK  	  upNK   	  upp# V  Uu. uF  p\	        W1R7      NK  	  up# \	        WR7      # u upi u uppi u upi )zLoads images, handling different levels of nesting.

Args:
  images: A single image, a list of images, or a list of lists of images to load.
  timeout: Timeout for loading images.

Returns:
  A single image, a list of images, a list of lists of images.
)r   )r5   rM   rg   r   r   )rL   r   image_grouprF   s   &&  r,   load_imagesr  ,  s     &4-((v;;:fQi$??eklekVa[Q[EZ7[QekllDJKF5Ju6FKK&22	 RlKs   B+B&3B+B1&B+c                @   V ^8  d   QhR\         R,          R\        R,          R\         R,          R\        \        \        ,          ,          R,          R\        \        \        ,          ,          R,          R\         R,          R\        \        \
        3,          \
        ,          R,          R	\         R,          R
\        \        \
        3,          R,          R\         R,          R\        \        \
        3,          R,          R\        RR\
        3,          R,          /# )rK   
do_rescaleNrescale_factordo_normalize
image_mean	image_stddo_padpad_sizedo_center_crop	crop_size	do_resizesizeresamplePILImageResamplingr   )rn   r   rM   r   r   rw   r   )rN   s   "r,   rO   rO   A  s    +^ +^t+^DL+^ ++^ U#d*	+^
 tE{"T)+^ 4K+^ 38ns"T)+^ 4K+^ CH~$+^ d{+^ sCx.4
+^ (*=sBCdJ+^r+   c                    V '       d   Vf   \        R4      hV'       d   Vf   \        R4      hV'       d   Ve   Vf   \        R4      hV'       d   Vf   \        R4      hV	'       d   V
e   Vf   \        R4      hR# R# )ao  
Checks validity of typically used arguments in an `ImageProcessor` `preprocess` method.
Raises `ValueError` if arguments incompatibility is caught.
Many incompatibilities are model-specific. `do_pad` sometimes needs `size_divisor`,
sometimes `size_divisibility`, and sometimes `size`. New models and processors added should follow
existing arguments when possible.

Nz=`rescale_factor` must be specified if `do_rescale` is `True`.zgDepending on the model, `size_divisor` or `pad_size` or `size` must be specified if `do_pad` is `True`.zP`image_mean` and `image_std` must both be specified if `do_normalize` is `True`.z<`crop_size` must be specified if `do_center_crop` is `True`.zA`size` and `resample` must be specified if `do_resize` is `True`.)rC   )r  r  r  r  r  r   r!  r"  r#  r$  r%  r&  s   &&&&&&&&&&&&r,   validate_preprocess_argumentsr)  A  s    , n,XYY(" u
 	
 +y/@kll)+WXX$*x/C\]] 0Dyr+   c                      a  ] tR tRt o RtR tRR ltR tV 3R lR ltRR	 lt	R
 t
RR ltRR ltR tR tRR ltRtV tR# )ImageFeatureExtractionMixinio  z<
Mixin that contain utilities for preparing image features.
c                    \        V\        P                  P                  \        P                  34      '       g,   \        V4      '       g   \        R \        V4       R24      hR# R# )z	Got type zU which is not supported, only `PIL.Image.Image`, `np.ndarray` and `torch.Tensor` are.N)r5   r6   r7   r]   r^   r   rC   rD   selfrF   s   &&r,   _ensure_format_supported4ImageFeatureExtractionMixin._ensure_format_supportedt  sW    %#))//2::!>??X]H^H^DK= )& &  I_?r+   Nc                   V P                  V4       \        V4      '       d   VP                  4       p\        V\        P
                  4      '       d   Vf,   \        VP                  ^ ,          \        P                  4      pVP                  ^8X  d,   VP                  ^ ,          R9   d   VP                  ^^^ 4      pV'       d
   V^,          pVP                  \        P                  4      p\        P                  P                  V4      # V# )a  
Converts `image` to a PIL Image. Optionally rescales it and puts the channel dimension back as the last axis if
needed.

Args:
    image (`PIL.Image.Image` or `numpy.ndarray` or `torch.Tensor`):
        The image to convert to the PIL Image format.
    rescale (`bool`, *optional*):
        Whether or not to apply the scaling factor (to make pixel values integers between 0 and 255). Will
        default to `True` if the image type is a floating type, `False` otherwise.
r   )r/  r   r?   r5   r]   r^   flatfloatingr{   r   	transposeastyperq   r6   r7   	fromarray)r.  rF   rescales   &&&r,   to_pil_image(ImageFeatureExtractionMixin.to_pil_image{  s     	%%e,5!!KKMEeRZZ(($UZZ]BKK@zzQ5;;q>V#;1a0LL*E99&&u--r+   c                    V P                  V4       \        V\        P                  P                  4      '       g   V# VP	                  R4      # )zo
Converts `PIL.Image.Image` to RGB format.

Args:
    image (`PIL.Image.Image`):
        The image to convert.
r   )r/  r5   r6   r7   r
  r-  s   &&r,   convert_rgb'ImageFeatureExtractionMixin.convert_rgb  s;     	%%e,%11L}}U##r+   c                d   < V ^8  d   QhRS[ P                  RS[S[,          RS[ P                  /# )rK   rF   scalerm   )r]   r^   r   rw   )rN   __classdict__s   "r,   rO   (ImageFeatureExtractionMixin.__annotate__  s.      RZZ  

 r+   c                4    V P                  V4       W,          # )z'
Rescale a numpy image by scale amount
)r/  )r.  rF   r>  s   &&&r,   r7  #ImageFeatureExtractionMixin.rescale  s     	%%e,}r+   c                   V P                  V4       \        V\        P                  P                  4      '       d   \        P
                  ! V4      p\        V4      '       d   VP                  4       pVf,   \        VP                  ^ ,          \        P                  4      MTpV'       d0   V P                  VP                  \        P                  4      R4      pV'       d%   VP                  ^8X  d   VP                  ^^ ^4      pV# )a{  
Converts `image` to a numpy array. Optionally rescales it and puts the channel dimension as the first
dimension.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image to convert to a NumPy array.
    rescale (`bool`, *optional*):
        Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.). Will
        default to `True` if the image is a PIL Image or an array/tensor of integers, `False` otherwise.
    channel_first (`bool`, *optional*, defaults to `True`):
        Whether or not to permute the dimensions of the image to put the channel dimension first.
p?)r/  r5   r6   r7   r]   r   r   r?   r2  integerr7  r5  float32r{   r4  )r.  rF   r7  channel_firsts   &&&&r,   r   *ImageFeatureExtractionMixin.to_numpy_array  s     	%%e,eSYY__--HHUOE5!!KKME;B?*UZZ]BJJ7PWLLbjj!99EEUZZ1_OOAq!,Er+   c                    V P                  V4       \        V\        P                  P                  4      '       d   V# \	        V4      '       d   VP                  ^ 4      pV# \        P                  ! V^ R7      pV# )z
Expands 2-dimensional `image` to 3 dimensions.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image to expand.
rZ   )r/  r5   r6   r7   r   	unsqueezer]   expand_dimsr-  s   &&r,   rK  'ImageFeatureExtractionMixin.expand_dims  se     	%%e, eSYY__--L5!!OOA&E  NN5q1Er+   c                   V P                  V4       \        V\        P                  P                  4      '       d   V P	                  VRR7      pMV'       d   \        V\
        P                  4      '       d1   V P                  VP                  \
        P                  4      R4      pM1\        V4      '       d!   V P                  VP                  4       R4      p\        V\
        P                  4      '       d   \        V\
        P                  4      '       g0   \
        P                  ! V4      P                  VP                  4      p\        V\
        P                  4      '       g0   \
        P                  ! V4      P                  VP                  4      pM\        V4      '       d   ^ RIp\        W%P                  4      '       gF   \        V\
        P                  4      '       d   VP                   ! V4      pMVP"                  ! V4      p\        W5P                  4      '       gF   \        V\
        P                  4      '       d   VP                   ! V4      pMVP"                  ! V4      pVP$                  ^8X  d6   VP&                  ^ ,          R9   d   WR,          ,
          VR,          ,          # W,
          V,          # )a  
Normalizes `image` with `mean` and `std`. Note that this will trigger a conversion of `image` to a NumPy array
if it's a PIL Image.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image to normalize.
    mean (`list[float]` or `np.ndarray` or `torch.Tensor`):
        The mean (per channel) to use for normalization.
    std (`list[float]` or `np.ndarray` or `torch.Tensor`):
        The standard deviation (per channel) to use for normalization.
    rescale (`bool`, *optional*, defaults to `False`):
        Whether or not to rescale the image to be between 0 and 1. If a PIL image is provided, scaling will
        happen automatically.
T)r7  NrD  r   )NNNNN)r/  r5   r6   r7   r   r]   r^   r7  r5  rF  r   r   r   rp   r>   r`   
from_numpytensorr{   r   )r.  rF   meanstdr7  r>   s   &&&&& r,   	normalize%ImageFeatureExtractionMixin.normalize  s     	%%e,eSYY__--''t'<E %,,U\\"**%=yI ''U[[]I>eRZZ((dBJJ//xx~,,U[[9c2::..hhsm**5;;7U##dLL11dBJJ// ++D1D <<-Dc<<00c2::..**3/C,,s+C::?u{{1~7//3}3EEELC''r+   c                (   Ve   TM\         P                  pV P                  V4       \        V\        P
                  P
                  4      '       g   V P                  V4      p\        V\        4      '       d   \        V4      p\        V\        4      '       g   \        V4      ^8X  d   V'       d-   \        V\        4      '       d   W"3MV^ ,          V^ ,          3pMVP                  w  rgWg8:  d   Wg3MWv3w  r\        V\        4      '       d   TMV^ ,          p
W8X  d   V# T
\        W,          V,          4      rVe7   WZ8:  d   \        RV RV 24      hW8  d   \        W[,          V,          4      TrWg8:  d   W3MW3pVP                  W#R7      # )a  
Resizes `image`. Enforces conversion of input to PIL.Image.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image to resize.
    size (`int` or `tuple[int, int]`):
        The size to use for resizing the image. If `size` is a sequence like (h, w), output size will be
        matched to this.

        If `size` is an int and `default_to_square` is `True`, then image will be resized to (size, size). If
        `size` is an int and `default_to_square` is `False`, then smaller edge of the image will be matched to
        this number. i.e, if height > width, then image will be rescaled to (size * height / width, size).
    resample (`int`, *optional*, defaults to `PILImageResampling.BILINEAR`):
        The filter to user for resampling.
    default_to_square (`bool`, *optional*, defaults to `True`):
        How to convert `size` when it is a single int. If set to `True`, the `size` will be converted to a
        square (`size`,`size`). If set to `False`, will replicate
        [`torchvision.transforms.Resize`](https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.Resize)
        with support for resizing only the smallest edge and providing an optional `max_size`.
    max_size (`int`, *optional*, defaults to `None`):
        The maximum allowed for the longer edge of the resized image: if the longer edge of the image is
        greater than `max_size` after being resized according to `size`, then the image is resized again so
        that the longer edge is equal to `max_size`. As a result, `size` might be overruled, i.e the smaller
        edge may be shorter than `size`. Only used if `default_to_square` is `False`.

Returns:
    image: A resized `PIL.Image.Image`.
zmax_size = zN must be strictly greater than the requested size for the smaller edge size = )r&  )r'  BILINEARr/  r5   r6   r7   r8  rM   rg   rw   r   r%  rC   resize)r.  rF   r%  r&  default_to_squaremax_sizer   r   shortlongrequested_new_short	new_shortnew_longs   &&&&&&       r,   rW  "ImageFeatureExtractionMixin.resize  sb   <  (389K9T9T%%e,%11%%e,EdD!!;DdC  CIN '1$'<'<|47DQRGBT %

16uovo.8s.C.Cda#/ L&93?R?Y\a?a;b8'6()( 4@@DvG   *.1(2F2Q.RT\805	,hEZ||D|44r+   c                N   V P                  V4       \        V\        4      '       g   W"3p\        V4      '       g!   \        V\        P
                  4      '       db   VP                  ^8X  d   V P                  V4      pVP                  ^ ,          R9   d   VP                  R,          MVP                  R,          pM&VP                  ^,          VP                  ^ ,          3pV^ ,          V^ ,          ,
          ^,          pWB^ ,          ,           pV^,          V^,          ,
          ^,          pWb^,          ,           p\        V\        P                  P                  4      '       d   VP                  WdWu34      # VP                  ^ ,          R9   pV'       gX   \        V\        P
                  4      '       d   VP                  ^^ ^4      p\        V4      '       d   VP                  ^^ ^4      pV^ 8  d0   WS^ ,          8:  d#   V^ 8  d   Ws^,          8:  d   VRWE1Wg13,          # VP                  RR \        V^ ,          V^ ,          4      \        V^,          V^,          4      3,           p	\        V\        P
                  4      '       d   \        P                   ! WR7      p
M"\        V4      '       d   VP#                  V	4      p
V	R,          V^ ,          ,
          ^,          pW^ ,          ,           pV	R,          V^,          ,
          ^,          pW^,          ,           pVX
RW1W13&   WK,          pW[,          pWm,          pW},          pV
R\        ^ V4      \%        V
P                  R,          V4      1\        ^ V4      \%        V
P                  R,          V4      13,          p
V
# )	a=  
Crops `image` to the given size using a center crop. Note that if the image is too small to be cropped to the
size given, it will be padded (so the returned result has the size asked).

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor` of shape (n_channels, height, width) or (height, width, n_channels)):
        The image to resize.
    size (`int` or `tuple[int, int]`):
        The size to which crop the image.

Returns:
    new_image: A center cropped `PIL.Image.Image` or `np.ndarray` or `torch.Tensor` of shape: (n_channels,
    height, width).
:r   NN:NrK   N.N)r   r   r   r   )r/  r5   rg   r   r]   r^   r{   rK  r   r%  r6   r7   cropr4  permuters   
zeros_like	new_zerosrr   )r.  rF   r%  image_shapetopbottomleftrightrG  	new_shape	new_imagetop_pad
bottom_padleft_pad	right_pads   &&&            r,   center_crop'ImageFeatureExtractionMixin.center_cropY  s    	%%e,$&&<D 5!!Zrzz%B%BzzQ((/-2[[^v-E%++b/5;;WY?K ::a=%**Q-8K1~Q'A-AwAa(Q.Aw eSYY__--::t%899 A&0 %,,1a0u%%aA. !8a.0TQY5XYNCZcj$*455 KK$DG[^(Dc$q'S^_`SaFb'cc	eRZZ((e=IU##	2IR=;q>1a71~-
bMKN2q81~-	AF	#w)8+==>Qs9??2#6??QPST]TcTcdfTginPoAoo
	 r+   c                    V P                  V4       \        V\        P                  P                  4      '       d   V P	                  V4      pVRRR1RR3,          # )ah  
Flips the channel order of `image` from RGB to BGR, or vice versa. Note that this will trigger a conversion of
`image` to a NumPy array if it's a PIL Image.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image whose color channels to flip. If `np.ndarray` or `torch.Tensor`, the channel dimension should
        be first.
NrN  r   )r/  r5   r6   r7   r   r-  s   &&r,   flip_channel_order.ImageFeatureExtractionMixin.flip_channel_order  sL     	%%e,eSYY__--''.ETrT1aZ  r+   c           	        Ve   TM\         P                  P                  pV P                  V4       \	        V\         P                  P                  4      '       g   V P                  V4      pVP                  W#WEWgR7      # )a  
Returns a rotated copy of `image`. This method returns a copy of `image`, rotated the given number of degrees
counter clockwise around its centre.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image to rotate. If `np.ndarray` or `torch.Tensor`, will be converted to `PIL.Image.Image` before
        rotating.

Returns:
    image: A rotated `PIL.Image.Image`.
)r&  expandcenter	translate	fillcolor)r6   r7   NEARESTr/  r5   r8  rotate)r.  rF   angler&  rv  rw  rx  ry  s   &&&&&&&&r,   r{  "ImageFeatureExtractionMixin.rotate  sj      (389J9J%%e,%11%%e,E||Vi  
 	
r+   r#   r4   )NT)F)NTN)Nr   NNN)r$   r%   r&   r'   __doc__r/  r8  r;  r7  r   rK  rS  rW  rp  rs  r{  r*   __classdictcell__r?  s   @r,   r+  r+  o  sQ     <$ @(2(hA5FIV!"
 
r+   r+  c                p    V ^8  d   QhR\         R\        \         R3,          R\        \        ,          RR/# )rK   annotation_formatsupported_annotation_formats.r   rm   N)r.   rg   rM   r   )rN   s   "r,   rO   rO     s?      '"'(8#(="> d 
	r+   c                     W9  d   \        R \         RV 24      hV \        P                  J d   \	        V4      '       g   \        R4      hV \        P
                  J d   \        V4      '       g   \        R4      hR# R# )zUnsupported annotation format: z must be one of zInvalid COCO detection annotations. Annotations must a dict (single image) or list of dicts (batch of images) with the following keys: `image_id` and `annotations`, with the latter being a list of annotations in the COCO format.zInvalid COCO panoptic annotations. Annotations must a dict (single image) or list of dicts (batch of images) with the following keys: `image_id`, `file_name` and `segments_info`, with the latter being a list of annotations in the COCO format.N)rC   rN   r.   r1   r   r2   r   )r  r  r   s   &&&r,   validate_annotationsr    s    
 <:6(BRSoRpqrr,;;;/<<B  ,:::.{;;M  < ;r+   c                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# )rK   valid_processor_keyscaptured_kwargs)rM   r   )rN   s   "r,   rO   rO     s&     L L$s) Ld3i Lr+   c                     \        V4      P                  \        V 4      4      pV'       d-   R P                  V4      p\        P	                  RV R24       R# R# )z, zUnused or unrecognized kwargs: rz   N)set
differencejoinr   r   )r  r  unused_keysunused_key_strs   &&  r,   validate_kwargsr    sJ    o&11#6J2KLK;/88HJK r+   c                      a  ] tR tRt o RtRtRtRtRtRt	Rt
R tRR ltR tR tR tR	 tR
 tV 3R lR ltV 3R lR ltV 3R ltRtV tR# )SizeDicti  z6
Hashable dictionary to store image size information.
Nc                X    \        W4      '       d   \        W4      # \        R V R24      h)Key z not found in SizeDict.)hasattrgetattrKeyErrorr.  keys   &&r,   __getitem__SizeDict.__getitem__  s-    44%%cU"9:;;r+   c                X    \        W4      '       d   \        W4      e   \        W4      # V# r4   r  r  )r.  r  defaults   &&&r,   r   SizeDict.get  s'    4'$"4"@4%%r+   c              #     "   \        V 4       F.  p\        WP                  4      pVf   K  VP                  V3x  K0  	  R # 5ir4   )r   r  name)r.  fvals   &  r,   __iter__SizeDict.__iter__  s4     A$'Cffck! s
   %AAc                    \        V P                  V P                  V P                  V P                  V P
                  V P                  34      # r4   )hashr   r   longest_edgeshortest_edger   r   )r.  s   &r,   __hash__SizeDict.__hash__  s<    T[[$**d.?.?ASASUYUdUdfjftftuvvr+   c                B    \        W4      ;'       d    \        W4      R J# r4   r  r  s   &&r,   __contains__SizeDict.__contains__  s    t!DDgd&8&DDr+   c                r    \        W4      '       g   \        R V R24      h\        P                  WV4       R# )r  z" is not a valid field of SizeDict.N)r  r  object__setattr__)r.  r  values   &&&r,   __setitem__SizeDict.__setitem__  s2    t!!T#&HIJJ4e,r+   c                  a a \        S\        4      '       d   \        S 4      S8H  # \        S\        4      '       d   \        ;QJ d     . V 3R  l\	        S 4       4       F  NK  	  5M! V 3R  l\	        S 4       4       4      \        ;QJ d"    . V3R l\	        S 4       4       F  NK  	  58H  # ! V3R l\	        S 4       4       4      8H  # \
        # )c              3   P   <"   T F  p\        SVP                  4      x  K  	  R # 5ir4   r  r  )rR   r  r.  s   & r,   rS   "SizeDict.__eq__.<locals>.<genexpr>  s     E1qvv..   #&c              3   P   <"   T F  p\        SVP                  4      x  K  	  R # 5ir4   r  )rR   r  others   & r,   rS   r    s#      O0<1qvv&&r  )r5   r   r  rg   r   NotImplemented)r.  r  s   ffr,   __eq__SizeDict.__eq__  s    eT"":&&eX&&5EtE55EtEE O06tO   O06tO J   r+   c                   < V ^8  d   QhRR/# )rK   rm   r  r#   )rN   r?  s   "r,   rO   SizeDict.__annotate__!  s      z r+   c                    \        V\        \        ,          4      '       d1   \        V 4      pVP                  \        V4      4       \        R/ VB # \        # )Nr#   )r5   r   r  updater  r.  r  mergeds   && r,   __or__SizeDict.__or__!  s@    eTH_--$ZFMM$u+&%f%%r+   c                    < V ^8  d   QhRS[ /# r   )r   )rN   r?  s   "r,   rO   r  (  s       r+   c                    \        V\        4      '       d(   \        V4      pVP                  \        V 4      4       V# \        # r4   )r5   r   r  r  r  s   && r,   __ror__SizeDict.__ror__(  s3    eT""%[FMM$t*%Mr+   c                   < V ^8  d   Qh/ S[ R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   S[ R,          ;R&   # )rK   Nr   r   r  r  r   r   )rw   )rN   r?  s   "r,   rO   r    sk      $J  :  *#  :$  d
!  Tz  r+   r#   r4   )r$   r%   r&   r'   r~  r   r   r  r  r   r   r  r   r  r  r  r  r  r  r  __annotate_func__r*   r  r  s   @r,   r  r    sk      FE#L $M!J I<

"wE-
  s  r+   r  )r   r4   )torchvision)NNNNNNNNNNNN)fr  r   collections.abcr   dataclassesr   r   ior   typingr   r   r   r?   r]   utilsr	   r
   r   r   r   r   r   r   r   utils.constantsr   r   r   r   r   r   utils.import_utilsr   	PIL.Imager6   PIL.ImageOpsr7   
Resamplingr'  torchvision.ior   r   torchvision.transformsr   !torchvision.transforms.functionalr   rz  NEAREST_EXACTBOXrV  HAMMINGBICUBICLANCZOSpil_torch_interpolation_mappingitemstorch_pil_interpolation_mappingr>   
get_loggerr$   r   r^   rM   rx   r    r.   r   r   rw   AnnotationTyper:   r<   rG   rI   rX   re   rh   rk   rt   r|   r   r   r   r   r   r   r   r   r(   r   r   r   r   r   r   r  r  r)  r+  r  r  r  )kvs   00r,   <module>r     s    	 $ )    
 
 
  ) --:8? 	""$5$C$C 1 5 5##%6%?%?""$5$=$=""$5$=$=""$5$=$='# 9X8]8]8_&`8_qt8_&`#&(#&(#  
		H	% rzz>48I3JDQSQ[Q[L\^bcq^rr

| 
$| $
 c39tDz112F ?LE,	5#L#LL$vN$ANF,D0!>8 brawaw# ON*Z 
#$*
 %*
Z3*+^\\
 \
~
2L = = =[ 'as   >K