ó
    pyüi¨¢  ã                   ó¶  • S SK r S SKrS SKJr  S SKJrJr  S SKJr  S SK	J
r
Jr  S SKrS SKrSSKJrJrJrJrJrJrJrJrJr  SSKJrJrJrJrJrJr  SS	K J!r!  \" 5       (       a  S SK"r#S SK$r#\#RJ                  RL                  r'\" 5       (       aÀ  S S
K(J)r)J*r*  S SK+J,r,  S SK-J.r.  \'R^                  \,R`                  \'Rb                  \,Rb                  \'Rd                  \,Rd                  \'Rf                  \,Rf                  \'Rh                  \,Rh                  \'Rj                  \,Rj                  0r6\6Ro                  5        V Vs0 s H  u  pX_M	     snn r8O0 r60 r8\" 5       (       a  S SK9r9\Rt                  " \;5      r<\S\Rz                  S\>S   \>\Rz                     \>S   4   r? " S S\5      r@ " S S\5      rA\B\C\D\C-  \>\B   -  4   rES rF " S S\5      rGS rHS rIS\>4S jrJS rKS rLS rMS\Rz                  S\N4S jrOSXS \DS\>\?   4S! jjrP SXS\>\?   \?-  S \DS\?4S" jjrQ SXS\>\?   \?-  S \DS\>\?   4S# jjrRS\Rz                  4S$ jrS SYS\Rz                  S%\D\T\DS&4   -  S-  S\@4S' jjrUSYS\Rz                  S(\@\C-  S-  S\D4S) jjrVSYS\Rz                  S*\@S-  S\T\D\D4   4S+ jjrWS,\T\D\D4   S-\DS.\DS\T\D\D4   4S/ jrXS0\\
   S\>\
   4S1 jrY\@R´                  4S\>\S\Rz                  4      S(\C\@-  S\>\D   4S2 jjr[S3\B\C\>\T-  4   S\N4S4 jr\S3\B\C\>\T-  4   S\N4S5 jr]S6\\B\C\>\T-  4      S\N4S7 jr^S6\\B\C\>\T-  4      S\N4S8 jr_ SYS\\CS4   S9\`S-  SS4S: jjra\!" S;S<9 SYS\\CS4   S9\`S-  SS4S= jj5       rb SYS\\>\T\CS4   S9\`S-  S\S\>S   \>\>S      4   4S> jjrc            SZS?\NS-  S@\`S-  SA\NS-  SB\`\>\`   -  S-  SC\`\>\`   -  S-  SD\NS-  SE\B\C\D4   \D-  S-  SF\NS-  SG\B\C\D4   S-  SH\NS-  SI\B\C\D4   S-  SJ\SKSL\D4   S-  4SM jjrd " SN SO5      reSP\ASQ\T\AS&4   S6\>\B   SS4SR jrfSS\>\C   ST\>\C   4SU jrg\" 5        " SV SW5      5       rhgs  snn f )[é    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_tensorzPIL.Image.Imageztorch.Tensorc                   ó   • \ rS rSrSrSrSrg)ÚChannelDimensionéU   Úchannels_firstÚchannels_last© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚFIRSTÚLASTÚ__static_attributes__r#   ó    ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/image_utils.pyr   r   U   s   † Ø€EØƒDr+   r   c                   ó   • \ rS rSrSrSrSrg)ÚAnnotationFormatéZ   Úcoco_detectionÚcoco_panopticr#   N)r$   r%   r&   r'   ÚCOCO_DETECTIONÚCOCO_PANOPTICr*   r#   r+   r,   r.   r.   Z   s   † Ø%€NØ#ƒMr+   r.   c                 ól   • [        5       =(       a$    [        U [        R                  R                  5      $ ©N)r   Ú
isinstanceÚPILÚImage©Úimgs    r,   Úis_pil_imager;   b   s   € ÜÓ ×E¤Z°´S·Y±Y·_±_Ó%EÐEr+   c                   ó    • \ rS rSrSrSrSrSrg)Ú	ImageTypeéf   ÚpillowÚtorchÚnumpyr#   N)r$   r%   r&   r'   r7   ÚTORCHÚNUMPYr*   r#   r+   r,   r=   r=   f   s   † Ø
€CØ€EØƒEr+   r=   c                 óð   • [        U 5      (       a  [        R                  $ [        U 5      (       a  [        R                  $ [        U 5      (       a  [        R                  $ [        S[        U 5       35      e)NzUnrecognized image type )	r;   r=   r7   r   rB   r   rC   Ú
ValueErrorÚtype©Úimages    r,   Úget_image_typerI   l   sX   € Ü�E×ÑÜ�}‰}ÐÜ�u×ÑÜ�‰ÐÜ�e×ÑÜ�‰ÐÜ
Ð/´°U³¨}Ð=Ó
>Ð>r+   c                 ó`   • [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ r5   )r;   r   r   r9   s    r,   Úis_valid_imagerK   v   s!   € Ü˜Ó×K¤¨sÓ 3×K´ÀsÓ7KÐKr+   Úimagesc                 ó8   • U =(       a    [        S U  5       5      $ )Nc              3   ó8   #   • U  H  n[        U5      v •  M     g 7fr5   )rK   )Ú.0rH   s     r,   Ú	<genexpr>Ú*is_valid_list_of_images.<locals>.<genexpr>{   s   é € ÐDºV°Eœ.¨×/Ð/ºVùó   ‚©Úall)rL   s    r,   Úis_valid_list_of_imagesrU   z   s   € Ø×D”cÑD¹VÓDÓDÐDr+   c                 óV  • [        U S   [        5      (       a  U  VVs/ s H  o  H  o"PM     M     snn$ [        U S   [        R                  5      (       a  [        R                  " U SS9$ [        U S   [
        R                  5      (       a  [
        R                  " U SS9$ g s  snnf )Nr   ©Úaxis)Údim)r6   ÚlistÚnpÚndarrayÚconcatenater@   ÚTensorÚcat)Ú
input_listÚsublistÚitems      r,   Úconcatenate_listrc   ~   s‡   € Ü�*˜Q‘-¤×&Ñ&Ù$.ÔC¢J˜»7°4’¹7‘¡JÒCÐCÜ	�J˜q‘M¤2§:¡:×	.Ñ	.Ü�~Š~˜j¨qÑ1Ð1Ü	�J˜q‘M¤5§<¡<×	0Ñ	0Ü�yŠy˜¨Ñ+Ð+ð 
1ùó Ds   žB%c                 ó”   • [        U [        [        45      (       a  U  H  n[        U5      (       a  M    g   g[	        U 5      (       d  gg)NFT)r6   rZ   ÚtupleÚvalid_imagesrK   )Úimgsr:   s     r,   rf   rf   ‡   sC   € ä�$œœu˜×&Ñ&ÛˆCÜ ×$Ó$Ùñ ð ô ˜D×!Ñ!ØØr+   c                 óV   • [        U [        [        45      (       a  [        U S   5      $ g)Nr   F)r6   rZ   re   rK   r9   s    r,   Ú
is_batchedri   “   s%   € Ü�#œœe�}×%Ñ%Ü˜c !™fÓ%Ð%Ør+   rH   Úreturnc                 ó²   • U R                   [        R                  :X  a  g[        R                  " U 5      S:¬  =(       a    [        R                  " U 5      S:*  $ )zN
Checks to see whether the pixel values have already been rescaled to [0, 1].
Fr   r	   )Údtyper[   Úuint8ÚminÚmaxrG   s    r,   Úis_scaled_imagerp   ™   s>   € ð ‡{�{”b—h‘hÓØô �6Š6�%‹=˜AÑ×4¤"§&¢&¨£-°1Ñ"4Ð4r+   Úexpected_ndimsc           	      óJ  • [        U 5      (       a  U $ [        U 5      (       a  U /$ [        U 5      (       aW  U R                  US-   :X  a  [	        U 5      n U $ U R                  U:X  a  U /n U $ [        SUS-    SU SU R                   S35      e[        S[        U 5       S35      e)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.
r	   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 Ú.)ri   r;   rK   ÚndimrZ   rE   rF   )rL   rq   s     r,   Úmake_list_of_imagesru   ¤   sÎ   € ô �&×ÑØˆô �F×Ñàˆxˆä�f×ÑØ�;‰;˜.¨1Ñ,Ó,ä˜&“\ˆFð ˆð �[‰[˜NÓ*à�XˆFð ˆô	 Ø7¸ÈÑ8JÐ7KÈ4ÐP^ÐO_ð `Ø—K‘K�= ð.óð ô
 Ø
gÔhlÐmsÓhtÐguÐuvÐwóð r+   c                 ó°  • [        U [        [        45      (       aK  [        S U  5       5      (       a4  [        S U  5       5      (       a  U  VVs/ s H  o"  H  o3PM     M     snn$ [        U [        [        45      (       ak  [	        U 5      (       a[  [        U S   5      (       d  U S   R                  U:X  a  U $ U S   R                  US-   :X  a  U  VVs/ s H  o"  H  o3PM     M     snn$ [        U 5      (       aA  [        U 5      (       d  U R                  U:X  a  U /$ U R                  US-   :X  a  [        U 5      $ [        SU  35      es  snnf s  snnf )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   #   • U  H  n[        U[        [        45      v •  M     g 7fr5   ©r6   rZ   re   ©rO   Úimages_is     r,   rP   Ú+make_flat_list_of_images.<locals>.<genexpr>Ü   ó   é € ÐKÂF¸”
˜8¤d¬E ]×3Ð3ÂFùó   ‚#%c              3   óT   #   • U  H  n[        U5      =(       d    U(       + v •  M      g 7fr5   ©rU   ry   s     r,   rP   r{   Ý   ó"   é € ÐYÒRXÀhÔ'¨Ó1×A¸´\ÔAÒRXùó   ‚&(r   r	   z*Could not make a flat list of images from ©	r6   rZ   re   rT   rU   r;   rt   rK   rE   )rL   rq   Úimg_listr:   s       r,   Úmake_flat_list_of_imagesr„   Ê   s(  € ô" 	�6œD¤%˜=×)Ñ)ÜÑKÁFÓK×KÑKÜÑYÑRXÓY×YÑYá$*Ô?¢F˜³h¨s’±h‘¡FÒ?Ð?ä�&œ4¤˜-×(Ñ(Ô-DÀV×-LÑ-LÜ˜˜q™	×"Ñ" f¨Q¡i§n¡n¸Ó&FØˆMØ�!‰9�>‰>˜^¨aÑ/Ó/Ù(.ÔCª˜H»(°3’C¹(‘C©ÒCÐCä�f×ÑÜ˜×Ñ 6§;¡;°.Ó#@Ø�8ˆOØ�;‰;˜.¨1Ñ,Ó,Ü˜“<Ðä
ÐAÀ&ÀÐJÓ
KÐKùó @ùó Ds   ÁEÃEc                 ój  • [        U [        [        45      (       a0  [        S U  5       5      (       a  [        S U  5       5      (       a  U $ [        U [        [        45      (       ak  [	        U 5      (       a[  [        U S   5      (       d  U S   R                  U:X  a  U /$ U S   R                  US-   :X  a  U  Vs/ s H  n[        U5      PM     sn$ [        U 5      (       aC  [        U 5      (       d  U R                  U:X  a  U //$ U R                  US-   :X  a  [        U 5      /$ [        S5      es  snf )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   #   • U  H  n[        U[        [        45      v •  M     g 7fr5   rx   ry   s     r,   rP   Ú-make_nested_list_of_images.<locals>.<genexpr>  r|   r}   c              3   óT   #   • U  H  n[        U5      =(       d    U(       + v •  M      g 7fr5   r   ry   s     r,   rP   r‡     r€   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   rq   rH   s      r,   Úmake_nested_list_of_imagesr‰   ð   s	  € ô  	�6œD¤%˜=×)Ñ)ÜÑKÁFÓK×KÑKÜÑYÑRXÓY×YÑYàˆô �&œ4¤˜-×(Ñ(Ô-DÀV×-LÑ-LÜ˜˜q™	×"Ñ" f¨Q¡i§n¡n¸Ó&FØ�8ˆOØ�!‰9�>‰>˜^¨aÑ/Ó/Ù-3Ó4ªV E”D˜–K©VÑ4Ð4ô �f×ÑÜ˜×Ñ 6§;¡;°.Ó#@Ø�H�:ÐØ�;‰;˜.¨1Ñ,Ó,Ü˜“L�>Ð!ä
ÐtÓ
uÐuùò 5s   Â:D0c                 ó  • [        U 5      (       d  [        S[        U 5       35      e[        5       (       a?  [	        U [
        R                  R                  5      (       a  [        R                  " U 5      $ [        U 5      $ )NzInvalid image type: )
rK   rE   rF   r   r6   r7   r8   r[   Úarrayr   r9   s    r,   Úto_numpy_arrayrŒ     sY   € Ü˜#×ÑÜÐ/´°S³	¨{Ð;Ó<Ð<ä×Ñ¤¨C´·±·±×!AÑ!AÜ�xŠx˜‹}ÐÜ�C‹=Ðr+   Únum_channels.c                 óF  • Ub  UOSn[        U[        5      (       a  U4OUnU R                  S:X  a  Su  p#OBU R                  S:X  a  Su  p#O-U R                  S:X  a  Su  p#O[        SU R                   35      eU R                  U   U;   aF  U R                  U   U;   a3  [
        R                  SU R                   S	35        [        R                  $ U R                  U   U;   a  [        R                  $ U R                  U   U;   a  [        R                  $ [        S
5      e)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.
©r	   é   r�   )r   é   é   é   )r‘   r’   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)
r6   Úintrt   rE   ÚshapeÚloggerÚwarningr   r(   r)   )rH   r�   Ú	first_dimÚlast_dims       r,   Úinfer_channel_dimension_formatrš      s  € ð $0Ñ#;‘<À€LÜ&0°¼s×&CÑ&C�L‘?È€Là‡z�z�QƒØ"Ñˆ	�8Ø	�‰�q‹Ø"Ñˆ	�8Ø	�‰�q‹Ø"Ñˆ	�8äÐCÀEÇJÁJÀ<ÐPÓQÐQà‡{�{�9Ñ Ó-°%·+±+¸hÑ2GÈ<Ó2WÜ�‰ØBÀ5Ç;Á;À-ð  PJð  Kô	
ô  ×%Ñ%Ð%Ø	�‰�YÑ	 <Ó	/Ü×%Ñ%Ð%Ø	�‰�XÑ	 ,Ó	.Ü×$Ñ$Ð$Ü
Ð?Ó
@Ð@r+   Úinput_data_formatc                 óÆ   • Uc  [        U 5      nU[        R                  :X  a  U R                  S-
  $ U[        R                  :X  a  U R                  S-
  $ [        SU 35      e)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.
r�   r	   úUnsupported data format: )rš   r   r(   rt   r)   rE   )rH   r›   s     r,   Úget_channel_dimension_axisrž   G  sd   € ð Ñ Ü:¸5ÓAÐØÔ,×2Ñ2Ó2Ø�z‰z˜A‰~ÐØ	Ô.×3Ñ3Ó	3Ø�z‰z˜A‰~ÐÜ
Ð0Ð1BÐ0CÐDÓ
EÐEr+   Úchannel_dimc                 ó  • Uc  [        U 5      nU[        R                  :X  a  U R                  S   U R                  S   4$ U[        R                  :X  a  U R                  S   U R                  S   4$ [        SU 35      e)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)   rE   )rH   rŸ   s     r,   Úget_image_sizer¤   ]  s{   € ð ÑÜ4°UÓ;ˆàÔ&×,Ñ,Ó,Ø�{‰{˜2‰ §¡¨B¡Ð/Ð/Ø	Ô(×-Ñ-Ó	-Ø�{‰{˜2‰ §¡¨B¡Ð/Ð/äÐ4°[°MÐBÓCÐCr+   Ú
image_sizeÚ
max_heightÚ	max_widthc                 ój   • U u  p4X-  nX$-  n[        XV5      n[        X7-  5      n[        XG-  5      n	X‰4$ )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.
)rn   r”   )
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   € ð, �M€FØÑ&€LØÑ#€KÜ�LÓ.€IÜ�VÑ'Ó(€JÜ�EÑ%Ó&€IØÐ Ð r+   Úvaluesc                 óP   • [        U 6  Vs/ s H  n[        U5      PM     sn$ s  snf )zG
Return the maximum value across all indices of an iterable of values.
)Úzipro   )r±   Úvalues_is     r,   Úmax_across_indicesrµ   ”  s$   € ô +.¨v©,Ó7ª,˜hŒC�ŽM©,Ñ7Ð7ùÒ7s   ‹#c                 ó.  • U[         R                  :X  a+  [        U  Vs/ s H  o"R                  PM     sn5      u  p4nXE4$ U[         R                  :X  a+  [        U  Vs/ s H  o"R                  PM     sn5      u  pEnXE4$ [        SU 35      es  snf s  snf )z@
Get the maximum height and width across all images in a batch.
z"Invalid channel dimension format: )r   r(   rµ   r•   r)   rE   )rL   r›   r:   Ú_r¦   r§   s         r,   Úget_max_height_widthr¸   ›  sš   € ð Ô,×2Ñ2Ó2Ü#5ÉFÓ6SÊFÀS·y´yÉFÑ6SÓ#TÑ ˆ�yð
 Ð"Ð"ð	 
Ô.×3Ñ3Ó	3Ü#5ÉFÓ6SÊFÀS·y´yÉFÑ6SÓ#TÑ ˆ
˜qð Ð"Ð"ô Ð=Ð>OÐ=PÐQÓRÐRùò	 7Tùâ6Ss   žBÁBÚ
annotationc                 óÞ   • [        U [        5      (       aX  SU ;   aR  SU ;   aL  [        U S   [        [        45      (       a.  [	        U S   5      S:X  d  [        U S   S   [        5      (       a  gg)NÚimage_idÚannotationsr   TF©r6   ÚdictrZ   re   Úlen©r¹   s    r,   Ú"is_valid_annotation_coco_detectionrÁ   ª  si   € ä�:œt×$Ñ$Ø˜*Ó$Ø˜ZÓ'Ü�z -Ñ0´4¼°-×@Ñ@ô �
˜=Ñ)Ó*¨aÓ/´:¸jÈÑ>WÐXYÑ>ZÔ\`×3aÑ3að Ør+   c                 óê   • [        U [        5      (       a^  SU ;   aX  SU ;   aR  SU ;   aL  [        U S   [        [        45      (       a.  [	        U S   5      S:X  d  [        U S   S   [        5      (       a  gg)Nr»   Úsegments_infoÚ	file_namer   TFr½   rÀ   s    r,   Ú!is_valid_annotation_coco_panopticrÅ   ¹  sq   € ä�:œt×$Ñ$Ø˜*Ó$Ø˜zÓ)Ø˜:Ó%Ü�z /Ñ2´T¼5°M×BÑBô �
˜?Ñ+Ó,°Ó1´ZÀ
È?Ñ@[Ð\]Ñ@^Ô`d×5eÑ5eð Ør+   r¼   c                 ó&   • [        S U  5       5      $ )Nc              3   ó8   #   • U  H  n[        U5      v •  M     g 7fr5   )rÁ   ©rO   Úanns     r,   rP   Ú3valid_coco_detection_annotations.<locals>.<genexpr>Ê  s   é € ÐNÂ+¸3Ô1°#×6Ð6Â+ùrR   rS   ©r¼   s    r,   Ú valid_coco_detection_annotationsrÌ   É  s   € ÜÑNÁ+ÓNÓNÐNr+   c                 ó&   • [        S U  5       5      $ )Nc              3   ó8   #   • U  H  n[        U5      v •  M     g 7fr5   )rÅ   rÈ   s     r,   rP   Ú2valid_coco_panoptic_annotations.<locals>.<genexpr>Î  s   é € ÐMÂ¸#Ô0°×5Ð5ÂùrR   rS   rË   s    r,   Úvalid_coco_panoptic_annotationsrÐ   Í  s   € ÜÑMÁÓMÓMÐMr+   Útimeoutc           
      ó¾  • [        [        S/5        [        U [        5      (       Ga.  U R	                  S5      (       d  U R	                  S5      (       aF  [
        R                  R                  [        [        R                  " XSS9R                  5      5      n Oð[        R                  R                  U 5      (       a   [
        R                  R                  U 5      n O¬U R	                  S5      (       a  U R                  S5      S   n  [         R"                  " U R%                  5       5      n[
        R                  R                  [        U5      5      n O4[        U [
        R                  R                  5      (       d  [+        S5      e[
        R,                  R/                  U 5      n U R1                  S5      n U $ ! [&         a  n[)        S	U  S
U 35      eSnAff = f)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/Ú,r	   ú’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_imager6   ÚstrÚ
startswithr7   r8   Úopenr   ÚhttpxÚgetÚcontentÚosÚpathÚisfileÚsplitÚbase64ÚdecodebytesÚencodeÚ	ExceptionrE   Ú	TypeErrorÚImageOpsÚexif_transposeÚconvert)rH   rÑ   Úb64Úes       r,   rÝ   rÝ   Ñ  s„  € ô  ”j 8 *Ô-Ü�%œ×ÒØ×Ñ˜I×&Ñ&¨%×*:Ñ*:¸:×*FÑ*Fô —I‘I—N‘N¤7¬5¯9ª9°UÐ^bÑ+c×+kÑ+kÓ#lÓm‰EÜ�W‰W�^‰^˜E×"Ñ"Ü—I‘I—N‘N 5Ó)‰Eà×Ñ ×.Ñ.ØŸ™ CÓ(¨Ñ+�ðÜ×(Ò(¨¯©«Ó8�ÜŸ	™	Ÿ™¤w¨s£|Ó4‘ô
 ˜œsŸy™yŸ™×/Ñ/Üð Dó
ð 	
ô �L‰L×'Ñ'¨Ó.€EØ�M‰M˜%Ó €EØ€Løô ó Ü ð ið  joð  ipð  p~ð  @ð  ~Að  Bóð ûðús   Ä	AF< Æ<
GÇGÇG)Útorchvision)Úbackendsc                 óò  • SSK n[        U [        5      (       GaN  U R                  S5      (       d  U R                  S5      (       a[  [        R
                  " XSS9R                  nUR                  " [        U5      UR                  S9n[        U[        R                  S9$ [        R                  R                  U 5      (       a  [        U [        R                  S9$ U R                  S	5      (       a  U R!                  S
5      S   n  ["        R$                  " U R'                  5       5      nUR                  " [        U5      UR                  S9n[        U[        R                  S9$ [        U [,        R.                  R.                  5      (       a9  [,        R0                  R3                  U 5      n [5        U R7                  S5      5      $ [9        S5      e! [(         a  n[+        SU  SU 35      eSnAff = f)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.
r   NrÔ   rÕ   TrÖ   )rl   )ÚmoderØ   rÙ   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@   r6   rÞ   rß   rá   râ   rã   Ú
frombufferÚ	bytearrayrm   r   r   rÜ   rä   rå   ræ   rç   rè   ré   rê   rë   rE   r7   r8   rí   rî   r   rï   rì   )rH   rÑ   r@   ÚrawÚbufrñ   s         r,   Úload_image_as_tensorrú   þ  s§  € ó" ä�%œ×ÒØ×Ñ˜I×&Ñ&¨%×*:Ñ*:¸:×*FÑ*FÜ—)’)˜EÀTÑJ×RÑRˆCØ×"Ò"¤9¨S£>¸¿¹ÑEˆCÜ ¬-×*;Ñ*;Ñ<Ð<Ü�W‰W�^‰^˜E×"Ñ"Ü ¬M×,=Ñ,=Ñ>Ð>à×Ñ ×.Ñ.ØŸ™ CÓ(¨Ñ+�ðÜ×(Ò(¨¯©«Ó8�ð
 ×"Ò"¤9¨S£>¸¿¹ÑEˆCÜ ¬-×*;Ñ*;Ñ<Ð<Ü	�Eœ3Ÿ9™9Ÿ?™?×	+Ñ	+Ü—‘×+Ñ+¨EÓ2ˆÜ˜UŸ]™]¨5Ó1Ó2Ð2äØnó
ð 	
øô ó Ü ð ið  joð  ipð  p~ð  @ð  ~Að  Bóð ûðús   Ä	$G Ç
G6Ç G1Ç1G6c                 óR  • [        U [        [        45      (       at  [        U 5      (       aJ  [        U S   [        [        45      (       a,  U  VVs/ s H  o" Vs/ s H  n[	        X1S9PM     snPM     snn$ U  Vs/ s H  n[	        X1S9PM     sn$ [	        XS9$ s  snf s  snnf s  snf )zýLoads 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   )rÑ   )r6   rZ   re   r¿   rÝ   )rL   rÑ   Úimage_grouprH   s       r,   Úload_imagesrý   ,  s�   € ô �&œ4¤˜-×(Ñ(Üˆv�;‰;œ: f¨Q¡i´$¼°×?Ñ?ÙekÔlÒekÐVaÀ[ÓQÂ[¸E”Z Ô7Á[ÔQÑekÒlÐláDJÓKÂF¸5”J˜uÔ6ÁFÑKÐKä˜&Ñ2Ð2ùò	 RùÓlùâKs   Á	BÁBÁ+BÁ:B$ÂBÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚdo_padÚpad_sizeÚdo_center_cropÚ	crop_sizeÚ	do_resizeÚsizeÚresampleÚPILImageResamplingr   c                 óä   • U (       a  Uc  [        S5      eU(       a  Uc  [        S5      eU(       a  Ub  Uc  [        S5      eU(       a  Uc  [        S5      eU	(       a  U
b  Uc  [        S5      egg)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`.)rE   )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                   ó¬   • \ rS rSrSrS rSS jrS rS\R                  S\
\-  S	\R                  4S
 jrSS jrS rSS jrSS jrS rS rSS jrSrg)ÚImageFeatureExtractionMixinio  z<
Mixin that contain utilities for preparing image features.
c                 óÈ   • [        U[        R                  R                  [        R                  45      (       d)  [        U5      (       d  [        S[        U5       S35      eg g )Nz	Got type zU which is not supported, only `PIL.Image.Image`, `np.ndarray` and `torch.Tensor` are.)r6   r7   r8   r[   r\   r   rE   rF   ©ÚselfrH   s     r,   Ú_ensure_format_supportedÚ4ImageFeatureExtractionMixin._ensure_format_supportedt  sW   € Ü˜%¤#§)¡)§/¡/´2·:±:Ð!>×?Ñ?ÌÐX]×H^ÑH^ÜØœD ›K˜=ð )&ð &óð ð I_Ð?r+   Nc                 óú  • U R                  U5        [        U5      (       a  UR                  5       n[        U[        R
                  5      (       aª  Uc'  [        UR                  S   [        R                  5      nUR                  S:X  a&  UR                  S   S;   a  UR                  SSS5      nU(       a  US-  nUR                  [        R                  5      n[        R                  R                  U5      $ U$ )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	   r‘   éÿ   )r  r   rA   r6   r[   r\   ÚflatÚfloatingrt   r•   Ú	transposeÚastyperm   r7   r8   Ú	fromarray)r  rH   Úrescales      r,   Úto_pil_imageÚ(ImageFeatureExtractionMixin.to_pil_image{  sº   € ð 	×%Ñ% eÔ,ä˜5×!Ñ!Ø—K‘K“MˆEä�eœRŸZ™Z×(Ñ(Ø‰ä$ U§Z¡Z°¡]´B·K±KÓ@�à�z‰z˜Q‹ 5§;¡;¨q¡>°VÓ#;ØŸ™¨¨1¨aÓ0�ÞØ ™�Ø—L‘L¤§¡Ó*ˆEÜ—9‘9×&Ñ& uÓ-Ð-Øˆr+   c                 óœ   • U R                  U5        [        U[        R                  R                  5      (       d  U$ UR	                  S5      $ )zo
Converts `PIL.Image.Image` to RGB format.

Args:
    image (`PIL.Image.Image`):
        The image to convert.
rÜ   )r  r6   r7   r8   rï   r  s     r,   Úconvert_rgbÚ'ImageFeatureExtractionMixin.convert_rgb™  s;   € ð 	×%Ñ% eÔ,Ü˜%¤§¡§¡×1Ñ1ØˆLà�}‰}˜UÓ#Ð#r+   rH   Úscalerj   c                 ó,   • U R                  U5        X-  $ )z'
Rescale a numpy image by scale amount
)r  )r  rH   r!  s      r,   r  Ú#ImageFeatureExtractionMixin.rescale§  s   € ð 	×%Ñ% eÔ,Ø‰}Ðr+   c                 óþ  • U R                  U5        [        U[        R                  R                  5      (       a  [        R
                  " U5      n[        U5      (       a  UR                  5       nUc'  [        UR                  S   [        R                  5      OUnU(       a/  U R                  UR                  [        R                  5      S5      nU(       a#  UR                  S:X  a  UR                  SSS5      nU$ )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.
r   çp?r�   r‘   r	   )r  r6   r7   r8   r[   r‹   r   rA   r  Úintegerr  r  Úfloat32rt   r  )r  rH   r  Úchannel_firsts       r,   rŒ   Ú*ImageFeatureExtractionMixin.to_numpy_array®  s­   € ð 	×%Ñ% eÔ,ä�eœSŸY™YŸ_™_×-Ñ-Ü—H’H˜U“OˆEä˜5×!Ñ!Ø—K‘K“MˆEà;B¹?”*˜UŸZ™Z¨™]¬B¯J©JÔ7ÐPWˆæØ—L‘L §¡¬b¯j©jÓ!9¸9ÓEˆEæ˜UŸZ™Z¨1›_Ø—O‘O A q¨!Ó,ˆEàˆr+   c                 óî   • U R                  U5        [        U[        R                  R                  5      (       a  U$ [	        U5      (       a  UR                  S5      nU$ [        R                  " USS9nU$ )z•
Expands 2-dimensional `image` to 3 dimensions.

Args:
    image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
        The image to expand.
r   rW   )r  r6   r7   r8   r   Ú	unsqueezer[   Úexpand_dimsr  s     r,   r,  Ú'ImageFeatureExtractionMixin.expand_dimsÎ  se   € ð 	×%Ñ% eÔ,ô �eœSŸY™YŸ_™_×-Ñ-ØˆLä˜5×!Ñ!Ø—O‘O AÓ&ˆEð ˆô —N’N 5¨qÑ1ˆEØˆr+   c                 ó>  • U R                  U5        [        U[        R                  R                  5      (       a  U R	                  USS9nO†U(       a  [        U[
        R                  5      (       a0  U R                  UR                  [
        R                  5      S5      nO0[        U5      (       a   U R                  UR                  5       S5      n[        U[
        R                  5      (       a�  [        U[
        R                  5      (       d/  [
        R                  " U5      R                  UR                  5      n[        U[
        R                  5      (       d/  [
        R                  " U5      R                  UR                  5      nOÐ[        U5      (       aÀ  SSKn[        X%R                  5      (       dD  [        U[
        R                  5      (       a  UR                   " U5      nOUR"                  " U5      n[        X5R                  5      (       dD  [        U[
        R                  5      (       a  UR                   " U5      nOUR"                  " U5      nUR$                  S:X  a*  UR&                  S   S;   a  XSS2SS4   -
  USS2SS4   -  $ X-
  U-  $ )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)r  r%  r   Nr�   r�   )r  r6   r7   r8   rŒ   r[   r\   r  r  r'  r   Úfloatr‹   rl   r@   r^   Ú
from_numpyÚtensorrt   r•   )r  rH   ÚmeanÚstdr  r@   s         r,   Ú	normalizeÚ%ImageFeatureExtractionMixin.normalizeâ  sÑ  € ð  	×%Ñ% eÔ,ä�eœSŸY™YŸ_™_×-Ñ-Ø×'Ñ'¨°tÐ'Ð<‰Eö Ü˜%¤§¡×,Ñ,ØŸ™ U§\¡\´"·*±*Ó%=¸yÓI‘Ü  ×'Ñ'ØŸ™ U§[¡[£]°IÓ>�ä�eœRŸZ™Z×(Ñ(Ü˜d¤B§J¡J×/Ñ/Ü—x’x “~×,Ñ,¨U¯[©[Ó9�Ü˜c¤2§:¡:×.Ñ.Ü—h’h˜s“m×*Ñ*¨5¯;©;Ó7�øÜ˜U×#Ñ#Ûä˜d§L¡L×1Ñ1Ü˜d¤B§J¡J×/Ñ/Ø ×+Ò+¨DÓ1‘Dà Ÿ<š<¨Ó-�DÜ˜c§<¡<×0Ñ0Ü˜c¤2§:¡:×.Ñ.Ø×*Ò*¨3Ó/‘CàŸ,š, sÓ+�Cà�:‰:˜‹?˜uŸ{™{¨1™~°Ó7Ø¢ D¨$ Ñ/Ñ/°3²q¸$À°}Ñ3EÑEÐEà‘L CÑ'Ð'r+   c                 óÎ  • Ub  UO[         R                  nU R                  U5        [        U[        R
                  R
                  5      (       d  U R                  U5      n[        U[        5      (       a  [        U5      n[        U[        5      (       d  [        U5      S:X  a³  U(       a#  [        U[        5      (       a  X"4O	US   US   4nO‰UR                  u  pgXg::  a  Xg4OXv4u  p‰[        U[        5      (       a  UOUS   n
XŠ:X  a  U$ U
[        X©-  U-  5      pËUb,  XZ::  a  [        SU SU 35      eXÅ:”  a  [        X[-  U-  5      UpËXg::  a  X¼4OXË4nUR                  X#S9$ )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`.
r	   r   zmax_size = zN must be strictly greater than the requested size for the smaller edge size = )r	  )r
  ÚBILINEARr  r6   r7   r8   r  rZ   re   r”   r¿   r  rE   Úresize)r  rH   r  r	  Údefault_to_squareÚmax_sizerª   r©   ÚshortÚlongÚrequested_new_shortÚ	new_shortÚnew_longs                r,   r8  Ú"ImageFeatureExtractionMixin.resize  sb  € ð<  (Ñ3‘8Ô9K×9TÑ9Tˆà×%Ñ% eÔ,ä˜%¤§¡§¡×1Ñ1Ø×%Ñ% eÓ,ˆEä�dœD×!Ñ!Ü˜“;ˆDä�dœC× Ñ ¤C¨£I°£NÞ Ü'1°$¼×'<Ñ'<˜‘|À4ÈÁ7ÈDÐQRÉGÐBT‘à %§
¡
‘�à16³˜u™oÀvÀo‘�Ü.8¸¼s×.CÑ.C¡dÈÈaÉÐ#àÓ/Ø �Là&9¼3Ð?RÑ?YÐ\aÑ?aÓ;b˜8àÑ'ØÓ6Ü(Ø)¨(¨ð 4@Ø@D¸vðGóð ð  Ó*Ü.1°(Ñ2FÈÑ2QÓ.RÐT\ 8à05³˜	Ñ,ÀhÐEZ�à�|‰|˜Dˆ|Ð4Ð4r+   c                 óÂ  • U R                  U5        [        U[        5      (       d  X"4n[        U5      (       d  [        U[        R
                  5      (       aS  UR                  S:X  a  U R                  U5      nUR                  S   S;   a  UR                  SS OUR                  SS nOUR                  S   UR                  S   4nUS   US   -
  S-  nXBS   -   nUS   US   -
  S-  nXbS   -   n[        U[        R                  R                  5      (       a  UR                  XdXu45      $ UR                  S   S;   nU(       dU  [        U[        R
                  5      (       a  UR                  SSS5      n[        U5      (       a  UR                  SSS5      nUS:¼  a   XSS   ::  a  US:¼  a  XsS   ::  a
  USXE2Xg24   $ UR                  SS [        US   US   5      [        US   US   5      4-   n	[        U[        R
                  5      (       a  [        R                   " XS9n
O![        U5      (       a  UR#                  U	5      n
U	S   US   -
  S-  nX³S   -   nU	S	   US   -
  S-  nXÓS   -   nUW
SX¼2XÞ24'   XK-  nX[-  nXm-  nX}-  nU
S[        SU5      [%        U
R                  S   U5      2[        SU5      [%        U
R                  S	   U5      24   n
U
$ )
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‘   r   r�   r	   N.r¡   )r•   r¢   )r  r6   re   r   r[   r\   rt   r,  r•   r  r7   r8   Úcropr  Úpermutero   Ú
zeros_likeÚ	new_zerosrn   )r  rH   r  Úimage_shapeÚtopÚbottomÚleftÚrightr(  Ú	new_shapeÚ	new_imageÚtop_padÚ
bottom_padÚleft_padÚ	right_pads                  r,   Úcenter_cropÚ'ImageFeatureExtractionMixin.center_cropY  sí  € ð 	×%Ñ% eÔ,ä˜$¤×&Ñ&Ø�<ˆDô ˜5×!Ñ!¤Z°´r·z±z×%BÑ%BØ�z‰z˜Q‹Ø×(Ñ(¨Ó/�Ø-2¯[©[¸©^¸vÓ-E˜%Ÿ+™+ a b™/È5Ï;É;ÐWYÐXYÈ?‰Kà Ÿ:™: a™=¨%¯*©*°Q©-Ð8ˆKà˜1‰~  Q¡Ñ'¨AÑ-ˆØ˜A‘w‘ˆØ˜A‘  a¡Ñ(¨QÑ.ˆØ˜A‘w‘ˆô �eœSŸY™YŸ_™_×-Ñ-Ø—:‘:˜t¨%Ð8Ó9Ð9ð Ÿ™ A™¨&Ñ0ˆö Ü˜%¤§¡×,Ñ,ØŸ™¨¨1¨aÓ0�Ü˜u×%Ñ%ØŸ™ a¨¨AÓ.�ð �!‹8˜¨a¡.Ó0°T¸Q³YÀ5ÐXYÉNÓCZØ˜˜c˜j¨$¨*Ð4Ñ5Ð5ð —K‘K  Ð$¬¨D°©G°[À±^Ó(DÄcÈ$ÈqÉ'ÐS^Ð_`ÑSaÓFbÐ'cÑcˆ	Ü�eœRŸZ™Z×(Ñ(ÜŸš eÑ=‰IÜ˜U×#Ñ#ØŸ™¨	Ó2ˆIà˜R‘= ;¨q¡>Ñ1°aÑ7ˆØ¨1™~Ñ-ˆ
Ø˜b‘M K°¡NÑ2°qÑ8ˆØ¨1™~Ñ-ˆ	ØAFˆ	�#�wÐ)¨8Ð+=Ð=Ñ>à‰ˆØÑˆØÑˆØÑˆàØ”�Q˜“œs 9§?¡?°2Ñ#6¸Ó?Ð?ÄÀQÈÃÔPSÐT]×TcÑTcÐdfÑTgÐinÓPoÐAoÐoñ
ˆ	ð Ðr+   c                 ó¶   • U R                  U5        [        U[        R                  R                  5      (       a  U R	                  U5      nUSSS2SS2SS24   $ )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.
Nr¢   )r  r6   r7   r8   rŒ   r  s     r,   Úflip_channel_orderÚ.ImageFeatureExtractionMixin.flip_channel_order¤  sL   € ð 	×%Ñ% eÔ,ä�eœSŸY™YŸ_™_×-Ñ-Ø×'Ñ'¨Ó.ˆEà‘T�r�Tš1ša�ZÑ Ð r+   c           	      óø   • Ub  UO[         R                  R                  nU R                  U5        [	        U[         R                  R                  5      (       d  U R                  U5      nUR                  X#XEXgS9$ )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)r7   r8   ÚNEARESTr  r6   r  Úrotate)r  rH   Úangler	  rW  rX  rY  rZ  s           r,   r\  Ú"ImageFeatureExtractionMixin.rotateµ  sj   € ð  (Ñ3‘8¼¿¹×9JÑ9Jˆà×%Ñ% eÔ,ä˜%¤§¡§¡×1Ñ1Ø×%Ñ% eÓ,ˆEà�|‰|Ø¨VÈið ð 
ð 	
r+   r#   r5   )NT)F)NTN)Nr   NNN)r$   r%   r&   r'   Ú__doc__r  r  r  r[   r\   r/  r”   r  rŒ   r,  r4  r8  rQ  rT  r\  r*   r#   r+   r,   r  r  o  se   † ñòôò<$ð˜RŸZ™Zð °¸±ð ÀÇ
Á
ô ôò@ô(2(ôhA5òFIòV!÷"
r+   r  Úannotation_formatÚsupported_annotation_formatsc                 óò   • X;  a  [        S[         SU 35      eU [        R                  L a  [	        U5      (       d  [        S5      eU [        R
                  L a  [        U5      (       d  [        S5      eg g )NzUnsupported annotation format: z must be one of zäInvalid 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.zòInvalid 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.)rE   Úformatr.   r2   rÌ   r3   rÐ   )r`  ra  r¼   s      r,   Úvalidate_annotationsrd  Î  sŒ   € ð
 Ó<ÜÐ:¼6¸(ÐBRÐSoÐRpÐqÓrÐràÔ,×;Ñ;Ò;Ü/°×<Ñ<ÜðBóð ð Ô,×:Ñ:Ò:Ü.¨{×;Ñ;ÜðMóð ð <ð ;r+   Úvalid_processor_keysÚcaptured_kwargsc                 ó®   • [        U5      R                  [        U 5      5      nU(       a+  SR                  U5      n[        R	                  SU S35        g g )Nz, zUnused or unrecognized kwargs: rs   )ÚsetÚ
differenceÚjoinr–   r—   )re  rf  Úunused_keysÚunused_key_strs       r,   Úvalidate_kwargsrm  ç  sJ   € Ü�oÓ&×1Ñ1´#Ð6JÓ2KÓL€KÞØŸ™ ;Ó/ˆä�‰Ð8¸Ð8HÈÐJÕKð r+   c                   óØ   • \ rS rSr% SrSr\S-  \S'   Sr\S-  \S'   Sr	\S-  \S'   Sr
\S-  \S'   Sr\S-  \S'   Sr\S-  \S	'   S
 rSS jrS rS rS rS rS rSS jrS\4S jrSrg)ÚSizeDictiï  z6
Hashable dictionary to store image size information.
Nr©   rª   Úlongest_edgeÚshortest_edger¦   r§   c                 óV   • [        X5      (       a  [        X5      $ [        SU S35      e)NúKey z not found in SizeDict.)ÚhasattrÚgetattrÚKeyError©r  Úkeys     r,   Ú__getitem__ÚSizeDict.__getitem__ü  s-   € Ü�4×ÑÜ˜4Ó%Ð%Ü˜˜c˜UÐ"9Ð:Ó;Ð;r+   c                 óT   • [        X5      (       a  [        X5      b  [        X5      $ U$ r5   ©rt  ru  )r  rx  Údefaults      r,   râ   ÚSizeDict.get  s'   € Ü�4×Ñ¤'¨$Ó"4Ñ"@Ü˜4Ó%Ð%Øˆr+   c              #   ó„   #   • [        U 5       H-  n[        XR                  5      nUc  M  UR                  U4v •  M/     g 7fr5   )r   ru  Úname)r  ÚfÚvals      r,   Ú__iter__ÚSizeDict.__iter__  s4   é € ä˜–ˆAÜ˜$§¡Ó'ˆCØ‹Ø—f‘f˜c�kÔ!ò ùs
   ‚%A «A c                 óœ   • [        U R                  U R                  U R                  U R                  U R
                  U R                  45      $ r5   )Úhashr©   rª   rp  rq  r¦   r§   )r  s    r,   Ú__hash__ÚSizeDict.__hash__  s<   € Ü�T—[‘[ $§*¡*¨d×.?Ñ.?À×ASÑASÐUY×UdÑUdÐfj×ftÑftÐuÓvÐvr+   c                 ó@   • [        X5      =(       a    [        X5      S L$ r5   r|  rw  s     r,   Ú__contains__ÚSizeDict.__contains__  s   € Ü�tÓ!×D¤g¨dÓ&8ÀÐ&DÐDr+   c                 ón   • [        X5      (       d  [        SU S35      e[        R                  XU5        g )Nrs  z" is not a valid field of SizeDict.)rt  rv  ÚobjectÚ__setattr__)r  rx  Úvalues      r,   Ú__setitem__ÚSizeDict.__setitem__  s2   € Ü�t×!Ñ!Ü˜T # Ð&HÐIÓJÐJÜ×Ñ˜4 eÕ,r+   c                 óü   ^ ^• [        T[        5      (       a  [        T 5      T:H  $ [        T[        5      (       a=  [        U 4S j[	        T 5       5       5      [        U4S j[	        T 5       5       5      :H  $ [
        $ )Nc              3   óP   >#   • U  H  n[        TUR                  5      v •  M     g 7fr5   ©ru  r€  )rO   r�  r  s     €r,   rP   Ú"SizeDict.__eq__.<locals>.<genexpr>  s   øé € ÐEº°1œ  q§v¡v×.Ð.ºùó   ƒ#&c              3   óP   >#   • U  H  n[        TUR                  5      v •  M     g 7fr5   r”  )rO   r�  Úothers     €r,   rP   r•    s#   øé € ð OÚ0<¨1”˜˜qŸv™v×&Ð&²ùr–  )r6   r¾   ro  re   r   ÚNotImplemented)r  r˜  s   ``r,   Ú__eq__ÚSizeDict.__eq__  sk   ù€ Ü�eœT×"Ñ"Ü˜“: Ñ&Ð&Ü�eœX×&Ñ&ÜÔE¼¸t¼ÓEÓEÌô OÜ06°t´óOó Jñ ð ô Ðr+   rj   c                 ó¦   • [        U[        [        -  5      (       a0  [        U 5      nUR                  [        U5      5        [        S0 UD6$ [        $ )Nr#   )r6   r¾   ro  Úupdater™  ©r  r˜  Úmergeds      r,   Ú__or__ÚSizeDict.__or__!  s@   € Ü�eœT¤H™_×-Ñ-Ü˜$“ZˆFØ�M‰Mœ$˜u›+Ô&ÜÑ%˜fÑ%Ð%ÜÐr+   c                 ó†   • [        U[        5      (       a'  [        U5      nUR                  [        U 5      5        U$ [        $ r5   )r6   r¾   r�  r™  rž  s      r,   Ú__ror__ÚSizeDict.__ror__(  s3   € Ü�eœT×"Ñ"Ü˜%“[ˆFØ�M‰Mœ$˜t›*Ô%ØˆMÜÐr+   r#   r5   )rj   ro  )r$   r%   r&   r'   r_  r©   r”   Ú__annotations__rª   rp  rq  r¦   r§   ry  râ   rƒ  r‡  rŠ  r�  rš  r   r¾   r£  r*   r#   r+   r,   ro  ro  ï  s“   ‡ ñð €FˆC�$‰JÓØ€Eˆ3�‰:ÓØ#€L�#˜‘*Ó#Ø $€M�3˜‘:Ó$Ø!€J��d‘
Ó!Ø €Iˆs�T‰zÓ ò<ô
ò
"òwòEò-ò
ôð ÷ r+   ro  )r�   r5   )NNNNNNNNNNNN)irè   rä   Úcollections.abcr   Údataclassesr   r   Úior   Útypingr   r   rá   rA   r[   Úutilsr
   r   r   r   r   r   r   r   r   Úutils.constantsr   r   r   r   r   r   Úutils.import_utilsr   Ú	PIL.Imager7   ÚPIL.ImageOpsr8   Ú
Resamplingr
  Útorchvision.ior   r   Útorchvision.transformsr   Ú!torchvision.transforms.functionalr   r[  ÚNEAREST_EXACTÚBOXr7  ÚHAMMINGÚBICUBICÚLANCZOSÚpil_torch_interpolation_mappingÚitemsÚtorch_pil_interpolation_mappingr@   Ú
get_loggerr$   r–   r\   rZ   Ú
ImageInputr   r.   r¾   rÞ   r”   ÚAnnotationTyper;   r=   rI   rK   rU   rc   rf   ri   Úboolrp   ru   r„   r‰   rŒ   re   rš   rž   r¤   r°   rµ   r(   r¸   rÁ   rÅ   rÌ   rÐ   r/  rÝ   rú   rý   r  r  rd  rm  ro  )ÚkÚvs   00r,   Ú<module>rÁ     sÙ  ðó Û 	Ý $ß )Ý ß ã Û ÷
÷ 
õ 
÷÷ õ )ñ ×ÑÛÛàŸ™×-Ñ-Ðá×Ñß:Ý8Ý?ð 	×"Ñ"Ð$5×$CÑ$CØ×ÑÐ 1× 5Ñ 5Ø×#Ñ#Ð%6×%?Ñ%?Ø×"Ñ"Ð$5×$=Ñ$=Ø×"Ñ"Ð$5×$=Ñ$=Ø×"Ñ"Ð$5×$=Ñ$=ð'Ð#ð 9X×8]Ñ8]Ô8_Ô&`Ò8_±° q¢tÑ8_Ò&`Ñ#à&(Ð#Ø&(Ð#ñ ×ÑÛð 
×	Ò	˜HÓ	%€ð Ø�r—z‘z >°4Ð8IÑ3JÈDÐQS×Q[ÑQ[ÑL\Ð^bÐcqÑ^rÐrñ€
ô
�|ô ô
$�|ô $ð
 �c˜3 ™9 t¨D¡zÑ1Ð1Ñ2€òFô�ô ò?òLðE Dô Eò,ò	òð5˜2Ÿ:™:ð 5¨$ô 5ñ#°ð #¸DÀÑ<Lõ #ðP ñ#LØ�Ñ˜zÑ)ð#Làð#Lð õ#LðP ñ$vØ�Ñ˜zÑ)ð$vàð$vð 
ˆ*Ñõ$vðN˜2Ÿ:™:ô ð EIñ$AØ�:‰:ð$AØ%(¨5°°c°©?Ñ%:¸TÑ%Að$Aàõ$AñNF b§j¡jð FÐEUÐX[ÑE[Ð^bÑEbð FÐnqõ Fñ,D˜"Ÿ*™*ð DÐ3CÀdÑ3Jð DÐV[Ð\_ÐadÐ\dÑVeõ Dð0!Ø�c˜3�h‘ð!àð!ð ð!ð ˆ3�ˆ8�_ô	!ð>8˜x¨™}ð 8°°c±ô 8ð br×awÑawñ#Ø��~ r§z¡zÐ1Ñ2Ñ3ð#ØHKÐN^ÑH^ð#à	ˆ#�Yõ#ð°4¸¸TÀE¹\Ð8IÑ3Jð Ètô ð°$°s¸DÀ5¹LÐ7HÑ2Ið Èdô ð O°(¸4ÀÀTÈEÁ\Ð@QÑ;RÑ2Sð OÐX\ô OðN°¸$¸sÀDÈ5ÁLÐ?PÑ:QÑ1Rð NÐW[ô Nð !ñ*Ø�Ð'Ð'Ñ(ð*à�T‰\ð*ð õ*ñZ 
Ð#Ñ$ð !ñ*
Ø�Ð'Ð'Ñ(ð*
à�T‰\ð*
ð ô*
ó %ð*
ð\ QUñ3Ø�$˜˜sÐ$5Ð5Ñ6ð3ØAFÈÁð3à
Ð˜dÐ#4Ñ5°t¸DÐARÑ<SÑ7TÐTÑUõ3ð, #Ø#'Ø $Ø-1Ø,0ØØ,0Ø"&Ø'+Ø!Ø"&ØMQñ+^Ø�t‘ð+^à˜D‘Lð+^ð ˜‘+ð+^ð ˜˜U™Ñ# dÑ*ð	+^ð
 �t˜E‘{Ñ" TÑ)ð+^ð �4‰Kð+^ð �3˜�8‰n˜sÑ" TÑ)ð+^ð ˜4‘Kð+^ð �C˜�H‰~ Ñ$ð+^ð �d‰{ð+^ð ˆs�Cˆx‰.˜4Ñ
ð+^ð Ð(Ð*=¸sÐBÑCÀdÑJõ+^÷\\
ñ \
ð~
Ø'ðà"'Ð(8¸#Ð(=Ñ">ðð �d‘ðð 
ô	ð2L¨$¨s©)ð LÀdÈ3Áiô Lñ ƒ÷=ð =ó ñ=ùó[ 'as   Ä<Q