Ë
    Gêñi¨¢  ã                   óZ  — d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlZd dlZddlmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZ dd	l m!Z!  e«       rd dl"Z#d dl$Z#e#jJ                  jL                  Z' e«       r¿d d
l(m)Z)m*Z* d dl+m,Z, d dl-m.Z. e'j^                  e,j`                  e'jb                  e,jb                  e'jd                  e,jd                  e'jf                  e,jf                  e'jh                  e,jh                  e'jj                  e,jj                  iZ6e6jo                  «       D � �ci c]  \  } }|| “Œ
 c}} Z8ni Z6i Z8 e«       rd dl9Z9 ejt                  e;«      Z<edejz                  de>d   e>ejz                     e>d   f   Z? G d„ de«      Z@ G d„ de«      ZAeBeCeDeCz  e>eB   z  f   ZEd„ ZF G d„ de«      ZGd„ ZHd„ ZIde>fd„ZJd„ ZKd„ ZLd„ ZMdejz                  deNfd„ZOdXd eDde>e?   fd!„ZP	 dXde>e?   e?z  d eDde?fd"„ZQ	 dXde>e?   e?z  d eDde>e?   fd#„ZRdejz                  fd$„ZS	 dYdejz                  d%eDeTeDd&f   z  dz  de@fd'„ZUdYdejz                  d(e@eCz  dz  deDfd)„ZVdYdejz                  d*e@dz  deTeDeDf   fd+„ZWd,eTeDeDf   d-eDd.eDdeTeDeDf   fd/„ZXd0ee
   de>e
   fd1„ZYe@j´                  fde>edejz                  f      d(eCe@z  de>eD   fd2„Z[d3eBeCe>eTz  f   deNfd4„Z\d3eBeCe>eTz  f   deNfd5„Z]d6eeBeCe>eTz  f      deNfd7„Z^d6eeBeCe>eTz  f      deNfd8„Z_	 dYdeeCdf   d9e`dz  ddfd:„Za e!d;¬<«      	 dYdeeCdf   d9e`dz  ddfd=„«       Zb	 dYdee>eTeCdf   d9e`dz  dede>d   e>e>d      f   fd>„Zc	 	 	 	 	 	 	 	 	 	 	 	 dZd?eNdz  d@e`dz  dAeNdz  dBe`e>e`   z  dz  dCe`e>e`   z  dz  dDeNdz  dEeBeCeDf   eDz  dz  dFeNdz  dGeBeCeDf   dz  dHeNdz  dIeBeCeDf   dz  dJedKdLeDf   dz  fdM„Zd G dN„ dO«      ZedPeAdQeTeAd&f   d6e>eB   ddfdR„ZfdSe>eC   dTe>eC   fdU„Zg e«        G dV„ dW«      «       Zhyc c}} w )[é    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                   ó   — e Zd ZdZdZy)ÚChannelDimensionÚchannels_firstÚchannels_lastN)Ú__name__Ú
__module__Ú__qualname__ÚFIRSTÚLAST© ó    úZ/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/transformers/image_utils.pyr   r   U   s   „ Ø€EØ�Dr(   r   c                   ó   — e Zd ZdZdZy)ÚAnnotationFormatÚcoco_detectionÚcoco_panopticN)r"   r#   r$   ÚCOCO_DETECTIONÚCOCO_PANOPTICr'   r(   r)   r+   r+   Z   s   „ Ø%€NØ#�Mr(   r+   c                 ób   — t        «       xr$ t        | t        j                  j                  «      S ©N)r   Ú
isinstanceÚPILÚImage©Úimgs    r)   Úis_pil_imager7   b   s   € ÜÓ ÒE¤Z°´S·Y±Y·_±_Ó%EÐEr(   c                   ó   — e Zd ZdZdZdZy)Ú	ImageTypeÚpillowÚtorchÚnumpyN)r"   r#   r$   r3   ÚTORCHÚNUMPYr'   r(   r)   r9   r9   f   s   „ Ø
€CØ€EØ�Er(   r9   c                 óÒ   — t        | «      rt        j                  S t        | «      rt        j                  S t        | «      rt        j                  S t        dt        | «      › �«      ‚)NzUnrecognized image type )	r7   r9   r3   r   r=   r   r>   Ú
ValueErrorÚtype©Úimages    r)   Úget_image_typerD   l   sO   € Ü�EÔÜ�}‰}ÐÜ�uÔÜ�‰ÐÜ�eÔÜ�‰ÐÜ
Ð/´°U³¨}Ð=Ó
>Ð>r(   c                 óL   — t        | «      xs t        | «      xs t        | «      S r1   )r7   r   r   r5   s    r)   Úis_valid_imagerF   v   s!   € Ü˜ÓÒK¤¨sÓ 3ÒK´ÀsÓ7KÐKr(   Úimagesc                 ó.   — | xr t        d„ | D «       «      S )Nc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr1   )rF   )Ú.0rC   s     r)   ú	<genexpr>z*is_valid_list_of_images.<locals>.<genexpr>{   s   è ø€ ÒD°Eœ.¨×/ÑDùó   ‚©Úall)rG   s    r)   Úis_valid_list_of_imagesrO   z   s   € ØÒD”cÑD¸VÔDÓDÐDr(   c                 ó8  — t        | d   t        «      r| D ��cg c]  }|D ]  }|‘Œ Œ c}}S t        | d   t        j                  «      rt        j                  | d¬«      S t        | d   t
        j                  «      rt        j                  | d¬«      S y c c}}w )Nr   ©Úaxis)Údim)r2   ÚlistÚnpÚndarrayÚconcatenater;   ÚTensorÚcat)Ú
input_listÚsublistÚitems      r)   Úconcatenate_listr]   ~   s~   € Ü�*˜Q‘-¤Ô&Ø$.×C˜¸7ÒC°4’ÐC�ÓCÐCÜ	�J˜q‘M¤2§:¡:Ô	.Ü�~‰~˜j¨qÔ1Ð1Ü	�J˜q‘M¤5§<¡<Ô	0Ü�y‰y˜¨Ô+Ð+ð 
1ùó Ds   ™Bc                 ór   — t        | t        t        f«      r| D ]  }t        |«      rŒ y yt	        | «      syy)NFT)r2   rT   ÚtupleÚvalid_imagesrF   )Úimgsr6   s     r)   r`   r`   ‡   s?   € ä�$œœu˜Ô&Øò 	ˆCÜ Õ$Ùð	ð ô ˜DÔ!ØØr(   c                 óL   — t        | t        t        f«      rt        | d   «      S y)Nr   F)r2   rT   r_   rF   r5   s    r)   Ú
is_batchedrc   “   s"   € Ü�#œœe�}Ô%Ü˜c !™fÓ%Ð%Ør(   rC   Úreturnc                 ó¢   — | j                   t        j                  k(  ryt        j                  | «      dk\  xr t        j                  | «      dk  S )zV
    Checks to see whether the pixel values have already been rescaled to [0, 1].
    Fr   r	   )ÚdtyperU   Úuint8ÚminÚmaxrB   s    r)   Úis_scaled_imagerj   ™   s>   € ð ‡{�{”b—h‘hÒØô �6‰6�%‹=˜AÑÒ4¤"§&¡&¨£-°1Ñ"4Ð4r(   Úexpected_ndimsc           	      ó(  — t        | «      r| S t        | «      r| gS t        | «      rU| j                  |dz   k(  rt	        | «      } | S | j                  |k(  r| g} | S t        d|dz   › d|› d| j                  › d�«      ‚t        dt        | «      › d�«      ‚)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 ú.)rc   r7   rF   ÚndimrT   r@   rA   )rG   rk   s     r)   Úmake_list_of_imagesro   ¤   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                 óH  — t        | t        t        f«      r=t        d„ | D «       «      r+t        d„ | D «       «      r| D ��cg c]  }|D ]  }|‘Œ Œ c}}S t        | t        t        f«      r[t	        | «      rPt        | d   «      s| d   j                  |k(  r| S | d   j                  |dz   k(  r| D ��cg c]  }|D ]  }|‘Œ Œ c}}S t        | «      r:t        | «      s| j                  |k(  r| gS | j                  |dz   k(  rt        | «      S t        d| › �«      ‚c c}}w c c}}w )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   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­wr1   ©r2   rT   r_   ©rJ   Úimages_is     r)   rK   z+make_flat_list_of_images.<locals>.<genexpr>Ü   ó   è ø€ ÒK¸”
˜8¤d¬E ]×3ÑKùó   ‚ "c              3   ó<   K  — | ]  }t        |«      xs | –— Œ y ­wr1   ©rO   rs   s     r)   rK   z+make_flat_list_of_images.<locals>.<genexpr>Ý   ó    è ø€ ÒYÀhÔ'¨Ó1ÒA¸°\ÓAÑYùó   ‚r   r	   z*Could not make a flat list of images from ©	r2   rT   r_   rN   rO   r7   rn   rF   r@   )rG   rk   Úimg_listr6   s       r)   Úmake_flat_list_of_imagesr}   Ê   s  € ô" 	�6œD¤%˜=Ô)ÜÑKÀFÔKÔKÜÑYÐRXÔYÔYà$*×?˜°hÒ?¨s’Ð?�Ó?Ð?ä�&œ4¤˜-Ô(Ô-DÀVÔ-LÜ˜˜q™	Ô" f¨Q¡i§n¡n¸Ò&FØˆMØ�!‰9�>‰>˜^¨aÑ/Ò/Ø(.×C˜H¸(ÒC°3’CÐC�CÓCÐCä�fÔÜ˜Ô 6§;¡;°.Ò#@Ø�8ˆOØ�;‰;˜.¨1Ñ,Ò,Ü˜“<Ðä
ÐAÀ&ÀÐJÓ
KÐKùó @ùó Ds   Á DÂ1Dc                 ó  — t        | t        t        f«      r&t        d„ | D «       «      rt        d„ | D «       «      r| S t        | t        t        f«      r\t	        | «      rQt        | d   «      s| d   j                  |k(  r| gS | d   j                  |dz   k(  r| D �cg c]  }t        |«      ‘Œ c}S t        | «      r<t        | «      s| j                  |k(  r| ggS | j                  |dz   k(  rt        | «      gS t        d«      ‚c c}w )as  
    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   óH   K  — | ]  }t        |t        t        f«      –— Œ y ­wr1   rr   rs   s     r)   rK   z-make_nested_list_of_images.<locals>.<genexpr>  ru   rv   c              3   ó<   K  — | ]  }t        |«      xs | –— Œ y ­wr1   rx   rs   s     r)   rK   z-make_nested_list_of_images.<locals>.<genexpr>  ry   rz   r   r	   z]Invalid input type. Must be a single image, a list of images, or a list of batches of images.r{   )rG   rk   rC   s      r)   Úmake_nested_list_of_imagesr�   ð   sí   € ô  	�6œD¤%˜=Ô)ÜÑKÀFÔKÔKÜÑYÐRXÔYÔYàˆô �&œ4¤˜-Ô(Ô-DÀVÔ-LÜ˜˜q™	Ô" f¨Q¡i§n¡n¸Ò&FØ�8ˆOØ�!‰9�>‰>˜^¨aÑ/Ò/Ø-3Ö4 E”D˜•KÒ4Ð4ô �fÔÜ˜Ô 6§;¡;°.Ò#@Ø�H�:ÐØ�;‰;˜.¨1Ñ,Ò,Ü˜“L�>Ð!ä
ÐtÓ
uÐuùò 5s   ÂDc                 óâ   — t        | «      st        dt        | «      › �«      ‚t        «       r9t	        | t
        j                  j                  «      rt        j                  | «      S t        | «      S )NzInvalid image type: )
rF   r@   rA   r   r2   r3   r4   rU   Úarrayr   r5   s    r)   Úto_numpy_arrayr„     sP   € Ü˜#ÔÜÐ/´°S³	¨{Ð;Ó<Ð<äÔ¤¨C´·±·±Ô!AÜ�x‰x˜‹}ÐÜ�C‹=Ðr(   Únum_channels.c                 ó*  — |�|nd}t        |t        «      r|fn|}| j                  dk(  rd\  }}nB| j                  dk(  rd\  }}n-| j                  dk(  rd\  }}nt        d| j                  › �«      ‚| j                  |   |v rD| j                  |   |v r3t
        j                  d| j                  › d	�«       t        j                  S | j                  |   |v rt        j                  S | j                  |   |v rt        j                  S t        d
«      ‚)a[  
    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)
r2   Úintrn   r@   ÚshapeÚloggerÚwarningr   r%   r&   )rC   r…   Ú	first_dimÚlast_dims       r)   Úinfer_channel_dimension_formatr’      s  € ð $0Ð#;‘<À€LÜ&0°¼sÔ&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                 óÀ   — |€t        | «      }|t        j                  k(  r| j                  dz
  S |t        j                  k(  r| j                  dz
  S t        d|› �«      ‚)a–  
    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%   rn   r&   r@   )rC   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                 óü   — |€t        | «      }|t        j                  k(  r| j                  d   | j                  d   fS |t        j                  k(  r| j                  d   | j                  d   fS t        d|› �«      ‚)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&   r@   )rC   r—   s     r)   Úget_image_sizerœ   ]  s{   € ð ÐÜ4°UÓ;ˆàÔ&×,Ñ,Ò,Ø�{‰{˜2‰ §¡¨B¡Ð/Ð/Ø	Ô(×-Ñ-Ò	-Ø�{‰{˜2‰ §¡¨B¡Ð/Ð/äÐ4°[°MÐBÓCÐCr(   Ú
image_sizeÚ
max_heightÚ	max_widthc                 óx   — | \  }}||z  }||z  }t        ||«      }t        ||z  «      }t        ||z  «      }	||	fS )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.
    )rh   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  sV   € ð, �M€FˆEØ Ñ&€LØ˜eÑ#€KÜ�L +Ó.€IÜ�V˜iÑ'Ó(€JÜ�E˜IÑ%Ó&€IØ�yÐ Ð r(   Úvaluesc                 óJ   — t        | Ž D �cg c]  }t        |«      ‘Œ c}S c c}w )zO
    Return the maximum value across all indices of an iterable of values.
    )Úzipri   )r©   Úvalues_is     r)   Úmax_across_indicesr­   ”  s    € ô +.¨v¨,Ö7˜hŒC��MÒ7Ð7ùÒ7s   ‹ c                 ó*  — |t         j                  k(  r+t        | D �cg c]  }|j                  ‘Œ c}«      \  }}}||fS |t         j                  k(  r+t        | D �cg c]  }|j                  ‘Œ c}«      \  }}}||fS t        d|› �«      ‚c c}w c c}w )zH
    Get the maximum height and width across all images in a batch.
    z"Invalid channel dimension format: )r   r%   r­   r�   r&   r@   )rG   r“   r6   Ú_rž   rŸ   s         r)   Úget_max_height_widthr°   ›  sž   € ð Ô,×2Ñ2Ò2Ü#5ÈFÖ6SÀS°s·y³yÒ6SÓ#TÑ ˆˆ:�yð
 ˜	Ð"Ð"ð	 
Ô.×3Ñ3Ò	3Ü#5ÈFÖ6SÀS°s·y³yÒ6SÓ#TÑ ˆ
�I˜qð ˜	Ð"Ð"ô Ð=Ð>OÐ=PÐQÓRÐRùò	 7Tùâ6Ss   �BÁBÚ
annotationc                 ó¶   — t        | t        «      rId| v rEd| v rAt        | d   t        t        f«      r(t	        | d   «      dk(  st        | d   d   t        «      ryy)NÚimage_idÚannotationsr   TF©r2   ÚdictrT   r_   Úlen©r±   s    r)   Ú"is_valid_annotation_coco_detectionr¹   ª  s`   € ä�:œtÔ$Ø˜*Ñ$Ø˜ZÑ'Ü�z -Ñ0´4¼°-Ô@ô �
˜=Ñ)Ó*¨aÒ/´:¸jÈÑ>WÐXYÑ>ZÔ\`Ô3að Ør(   c                 ó¾   — t        | t        «      rMd| v rId| v rEd| v rAt        | d   t        t        f«      r(t	        | d   «      dk(  st        | d   d   t        «      ryy)Nr³   Úsegments_infoÚ	file_namer   TFrµ   r¸   s    r)   Ú!is_valid_annotation_coco_panopticr½   ¹  sh   € ä�:œtÔ$Ø˜*Ñ$Ø˜zÑ)Ø˜:Ñ%Ü�z /Ñ2´T¼5°MÔBô �
˜?Ñ+Ó,°Ò1´ZÀ
È?Ñ@[Ð\]Ñ@^Ô`dÔ5eð Ør(   r´   c                 ó&   — t        d„ | D «       «      S )Nc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr1   )r¹   ©rJ   Úanns     r)   rK   z3valid_coco_detection_annotations.<locals>.<genexpr>Ê  s   è ø€ ÒN¸3Ô1°#×6ÑNùrL   rM   ©r´   s    r)   Ú valid_coco_detection_annotationsrÃ   É  s   € ÜÑNÀ+ÔNÓNÐNr(   c                 ó&   — t        d„ | D «       «      S )Nc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr1   )r½   rÀ   s     r)   rK   z2valid_coco_panoptic_annotations.<locals>.<genexpr>Î  s   è ø€ ÒM¸#Ô0°×5ÑMùrL   rM   rÂ   s    r)   Úvalid_coco_panoptic_annotationsrÆ   Í  s   € ÜÑMÀÔMÓMÐMr(   Útimeoutc           	      ó„  — t        t        dg«       t        | t        «      �r| j	                  d«      s| j	                  d«      rIt
        j                  j                  t        t        j                  | |d¬«      j                  «      «      } nàt        j                  j                  | «      r t
        j                  j                  | «      } n¡| j	                  d«      r| j                  d«      d   } 	 t!        j"                  | j%                  «       «      }t
        j                  j                  t        |«      «      } n/t        | t
        j                  j                  «      st+        d«      ‚t
        j,                  j/                  | «      } | j1                  d«      } | S # t&        $ r}t)        d	| › d
|› �«      ‚d}~ww xY w)a3  
    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_imager2   ÚstrÚ
startswithr3   r4   Úopenr   ÚhttpxÚgetÚcontentÚosÚpathÚisfileÚsplitÚbase64ÚdecodebytesÚencodeÚ	Exceptionr@   Ú	TypeErrorÚImageOpsÚexif_transposeÚconvert)rC   rÇ   Úb64Úes       r)   rÓ   rÓ   Ñ  st  € ô  ”j 8 *Ô-Ü�%œÕØ×Ñ˜IÔ&¨%×*:Ñ*:¸:Ô*Fô —I‘I—N‘N¤7¬5¯9©9°UÀGÐ^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   Ã3AF  Æ 	F?Æ)F:Æ:F?)Útorchvision)Úbackendsc                 óÖ  — ddl }t        | t        «      �rK| j                  d«      s| j                  d«      rdt	        j
                  | |d¬«      j                  } |j                  t        |«      |j                  ¬«      }t        |t        j                  ¬«      S t        j                  j                  | «      rt        | t        j                  ¬«      S | j                  d	«      r| j!                  d
«      d   } 	 t#        j$                  | j'                  «       «      } |j                  t        |«      |j                  ¬«      }t        |t        j                  ¬«      S t        | t,        j.                  j.                  «      r9t,        j0                  j3                  | «      } t5        | j7                  d«      «      S t9        d«      ‚# t(        $ r}t+        d| › d|› �«      ‚d}~ww xY w)at  
    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Ì   )rf   )Ú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;   r2   rÔ   rÕ   r×   rØ   rÙ   Ú
frombufferÚ	bytearrayrg   r   r   rÒ   rÚ   rÛ   rÜ   rÝ   rÞ   rß   rà   rá   r@   r3   r4   rã   rä   r   rå   râ   )rC   rÇ   r;   ÚrawÚbufrç   s         r)   Úload_image_as_tensorrð   þ  s›  € ó" ä�%œÕØ×Ñ˜IÔ&¨%×*:Ñ*:¸:Ô*FÜ—)‘)˜E¨7À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	 Ç		G(ÇG#Ç#G(c                 ó<  — t        | t        t        f«      rjt        | «      rDt        | d   t        t        f«      r+| D ��cg c]  }|D �cg c]  }t	        ||¬«      ‘Œ c}‘Œ c}}S | D �cg c]  }t	        ||¬«      ‘Œ c}S t	        | |¬«      S c c}w c c}}w c c}w )a  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Ç   )r2   rT   r_   r·   rÓ   )rG   rÇ   Úimage_grouprC   s       r)   Úload_imagesró   ,  s   € ô �&œ4¤˜-Ô(ÜˆvŒ;œ: f¨Q¡i´$¼°Ô?Øek×lÐVaÀ[ÖQ¸E”Z ¨wÖ7ÔQÓlÐlàDJÖK¸5”J˜u¨gÖ6Ò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                 ó¤   — | r|€t        d«      ‚|r|€t        d«      ‚|r|�|€t        d«      ‚|r|€t        d«      ‚|	r|
�|€t        d«      ‚yy)a‡  
    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`.)r@   )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                   ó˜   — e Zd ZdZd„ Zdd„Zd„ Zdej                  de	e
z  dej                  fd	„Zdd
„Zd„ Zdd„Zdd„Zd„ Zd„ Zdd„Zy)ÚImageFeatureExtractionMixinzD
    Mixin that contain utilities for preparing image features.
    c                 ó´   — t        |t        j                  j                  t        j                  f«      s$t        |«      st        dt        |«      › d�«      ‚y y )Nz	Got type zU which is not supported, only `PIL.Image.Image`, `np.ndarray` and `torch.Tensor` are.)r2   r3   r4   rU   rV   r   r@   rA   ©ÚselfrC   s     r)   Ú_ensure_format_supportedz4ImageFeatureExtractionMixin._ensure_format_supportedt  sQ   € Ü˜%¤#§)¡)§/¡/´2·:±:Ð!>Ô?ÌÐX]ÔH^ÜØœD ›K˜=ð )&ð &óð ð I_Ð?r(   Nc                 óÔ  — | j                  |«       t        |«      r|j                  «       }t        |t        j
                  «      r¡|€'t        |j                  d   t        j                  «      }|j                  dk(  r$|j                  d   dv r|j                  ddd«      }|r|dz  }|j                  t        j                  «      }t        j                  j                  |«      S |S )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   r<   r2   rU   rV   ÚflatÚfloatingrn   r�   Ú	transposeÚastyperg   r3   r4   Ú	fromarray)r  rC   Úrescales      r)   Úto_pil_imagez(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                 ó’   — | j                  |«       t        |t        j                  j                  «      s|S |j	                  d«      S )z—
        Converts `PIL.Image.Image` to RGB format.

        Args:
            image (`PIL.Image.Image`):
                The image to convert.
        rÒ   )r  r2   r3   r4   rå   r  s     r)   Úconvert_rgbz'ImageFeatureExtractionMixin.convert_rgb™  s8   € ð 	×%Ñ% eÔ,Ü˜%¤§¡§¡Ô1ØˆLà�}‰}˜UÓ#Ð#r(   rC   Úscalerd   c                 ó.   — | j                  |«       ||z  S )z7
        Rescale a numpy image by scale amount
        )r  )r  rC   r  s      r)   r  z#ImageFeatureExtractionMixin.rescale§  s   € ð 	×%Ñ% eÔ,Ø�u‰}Ðr(   c                 óÐ  — | j                  |«       t        |t        j                  j                  «      rt	        j
                  |«      }t        |«      r|j                  «       }|€'t        |j                  d   t        j                  «      n|}|r/| j                  |j                  t        j                  «      d«      }|r"|j                  dk(  r|j                  ddd«      }|S )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  r2   r3   r4   rU   rƒ   r   r<   r  Úintegerr  r  Úfloat32rn   r  )r  rC   r  Úchannel_firsts       r)   r„   z*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                 óÞ   — | j                  |«       t        |t        j                  j                  «      r|S t	        |«      r|j                  d«      }|S t        j                  |d¬«      }|S )z½
        Expands 2-dimensional `image` to 3 dimensions.

        Args:
            image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
                The image to expand.
        r   rQ   )r  r2   r3   r4   r   Ú	unsqueezerU   Úexpand_dimsr  s     r)   r  z'ImageFeatureExtractionMixin.expand_dimsÎ  s_   € ð 	×%Ñ% eÔ,ô �eœSŸY™YŸ_™_Ô-ØˆLä˜5Ô!Ø—O‘O AÓ&ˆEð ˆô —N‘N 5¨qÔ1ˆEØˆr(   c                 óÊ  — | j                  |«       t        |t        j                  j                  «      r| j	                  |d¬«      }nw|rut        |t
        j                  «      r0| j                  |j                  t
        j                  «      d«      }n+t        |«      r | j                  |j                  «       d«      }t        |t
        j                  «      r‘t        |t
        j                  «      s.t        j                  |«      j                  |j                  «      }t        |t
        j                  «      sèt        j                  |«      j                  |j                  «      }n¹t        |«      r®ddl}t        ||j                  «      s?t        |t
        j                  «      r |j                   |«      }n |j"                  |«      }t        ||j                  «      s?t        |t
        j                  «      r |j                   |«      }n |j"                  |«      }|j$                  dk(  r)|j&                  d   dv r||dd…ddf   z
  |dd…ddf   z  S ||z
  |z  S )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  r2   r3   r4   r„   rU   rV   r  r  r  r   Úfloatrƒ   rf   r;   rX   Ú
from_numpyÚtensorrn   r�   )r  rC   ÚmeanÚstdr  r;   s         r)   Ú	normalizez%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 E§L¡LÔ1Ü˜d¤B§J¡JÔ/Ø+˜5×+Ñ+¨DÓ1‘Dà'˜5Ÿ<™<¨Ó-�DÜ˜c 5§<¡<Ô0Ü˜c¤2§:¡:Ô.Ø*˜%×*Ñ*¨3Ó/‘Cà&˜%Ÿ,™, sÓ+�Cà�:‰:˜Š?˜uŸ{™{¨1™~°Ñ7Ø˜D¢ D¨$ Ñ/Ñ/°3²q¸$À°}Ñ3EÑEÐEà˜D‘L CÑ'Ð'r(   c                 óª  — |�|nt         j                  }| j                  |«       t        |t        j
                  j
                  «      s| j                  |«      }t        |t        «      rt        |«      }t        |t        «      st        |«      dk(  r®|rt        |t        «      r||fn	|d   |d   f}n�|j                  \  }}||k  r||fn||f\  }}	t        |t        «      r|n|d   }
||
k(  r|S |
t        |
|	z  |z  «      }}|�.||
k  rt        d|› d|› �«      ‚||kD  rt        ||z  |z  «      |}}||k  r||fn||f}|j                  ||¬«      S )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  r2   r3   r4   r  rT   r_   rŒ   r·   rþ   r@   Úresize)r  rC   rþ   rÿ   Údefault_to_squareÚmax_sizer¢   r¡   ÚshortÚlongÚrequested_new_shortÚ	new_shortÚnew_longs                r)   r'  z"ImageFeatureExtractionMixin.resize  sy  € ð<  (Ð3‘8Ô9K×9TÑ9Tˆà×%Ñ% eÔ,ä˜%¤§¡§¡Ô1Ø×%Ñ% eÓ,ˆEä�dœDÔ!Ü˜“;ˆDä�dœCÔ ¤C¨£I°¢NÙ Ü'1°$¼Ô'<˜˜d‘|À4ÈÁ7ÈDÐQRÉGÐBT‘à %§
¡
‘��và16¸&²˜u f™oÀvÈuÀo‘��tÜ.8¸¼sÔ.C¡dÈÈaÉÐ#àÐ/Ò/Ø �Là&9¼3Ð?RÐUYÑ?YÐ\aÑ?aÓ;b˜8�	àÐ'ØÐ#6Ò6Ü(Ø)¨(¨ð 4@Ø@D¸vðGóð ð   (Ò*Ü.1°(¸YÑ2FÈÑ2QÓ.RÐT\ 8˜	à05¸²˜	 8Ñ,ÀhÐPYÐEZ�à�|‰|˜D¨8ˆ|Ó4Ð4r(   c                 ó€  — | j                  |«       t        |t        «      s||f}t        |«      st        |t        j
                  «      rP|j                  dk(  r| j                  |«      }|j                  d   dv r|j                  dd n|j                  dd }n|j                  d   |j                  d   f}|d   |d   z
  dz  }||d   z   }|d   |d   z
  dz  }||d   z   }t        |t        j                  j                  «      r|j                  ||||f«      S |j                  d   dv }|sKt        |t        j
                  «      r|j                  ddd«      }t        |«      r|j                  ddd«      }|dk\  r!||d   k  r|dk\  r||d   k  r|d||…||…f   S |j                  dd t        |d   |d   «      t        |d   |d   «      fz   }	t        |t        j
                  «      rt	        j                   ||	¬«      }
nt        |«      r|j#                  |	«      }
|	d   |d   z
  dz  }||d   z   }|	d	   |d   z
  dz  }||d   z   }|
d||…||…f<   ||z  }||z  }||z  }||z  }|
dt        d|«      t%        |
j                  d   |«      …t        d|«      t%        |
j                  d	   |«      …f   }
|
S )
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  r2   r_   r   rU   rV   rn   r  r�   rþ   r3   r4   Úcropr  Úpermuteri   Ú
zeros_likeÚ	new_zerosrh   )r  rC   rþ   Úimage_shapeÚtopÚbottomÚleftÚrightr  Ú	new_shapeÚ	new_imageÚtop_padÚ
bottom_padÚleft_padÚ	right_pads                  r)   Úcenter_cropz'ImageFeatureExtractionMixin.center_cropY  sù  € ð 	×%Ñ% eÔ,ä˜$¤Ô&Ø˜$�<ˆDô ˜5Ô!¤Z°´r·z±zÔ%BØ�z‰z˜QŠØ×(Ñ(¨Ó/�Ø-2¯[©[¸©^¸vÑ-E˜%Ÿ+™+ a b™/È5Ï;É;ÐWYÐXYÈ?‰Kà Ÿ:™: a™=¨%¯*©*°Q©-Ð8ˆKà˜1‰~  Q¡Ñ'¨AÑ-ˆØ�t˜A‘w‘ˆØ˜A‘  a¡Ñ(¨QÑ.ˆØ�t˜A‘w‘ˆô �eœSŸY™YŸ_™_Ô-Ø—:‘:˜t S¨%°Ð8Ó9Ð9ð Ÿ™ A™¨&Ð0ˆñ Ü˜%¤§¡Ô,ØŸ™¨¨1¨aÓ0�Ü˜uÔ%ØŸ™ a¨¨AÓ.�ð �!Š8˜ +¨a¡.Ò0°T¸Q²YÀ5ÈKÐXYÉNÒCZØ˜˜c &˜j¨$¨u¨*Ð4Ñ5Ð5ð —K‘K  Ð$¬¨D°©G°[À±^Ó(DÄcÈ$ÈqÉ'ÐS^Ð_`ÑSaÓFbÐ'cÑcˆ	Ü�eœRŸZ™ZÔ(ÜŸ™ e°9Ô=‰IÜ˜UÔ#ØŸ™¨	Ó2ˆIà˜R‘= ;¨q¡>Ñ1°aÑ7ˆØ˜{¨1™~Ñ-ˆ
Ø˜b‘M K°¡NÑ2°qÑ8ˆØ˜{¨1™~Ñ-ˆ	ØAFˆ	�#�w˜zÐ)¨8°IÐ+=Ð=Ñ>àˆw‰ˆØ�'ÑˆØ�ÑˆØ�ÑˆàØ”�Q˜“œs 9§?¡?°2Ñ#6¸Ó?Ð?ÄÀQÈÃÔPSÐT]×TcÑTcÐdfÑTgÐinÓPoÐAoÐoñ
ˆ	ð Ðr(   c                 ó¬   — | j                  |«       t        |t        j                  j                  «      r| j	                  |«      }|ddd…dd…dd…f   S )a   
        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  r2   r3   r4   r„   r  s     r)   Úflip_channel_orderz.ImageFeatureExtractionMixin.flip_channel_order¤  sI   € ð 	×%Ñ% eÔ,ä�eœSŸY™YŸ_™_Ô-Ø×'Ñ'¨Ó.ˆEà‘T�r�Tš1ša�ZÑ Ð r(   c                 óø   — |�|nt         j                  j                  }| j                  |«       t	        |t         j                  j                  «      s| j                  |«      }|j                  ||||||¬«      S )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)r3   r4   ÚNEARESTr  r2   r  Úrotate)r  rC   Úanglerÿ   rC  rD  rE  rF  s           r)   rH  z"ImageFeatureExtractionMixin.rotateµ  sn   € ð  (Ð3‘8¼¿¹×9JÑ9Jˆà×%Ñ% eÔ,ä˜%¤§¡§¡Ô1Ø×%Ñ% eÓ,ˆEà�|‰|Ø˜H¨V¸FÈiÐclð ó 
ð 	
r(   r1   )NT)F)NTN)Nr   NNN)r"   r#   r$   Ú__doc__r  r  r  rU   rV   r  rŒ   r  r„   r  r$  r'  r?  rA  rH  r'   r(   r)   r  r  o  se   „ ñòóò<$ð˜RŸZ™Zð °¸±ð ÀÇ
Á
ó óò@ó(2(óhA5òFIòV!ô"
r(   r  Úannotation_formatÚsupported_annotation_formatsc                 óØ   — | |vrt        dt        › d|› �«      ‚| t        j                  u rt	        |«      st        d«      ‚| t        j
                  u rt        |«      st        d«      ‚y y )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.)r@   Úformatr+   r.   rÃ   r/   rÆ   )rK  rL  r´   s      r)   Úvalidate_annotationsrO  Î  s‰   € ð
 Ð <Ñ<ÜÐ:¼6¸(ÐBRÐSoÐRpÐqÓrÐràÔ,×;Ñ;Ñ;Ü/°Ô<ÜðBóð ð Ô,×:Ñ:Ñ:Ü.¨{Ô;ÜðMóð ð <ð ;r(   Úvalid_processor_keysÚcaptured_kwargsc                 ó¤   — t        |«      j                  t        | «      «      }|r+dj                  |«      }t        j	                  d|› d�«       y y )Nz, zUnused or unrecognized kwargs: rm   )ÚsetÚ
differenceÚjoinrŽ   r�   )rP  rQ  Úunused_keysÚunused_key_strs       r)   Úvalidate_kwargsrX  ç  sJ   € Ü�oÓ&×1Ñ1´#Ð6JÓ2KÓL€KÙØŸ™ ;Ó/ˆä�‰Ð8¸Ð8HÈÐJÕKð r(   c                   óÊ   — e Zd ZU dZdZedz  ed<   dZedz  ed<   dZedz  ed<   dZ	edz  ed<   dZ
edz  ed<   dZedz  ed<   d	„ Zdd
„Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zdefd„Zy)ÚSizeDictz>
    Hashable dictionary to store image size information.
    Nr¡   r¢   Úlongest_edgeÚshortest_edgerž   rŸ   c                 óP   — t        | |«      rt        | |«      S t        d|› d�«      ‚)NúKey z not found in SizeDict.)ÚhasattrÚgetattrÚKeyError©r  Úkeys     r)   Ú__getitem__zSizeDict.__getitem__ü  s.   € Ü�4˜ÔÜ˜4 Ó%Ð%Ü˜˜c˜UÐ"9Ð:Ó;Ð;r(   c                 óN   — t        | |«      rt        | |«      �t        | |«      S |S r1   ©r_  r`  )r  rc  Údefaults      r)   rØ   zSizeDict.get  s*   € Ü�4˜Ô¤'¨$°Ó"4Ð"@Ü˜4 Ó%Ð%Øˆr(   c              #   ó~   K  — t        | «      D ]+  }t        | |j                  «      }|€Œ|j                  |f–— Œ- y ­wr1   )r   r`  Úname)r  ÚfÚvals      r)   Ú__iter__zSizeDict.__iter__  s<   è ø€ ä˜“ò 	"ˆAÜ˜$ §¡Ó'ˆCØ‰Ø—f‘f˜c�kÓ!ñ	"ùs   ‚'=ª=c                 óœ   — t        | j                  | j                  | j                  | j                  | j
                  | j                  f«      S r1   )Úhashr¡   r¢   r[  r\  rž   rŸ   )r  s    r)   Ú__hash__zSizeDict.__hash__  s<   € Ü�T—[‘[ $§*¡*¨d×.?Ñ.?À×ASÑASÐUY×UdÑUdÐfj×ftÑftÐuÓvÐvr(   c                 ó:   — t        | |«      xr t        | |«      d uS r1   rf  rb  s     r)   Ú__contains__zSizeDict.__contains__  s    € Ü�t˜SÓ!ÒD¤g¨d°CÓ&8ÀÐ&DÐDr(   c                 óh   — t        | |«      st        d|› d�«      ‚t        j                  | ||«       y )Nr^  z" is not a valid field of SizeDict.)r_  ra  ÚobjectÚ__setattr__)r  rc  Úvalues      r)   Ú__setitem__zSizeDict.__setitem__  s3   € Ü�t˜SÔ!Ü˜T # Ð&HÐIÓJÐJÜ×Ñ˜4  eÕ,r(   c                 óä   ‡ ‡— t        ‰t        «      rt        ‰ «      ‰k(  S t        ‰t        «      r;t        ˆ fd„t	        ‰ «      D «       «      t        ˆfd„t	        ‰ «      D «       «      k(  S t
        S )Nc              3   óJ   •K  — | ]  }t        ‰|j                  «      –— Œ y ­wr1   ©r`  ri  )rJ   rj  r  s     €r)   rK   z"SizeDict.__eq__.<locals>.<genexpr>  s   øè ø€ ÒE°1œ  q§v¡v×.ÑEùó   ƒ #c              3   óJ   •K  — | ]  }t        ‰|j                  «      –— Œ y ­wr1   ry  )rJ   rj  Úothers     €r)   rK   z"SizeDict.__eq__.<locals>.<genexpr>  s#   øè ø€ ò OØ+,”˜˜qŸv™v×&ñOùrz  )r2   r¶   rZ  r_   r   ÚNotImplemented)r  r|  s   ``r)   Ú__eq__zSizeDict.__eq__  se   ù€ Ü�eœTÔ"Ü˜“: Ñ&Ð&Ü�eœXÔ&ÜÓE¼¸t»ÔEÓEÌó OÜ06°t³ôOó Jñ ð ô Ðr(   rd   c                 óœ   — t        |t        t        z  «      r0t        | «      }|j                  t        |«      «       t        di |¤ŽS t        S )Nr'   )r2   r¶   rZ  Úupdater}  ©r  r|  Úmergeds      r)   Ú__or__zSizeDict.__or__!  s=   € Ü�eœT¤H™_Ô-Ü˜$“ZˆFØ�M‰Mœ$˜u›+Ô&ÜÑ%˜fÑ%Ð%ÜÐr(   c                 ó|   — t        |t        «      r't        |«      }|j                  t        | «      «       |S t        S r1   )r2   r¶   r€  r}  r�  s      r)   Ú__ror__zSizeDict.__ror__(  s0   € Ü�eœTÔ"Ü˜%“[ˆFØ�M‰Mœ$˜t›*Ô%ØˆMÜÐr(   r1   )rd   rZ  )r"   r#   r$   rJ  r¡   rŒ   Ú__annotations__r¢   r[  r\  rž   rŸ   rd  rØ   rl  ro  rq  rv  r~  rƒ  r¶   r…  r'   r(   r)   rZ  rZ  ï  s“   … ñð €FˆC�$‰JÓØ€Eˆ3�‰:ÓØ#€L�#˜‘*Ó#Ø $€M�3˜‘:Ó$Ø!€J��d‘
Ó!Ø €Iˆs�T‰zÓ ò<ó
ò
"òwòEò-ò
óð ô r(   rZ  )rˆ   r1   )NNNNNNNNNNNN)irÞ   rÚ   Úcollections.abcr   Údataclassesr   r   Úior   Útypingr   r   r×   r<   rU   Úutilsr
   r   r   r   r   r   r   r   r   Úutils.constantsr   r   r   r   r   r   Úutils.import_utilsr   Ú	PIL.Imager3   ÚPIL.ImageOpsr4   Ú
Resamplingr   Útorchvision.ior   r   Útorchvision.transformsr   Ú!torchvision.transforms.functionalr   rG  ÚNEAREST_EXACTÚBOXr&  ÚHAMMINGÚBICUBICÚLANCZOSÚpil_torch_interpolation_mappingÚitemsÚtorch_pil_interpolation_mappingr;   Ú
get_loggerr"   rŽ   rV   rT   Ú
ImageInputr   r+   r¶   rÔ   rŒ   ÚAnnotationTyper7   r9   rD   rF   rO   r]   r`   rc   Úboolrj   ro   r}   r�   r„   r_   r’   r–   rœ   r¨   r­   r%   r°   r¹   r½   rÃ   rÆ   r  rÓ   rð   ró   r  r  rO  rX  rZ  )ÚkÚvs   00r)   ú<module>r¢     sÐ  ðó Û 	Ý $ß )Ý ß ã Û ÷
÷ 
õ 
÷÷ õ )ñ ÔÛÛàŸ™×-Ñ-ÐáÔß:Ý8Ý?ð 	×"Ñ"Ð$5×$CÑ$CØ×ÑÐ 1× 5Ñ 5Ø×#Ñ#Ð%6×%?Ñ%?Ø×"Ñ"Ð$5×$=Ñ$=Ø×"Ñ"Ð$5×$=Ñ$=Ø×"Ñ"Ð$5×$=Ñ$=ð'Ð#ð 9X×8]Ñ8]Ó8_×&`±°°1 q¨!¡tÓ&`Ñ#à&(Ð#Ø&(Ð#ñ ÔÛð 
ˆ×	Ñ	˜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   Ä2P'