Ë
    S^(h–�  ã                   ó  — 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
mZmZmZmZmZ ddlmZmZmZmZmZ ddlmZmZmZmZmZ  e«       r
d dlZdd	l
mZ  e«       rd dlZ e«       rd dlZ  e«       rd dl!mZ" 	 dHd
e	jF                  deee$f   deeee$f      de	jF                  fd„Z%de	jL                  dfd
e	jF                  de'dee   de	jP                  deee$ef      de	jF                  fd„Z)d„ Z*	 	 	 dId
ee	jF                  ddddf   dee+   dee$   deee$ef      ddf
d„Z,dHde-e.e.f   fd„Z/	 	 	 dJde	jF                  dee.e-e.e.f   e0e.   e-e.   f   de+d ee.   deee$ef      de-fd!„Z1	 	 	 	 	 dKd
e	jF                  de-e.e.f   d"d#d$ee.   dee   d%e+deee$ef      de	jF                  fd&„Z2	 	 dLd
e	jF                  d'ee'ee'   f   d(ee'ee'   f   dee   deee$ef      de	jF                  fd)„Z3	 	 dLd
e	jF                  de-e.e.f   deee$ef      deee$ef      de	jF                  f
d*„Z4dMd,„Z5d+e	jF                  de	jF                  fd-„Z6dNd.„Z7d+edefd/„Z8dOd1„Z9d0e	jF                  de	jF                  fd2„Z:dPd3„Z;d0edefd4„Z<d5„ Z=d6„ Z> G d7„ d8e«      Z?e?j€                  d9ddfd
e	jF                  d:ee.e-e.e.f   ee-e.e.f      f   d;e?d<ee'ee'   f   deee$ef      deee$ef      de	jF                  fd=„ZAd
edefd>„ZB	 	 dLd
e	jF                  dee   deee$ef      de	jF                  fd?„ZCd@„ ZDdAe0d   de-eEe-e.e.f   e0d   f   eEe.e-e-e.e.f   e.f   f   f   fdB„ZFdCeEe-e.e.f   df   dDeEe.e-e.e.f   f   de0d   fdE„ZG G dF„ dG«      ZHy)Qé    )Ú
CollectionÚIterable)Úceil)ÚOptionalÚUnionNé   )ÚChannelDimensionÚ
ImageInputÚget_channel_dimension_axisÚget_image_sizeÚinfer_channel_dimension_format)ÚExplicitEnumÚ
TensorTypeÚis_jax_tensorÚis_tf_tensorÚis_torch_tensor)Úis_flax_availableÚis_tf_availableÚis_torch_availableÚis_vision_availableÚrequires_backends)ÚPILImageResamplingÚimageÚchannel_dimÚinput_channel_dimÚreturnc                 óV  — t        | t        j                  «      st        dt	        | «      › �«      ‚|€t        | «      }t        |«      }||k(  r| S |t        j                  k(  r| j                  d«      } | S |t        j                  k(  r| j                  d«      } | S t        d|› �«      ‚)a)  
    Converts `image` to the channel dimension format specified by `channel_dim`.

    Args:
        image (`numpy.ndarray`):
            The image to have its channel dimension set.
        channel_dim (`ChannelDimension`):
            The channel dimension format to use.
        input_channel_dim (`ChannelDimension`, *optional*):
            The channel dimension format of the input image. If not provided, it will be inferred from the input image.

    Returns:
        `np.ndarray`: The image with the channel dimension set to `channel_dim`.
    ú,Input image must be of type np.ndarray, got )é   r   r   )r   r   r   z&Unsupported channel dimension format: )Ú
isinstanceÚnpÚndarrayÚ	TypeErrorÚtyper   r	   ÚFIRSTÚ	transposeÚLASTÚ
ValueError)r   r   r   Útarget_channel_dims       ú[/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/image_transforms.pyÚto_channel_dimension_formatr+   5   s²   € ô& �eœRŸZ™ZÔ(ÜÐFÄtÈEÃ{ÀmÐTÓUÐUàÐ Ü:¸5ÓAÐä)¨+Ó6ÐØÐ.Ò.ØˆàÔ-×3Ñ3Ò3Ø—‘ 	Ó*ˆð €Lð 
Ô/×4Ñ4Ò	4Ø—‘ 	Ó*ˆð €Lô ÐAÀ+ÀÐOÓPÐPó    ÚscaleÚdata_formatÚdtypeÚinput_data_formatc                 óì   — t        | t        j                  «      st        dt	        | «      › �«      ‚| j                  t        j                  «      |z  }|�t        |||«      }|j                  |«      }|S )a  
    Rescales `image` by `scale`.

    Args:
        image (`np.ndarray`):
            The image to rescale.
        scale (`float`):
            The scale to use for rescaling the image.
        data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the image. If not provided, it will be the same as the input image.
        dtype (`np.dtype`, *optional*, defaults to `np.float32`):
            The dtype of the output image. Defaults to `np.float32`. Used for backwards compatibility with feature
            extractors.
        input_data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the input image. If not provided, it will be inferred from the input image.

    Returns:
        `np.ndarray`: The rescaled image.
    r   )r    r!   r"   r#   r$   ÚastypeÚfloat64r+   )r   r-   r.   r/   r0   Úrescaled_images         r*   Úrescaler5   \   sk   € ô4 �eœRŸZ™ZÔ(ÜÐFÄtÈEÃ{ÀmÐTÓUÐUà—\‘\¤"§*¡*Ó-°Ñ5€NØÐÜ4°^À[ÐRcÓdˆà#×*Ñ*¨5Ó1€NàÐr,   c                 ó  — | j                   t        j                  k(  rd}|S t        j                  | | j	                  t
        «      «      rbt        j                  d| k  «      rt        j                  | dk  «      rd}|S t        d| j                  «       › d| j                  «       › d�«      ‚t        j                  d| k  «      rt        j                  | dk  «      rd}|S t        d	| j                  «       › d| j                  «       › d�«      ‚)
zæ
    Detects whether or not the image needs to be rescaled before being converted to a PIL image.

    The assumption is that if the image is of type `np.float` and all values are between 0 and 1, it needs to be
    rescaled.
    Fr   éÿ   zZThe image to be converted to a PIL image contains values outside the range [0, 255], got [z, z%] which cannot be converted to uint8.r   TzXThe image to be converted to a PIL image contains values outside the range [0, 1], got [)
r/   r!   Úuint8Úallcloser2   ÚintÚallr(   ÚminÚmax)r   Ú
do_rescales     r*   Ú_rescale_for_pil_conversionr?   ‚   sü   € ð ‡{�{”b—h‘hÒØˆ
ð  Ðô 
�‰�U˜EŸL™L¬Ó-Ô	.Ü�6‰6�!�u‘*Ô¤"§&¡&¨°#©Ô"6ØˆJð Ðô ðØŸ	™	›�} B u§y¡y£{ mÐ3XðZóð ô 
�‰��U‘
Ô	¤§¡ u°¡zÔ 2Øˆ
ð Ðô	 ðØ—I‘I“K�=  5§9¡9£; -Ð/TðVó
ð 	
r,   zPIL.Image.Imageútorch.Tensorú	tf.Tensorzjnp.ndarrayr>   Ú
image_modec                 ó¨  — t        t        dg«       t        | t        j                  j                  «      r| S t        | «      st        | «      r| j                  «       } nRt        | «      rt        j                  | «      } n1t        | t        j                  «      st        dt        | «      › �«      ‚t        | t        j                   |«      } | j"                  d   dk(  rt        j$                  | d¬«      n| } |€t'        | «      n|}|rt)        | d«      } | j+                  t        j,                  «      } t        j                  j/                  | |¬«      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` or `tf.Tensor`):
            The image to convert to the `PIL.Image` format.
        do_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 and casting to `int` would result in a loss of precision,
            and `False` otherwise.
        image_mode (`str`, *optional*):
            The mode to use for the PIL image. If unset, will use the default mode for the input image type.
        input_data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the input image. If unset, will use the inferred format from the input.

    Returns:
        `PIL.Image.Image`: The converted image.
    Úvisionz Input image type not supported: éÿÿÿÿr   ©Úaxisr7   ©Úmode)r   Úto_pil_imager    ÚPILÚImager   r   Únumpyr   r!   Úarrayr"   r(   r$   r+   r	   r'   ÚshapeÚsqueezer?   r5   r2   r8   Ú	fromarray)r   r>   rB   r0   s       r*   rJ   rJ   �   s  € ô2 ”l X JÔ/ä�%œŸ™Ÿ™Ô)Øˆô �uÔ¤¨eÔ!4Ø—‘“‰Ü	�uÔ	Ü—‘˜“‰Ü˜œrŸz™zÔ*ÜÐ;¼DÀ»K¸=ÐIÓJÐJô (¨Ô/?×/DÑ/DÐFWÓX€Eð +0¯+©+°b©/¸QÒ*>ŒB�J‰J�u 2Õ&ÀE€Eð 8BÐ7IÔ,¨UÔ3Èz€JáÜ˜˜sÓ#ˆà�L‰LœŸ™Ó"€EÜ�9‰9×Ñ˜u¨:ÐÓ6Ð6r,   c                 ó¼  — | \  }}d}|�St        t        ||f«      «      }t        t        ||f«      «      }||z  |z  |kD  r||z  |z  }t        t	        |«      «      }||k  r||k(  s
||k  r||k(  r||}	}||	fS ||k  r0|}	|�|�t        ||z  |z  «      }||	fS t        ||z  |z  «      }||	fS |}|�|�t        ||z  |z  «      }	||	fS t        ||z  |z  «      }	||	fS )aC  
    Computes the output image size given the input image size and the desired output size.

    Args:
        image_size (`Tuple[int, int]`):
            The input image size.
        size (`int`):
            The desired output size.
        max_size (`int`, *optional*):
            The maximum allowed output size.
    N)Úfloatr<   r=   r:   Úround)
Ú
image_sizeÚsizeÚmax_sizeÚheightÚwidthÚraw_sizeÚmin_original_sizeÚmax_original_sizeÚohÚows
             r*   Úget_size_with_aspect_ratior_   Ó   sF  € ð �M€FˆEØ€HØÐÜ!¤# v¨u oÓ"6Ó7ÐÜ!¤# v¨u oÓ"6Ó7ÐØÐ0Ñ0°4Ñ7¸(ÒBØÐ"3Ñ3Ð6GÑGˆHÜ”u˜X“Ó'ˆDà�%Š˜F dšN°¸²ÀEÈTÂMØ˜ˆBˆð �ˆ8€Oð 
�ŠØˆØÐ HÐ$8Ü�X Ñ&¨Ñ.Ó/ˆBð �ˆ8€Oô �T˜F‘] UÑ*Ó+ˆBð �ˆ8€Oð ˆØÐ HÐ$8Ü�X Ñ%¨Ñ.Ó/ˆBð �ˆ8€Oô �T˜E‘\ FÑ*Ó+ˆBà�ˆ8€Or,   Úinput_imagerV   Údefault_to_squarerW   c                 óŒ  — t        |t        t        f«      r8t        |«      dk(  rt        |«      S t        |«      dk(  r|d   }nt	        d«      ‚|r||fS t        | |«      \  }}||k  r||fn||f\  }}|}	|	t        |	|z  |z  «      }}
|�.||	k  rt	        d|› d|› �«      ‚||kD  rt        ||
z  |z  «      |}}
||k  r||
fS |
|fS )a¾  
    Find the target (height, width) dimension of the output image after resizing given the input image and the desired
    size.

    Args:
        input_image (`np.ndarray`):
            The image to resize.
        size (`int` or `Tuple[int, int]` or List[int] or `Tuple[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).
        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*):
            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`.
        input_data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the input image. If unset, will use the inferred format from the input.

    Returns:
        `tuple`: The target (height, width) dimension of the output image after resizing.
    r   r   r   z7size must have 1 or 2 elements if it is a list or tuplezmax_size = zN must be strictly greater than the requested size for the smaller edge size = )r    ÚtupleÚlistÚlenr(   r   r:   )r`   rV   ra   rW   r0   rX   rY   ÚshortÚlongÚrequested_new_shortÚ	new_shortÚnew_longs               r*   Úget_resize_output_image_sizerk   û   s  € ôJ �$œ¤˜Ô&Üˆt‹9˜Š>Ü˜“;ÐÜ�‹Y˜!Š^à˜‘7‰DäÐVÓWÐWáØ�dˆ|Ðä" ;Ð0AÓB�M€FˆEØ%*¨f¢_�5˜&‘/¸6À5¸/�K€Eˆ4ØÐà-¬sÐ3FÈÑ3MÐPUÑ3UÓ/Vˆx€IàÐØÐ*Ò*ÜØ˜h˜Zð (4Ø48°6ð;óð ð �hÒÜ"% h°Ñ&:¸XÑ&EÓ"FÈ�xˆIà$)¨V¢OˆH�iÐ ÐN¸)ÀXÐ9NÐNr,   Úresampler   Úreducing_gapÚreturn_numpyc                 ó2  — t        t        dg«       |�|nt        j                  }t	        |«      dk(  st        d«      ‚|€t        | «      }|€|n|}d}t        | t        j                  j                  «      st        | «      }t        | ||¬«      } |\  }}	| j                  |	|f||¬«      }
|rit        j                  |
«      }
|
j                  dk(  rt        j                  |
d¬«      n|
}
t!        |
|t"        j$                  ¬	«      }
|rt'        |
d
«      n|
}
|
S )aË  
    Resizes `image` to `(height, width)` specified by `size` using the PIL library.

    Args:
        image (`np.ndarray`):
            The image to resize.
        size (`Tuple[int, int]`):
            The size to use for resizing the image.
        resample (`int`, *optional*, defaults to `PILImageResampling.BILINEAR`):
            The filter to user for resampling.
        reducing_gap (`int`, *optional*):
            Apply optimization by resizing the image in two steps. The bigger `reducing_gap`, the closer the result to
            the fair resampling. See corresponding Pillow documentation for more details.
        data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the output image. If unset, will use the inferred format from the input.
        return_numpy (`bool`, *optional*, defaults to `True`):
            Whether or not to return the resized image as a numpy array. If False a `PIL.Image.Image` object is
            returned.
        input_data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the input image. If unset, will use the inferred format from the input.

    Returns:
        `np.ndarray`: The resized image.
    rD   r   zsize must have 2 elementsF)r>   r0   )rl   rm   rE   rF   ©r   gp?)r   Úresizer   ÚBILINEARre   r(   r   r    rK   rL   r?   rJ   r!   rN   ÚndimÚexpand_dimsr+   r	   r'   r5   )r   rV   rl   rm   r.   rn   r0   r>   rX   rY   Úresized_images              r*   rq   rq   >  s  € ôB ”f˜x˜jÔ)à#Ð/‰xÔ5G×5PÑ5P€Häˆt‹9˜Š>ÜÐ4Ó5Ð5ð Ð Ü:¸5ÓAÐØ'2Ð':Ñ#À€Kð €JÜ�eœSŸY™YŸ_™_Ô-Ü0°Ó7ˆ
Ü˜U¨zÐM^Ô_ˆØ�M€FˆEà—L‘L %¨ ¸8ÐR^�LÓ_€MáÜŸ™ Ó/ˆð CP×BTÑBTÐXYÒBYœŸ™ }¸2Õ>Ð_lˆä3Ø˜;Ô:J×:OÑ:Oô
ˆñ
 <Fœ ¨wÔ7È=ˆØÐr,   ÚmeanÚstdc                 óN  — t        | t        j                  «      st        d«      ‚|€t	        | «      }t        | |¬«      }| j                  |   }t        j                  | j                  t        j                  «      s| j                  t        j                  «      } t        |t        «      r(t        |«      |k7  r t        d|› dt        |«      › �«      ‚|g|z  }t        j                  || j                  ¬«      }t        |t        «      r(t        |«      |k7  r t        d|› dt        |«      › �«      ‚|g|z  }t        j                  || j                  ¬«      }|t        j                   k(  r	| |z
  |z  } n| j"                  |z
  |z  j"                  } |�t%        | ||«      } | S | } | S )aô  
    Normalizes `image` using the mean and standard deviation specified by `mean` and `std`.

    image = (image - mean) / std

    Args:
        image (`np.ndarray`):
            The image to normalize.
        mean (`float` or `Collection[float]`):
            The mean to use for normalization.
        std (`float` or `Collection[float]`):
            The standard deviation to use for normalization.
        data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the output image. If unset, will use the inferred format from the input.
        input_data_format (`ChannelDimension`, *optional*):
            The channel dimension format of the input image. If unset, will use the inferred format from the input.
    zimage must be a numpy array)r0   zmean must have z$ elements if it is an iterable, got ©r/   zstd must have )r    r!   r"   r(   r   r   rO   Ú
issubdtyper/   Úfloatingr2   Úfloat32r   re   rN   r	   r'   ÚTr+   )r   rv   rw   r.   r0   Úchannel_axisÚnum_channelss          r*   Ú	normalizer€   …  s  € ô0 �eœRŸZ™ZÔ(ÜÐ6Ó7Ð7àÐ Ü:¸5ÓAÐä-¨eÐGXÔY€LØ—;‘;˜|Ñ,€Lô �=‰=˜Ÿ™¤b§k¡kÔ2Ø—‘œRŸZ™ZÓ(ˆä�$œ
Ô#Üˆt‹9˜Ò$Ü˜¨|¨nÐ<`ÔadÐeiÓajÐ`kÐlÓmÐmàˆv˜Ñ$ˆÜ�8‰8�D §¡Ô,€Dä�#”zÔ"Üˆs‹8�|Ò#Ü˜~¨l¨^Ð;_Ô`cÐdgÓ`hÐ_iÐjÓkÐkàˆe�lÑ"ˆÜ
�(‰(�3˜eŸk™kÔ
*€CàÔ,×1Ñ1Ò1Ø˜‘ Ñ$‰à—'‘'˜D‘. CÑ'×*Ñ*ˆàR]ÐRiÔ'¨¨{Ð<MÓN€EØ€Lð pu€EØ€Lr,   c                 ó  — t        t        dg«       t        | t        j                  «      st        dt        | «      › �«      ‚t        |t        «      rt        |«      dk7  rt        d«      ‚|€t        | «      }|�|n|}t        | t        j                  |«      } t        | t        j                  «      \  }}|\  }}t        |«      t        |«      }}||z
  dz  }	|	|z   }
||z
  dz  }||z   }|	dk\  r8|
|k  r3|dk\  r.||k  r)| d|	|
…||…f   } t        | |t        j                  «      } | S t!        ||«      }t!        ||«      }| j"                  dd ||fz   }t        j$                  | |¬	«      }t'        ||z
  dz  «      }||z   }t'        ||z
  dz  «      }||z   }| |d||…||…f<   |	|z  }	|
|z  }
||z  }||z  }|dt!        d|	«      t)        ||
«      …t!        d|«      t)        ||«      …f   }t        ||t        j                  «      }|S )
a  
    Crops the `image` to the specified `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 will always be of size `size`).

    Args:
        image (`np.ndarray`):
            The image to crop.
        size (`Tuple[int, int]`):
            The target size for the cropped image.
        data_format (`str` or `ChannelDimension`, *optional*):
            The channel dimension format for the output image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            If unset, will use the inferred format of the input image.
        input_data_format (`str` or `ChannelDimension`, *optional*):
            The channel dimension format for the input image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            If unset, will use the inferred format of the input image.
    Returns:
        `np.ndarray`: The cropped image.
    rD   r   r   zOsize must have 2 elements representing the height and width of the output imageNr   .éþÿÿÿ)rO   )r   Úcenter_cropr    r!   r"   r#   r$   r   re   r(   r   r+   r	   r%   r   r:   r=   rO   Ú
zeros_liker   r<   )r   rV   r.   r0   Úoutput_data_formatÚorig_heightÚ
orig_widthÚcrop_heightÚ
crop_widthÚtopÚbottomÚleftÚrightÚ
new_heightÚ	new_widthÚ	new_shapeÚ	new_imageÚtop_padÚ
bottom_padÚleft_padÚ	right_pads                        r*   rƒ   rƒ   Â  s]  € ô8 ”k H :Ô.ä�eœRŸZ™ZÔ(ÜÐFÄtÈEÃ{ÀmÐTÓUÐUä�dœHÔ%¬¨T«°aªÜÐjÓkÐkàÐ Ü:¸5ÓAÐØ(3Ð(?™ÐEVÐô (¨Ô/?×/EÑ/EÐGXÓY€Eä,¨UÔ4D×4JÑ4JÓKÑ€K�Ø"Ñ€K�Ü! +Ó.´°J³�€Kð ˜Ñ$¨Ñ
*€CØ�;Ñ€Fà˜Ñ#¨Ñ)€DØ�:Ñ€Eð ˆa‚x�F˜kÒ)¨d°aªi¸EÀZÒ<OØ�c˜3˜v˜: t¨E zÐ1Ñ2ˆÜ+¨EÐ3EÔGW×G]ÑG]Ó^ˆØˆô �[ +Ó.€JÜ�J 
Ó+€IØ—‘˜C˜RÐ  J°	Ð#:Ñ:€IÜ—‘˜e¨9Ô5€Iô �J Ñ,°Ñ1Ó2€GØ˜;Ñ&€JÜ�Y Ñ+¨qÑ0Ó1€HØ˜:Ñ%€IØ=B€Iˆc�7˜:Ð% x°	Ð'9Ð9Ñ:àˆ7�N€CØ
ˆgÑ€FØˆHÑ€DØ	ˆXÑ€Eà˜#œs 1 c›{¬S°¸VÓ-DÐDÄcÈ!ÈTÃlÔUXÐYbÐdiÓUjÐFjÐjÑk€IÜ+¨IÐ7IÔK[×KaÑKaÓb€IàÐr,   Úbboxes_centerc                 ó˜   — | j                  d«      \  }}}}t        j                  |d|z  z
  |d|z  z
  |d|z  z   |d|z  z   gd¬«      }|S )NrE   ç      à?©Údim©ÚunbindÚtorchÚstack)r–   Úcenter_xÚcenter_yrY   rX   Úbbox_cornerss         r*   Ú_center_to_corners_format_torchr¢     si   € Ø(5×(<Ñ(<¸RÓ(@Ñ%€Hˆh˜˜vÜ—;‘;à
�S˜5‘[Ñ
  H¨s°V©|Ñ$;¸xÈ#ÐPUÉ+Ñ?UÐYaÐdgÐjpÑdpÑYpÐrØô€Lð
 Ðr,   c                 óŽ   — | j                   \  }}}}t        j                  |d|z  z
  |d|z  z
  |d|z  z   |d|z  z   gd¬«      }|S )Nr˜   rE   rF   ©r}   r!   rž   ©r–   rŸ   r    rY   rX   Úbboxes_cornerss         r*   Ú_center_to_corners_format_numpyr§      sa   € Ø(5¯©Ñ%€Hˆh˜˜vÜ—X‘Xà	�C˜%‘KÑ	 ¨C°&©LÑ!8¸(ÀSÈ5Á[Ñ:PÐRZÐ]`ÐciÑ]iÑRiÐjØô€Nð
 Ðr,   c                 ó¤   — t        j                  | d¬«      \  }}}}t        j                  |d|z  z
  |d|z  z
  |d|z  z   |d|z  z   gd¬«      }|S )NrE   rF   r˜   ©ÚtfÚunstackrž   r¥   s         r*   Ú_center_to_corners_format_tfr¬   *  sh   € Ü(*¯
©
°=ÀrÔ(JÑ%€Hˆh˜˜vÜ—X‘Xà	�C˜%‘KÑ	 ¨C°&©LÑ!8¸(ÀSÈ5Á[Ñ:PÐRZÐ]`ÐciÑ]iÑRiÐjØô€Nð
 Ðr,   c                 óÒ   — t        | «      rt        | «      S t        | t        j                  «      rt        | «      S t        | «      rt        | «      S t        dt        | «      › �«      ‚)a}  
    Converts bounding boxes from center format to corners format.

    center format: contains the coordinate for the center of the box and its width, height dimensions
        (center_x, center_y, width, height)
    corners format: contains the coordinates for the top-left and bottom-right corners of the box
        (top_left_x, top_left_y, bottom_right_x, bottom_right_y)
    úUnsupported input type )
r   r¢   r    r!   r"   r§   r   r¬   r(   r$   )r–   s    r*   Úcenter_to_corners_formatr¯   5  s\   € ô �}Ô%Ü.¨}Ó=Ð=Ü	�M¤2§:¡:Ô	.Ü.¨}Ó=Ð=Ü	�mÔ	$Ü+¨MÓ:Ð:ä
Ð.¬t°MÓ/BÐ.CÐDÓ
EÐEr,   r¦   c                 óŒ   — | j                  d«      \  }}}}||z   dz  ||z   dz  ||z
  ||z
  g}t        j                  |d¬«      S )NrE   r   r™   r›   )r¦   Ú
top_left_xÚ
top_left_yÚbottom_right_xÚbottom_right_yÚbs         r*   Ú_corners_to_center_format_torchr¶   J  s`   € Ø=K×=RÑ=RÐSUÓ=VÑ:€J�
˜N¨Nà	�nÑ	$¨Ñ)Ø	�nÑ	$¨Ñ)Ø	˜*Ñ	$Ø	˜*Ñ	$ð		€Aô �;‰;�q˜bÔ!Ð!r,   c                 ó‚   — | j                   \  }}}}t        j                  ||z   dz  ||z   dz  ||z
  ||z
  gd¬«      }|S )Nr   rE   rF   r¤   ©r¦   r±   r²   r³   r´   r–   s         r*   Ú_corners_to_center_format_numpyr¹   U  s`   € Ø=K×=MÑ=MÑ:€J�
˜N¨NÜ—H‘Hà˜.Ñ(¨AÑ-Ø˜.Ñ(¨AÑ-Ø˜jÑ(Ø˜jÑ(ð		
ð ô€Mð Ðr,   c                 ó˜   — t        j                  | d¬«      \  }}}}t        j                  ||z   dz  ||z   dz  ||z
  ||z
  gd¬«      }|S )NrE   rF   r   r©   r¸   s         r*   Ú_corners_to_center_format_tfr»   c  sf   € Ü=?¿Z¹ZÈÐ]_Ô=`Ñ:€J�
˜N¨NÜ—H‘Hà˜.Ñ(¨AÑ-Ø˜.Ñ(¨AÑ-Ø˜jÑ(Ø˜jÑ(ð		
ð ô€Mð Ðr,   c                 óÒ   — t        | «      rt        | «      S t        | t        j                  «      rt        | «      S t        | «      rt        | «      S t        dt        | «      › �«      ‚)a�  
    Converts bounding boxes from corners format to center format.

    corners format: contains the coordinates for the top-left and bottom-right corners of the box
        (top_left_x, top_left_y, bottom_right_x, bottom_right_y)
    center format: contains the coordinate for the center of the box and its the width, height dimensions
        (center_x, center_y, width, height)
    r®   )
r   r¶   r    r!   r"   r¹   r   r»   r(   r$   )r¦   s    r*   Úcorners_to_center_formatr½   q  s\   € ô �~Ô&Ü.¨~Ó>Ð>Ü	�N¤B§J¡JÔ	/Ü.¨~Ó>Ð>Ü	�nÔ	%Ü+¨NÓ;Ð;ä
Ð.¬t°NÓ/CÐ.DÐEÓ
FÐFr,   c                 óv  — t        | t        j                  «      r€t        | j                  «      dk(  rh| j
                  t        j                  k(  r| j                  t        j                  «      } | dd…dd…df   d| dd…dd…df   z  z   d| dd…dd…df   z  z   S t        | d   d| d   z  z   d| d   z  z   «      S )z*
    Converts RGB color to unique ID.
    é   Nr   é   r   i   r   )
r    r!   r"   re   rO   r/   r8   r2   Úint32r:   )Úcolors    r*   Ú	rgb_to_idrÃ   ˆ  s¦   € ô �%œŸ™Ô$¬¨U¯[©[Ó)9¸QÒ)>Ø�;‰;œ"Ÿ(™(Ò"Ø—L‘L¤§¡Ó*ˆEØ’Qš˜1�W‰~  eªAªq°!¨G¡nÑ 4Ñ4°yÀ5ÊÊAÈqÈÁ>Ñ7QÑQÐQÜˆu�Q‰x˜#  a¡™.Ñ(¨9°u¸Q±xÑ+?Ñ?Ó@Ð@r,   c                 ó€  — t        | t        j                  «      rx| j                  «       }t	        t        | j                  «      dgz   «      }t        j                  |t        j                  ¬«      }t        d«      D ]  }|dz  |d|f<   |dz  }Œ |S g }t        d«      D ]  }|j                  | dz  «       | dz  } Œ |S )z*
    Converts unique ID to RGB color.
    r¿   ry   rÀ   .)r    r!   r"   Úcopyrc   rd   rO   Úzerosr8   ÚrangeÚappend)Úid_mapÚid_map_copyÚ	rgb_shapeÚrgb_mapÚirÂ   Ú_s          r*   Ú	id_to_rgbrÏ   “  s¹   € ô �&œ"Ÿ*™*Ô%Ø—k‘k“mˆÜœ$˜vŸ|™|Ó,°¨sÑ2Ó3ˆ	Ü—(‘(˜9¬B¯H©HÔ5ˆÜ�q“ò 	 ˆAØ)¨CÑ/ˆG�C˜�F‰OØ˜CÑ‰Kð	 ð ˆØ€EÜ�1‹Xò ˆØ�‰�V˜c‘\Ô"Ø�3‰‰ðð €Lr,   c                   ó    — e Zd ZdZdZdZdZdZy)ÚPaddingModezP
    Enum class for the different padding modes to use when padding images.
    ÚconstantÚreflectÚ	replicateÚ	symmetricN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚCONSTANTÚREFLECTÚ	REPLICATEÚ	SYMMETRIC© r,   r*   rÑ   rÑ   ¦  s   „ ñð €HØ€GØ€IØ�Ir,   rÑ   g        ÚpaddingrI   Úconstant_valuesc                 óô  ‡ ‡— ‰€t        ‰ «      Šˆ ˆfd„} ||«      }|t        j                  k(  r" ||«      }t        j                  ‰ |d|¬«      Š n’|t        j
                  k(  rt        j                  ‰ |d¬«      Š nf|t        j                  k(  rt        j                  ‰ |d¬«      Š n:|t        j                  k(  rt        j                  ‰ |d¬«      Š nt        d|› �«      ‚|�t        ‰ |‰«      Š ‰ S ‰ Š ‰ S )	a›  
    Pads the `image` with the specified (height, width) `padding` and `mode`.

    Args:
        image (`np.ndarray`):
            The image to pad.
        padding (`int` or `Tuple[int, int]` or `Iterable[Tuple[int, int]]`):
            Padding to apply to the edges of the height, width axes. Can be one of three formats:
            - `((before_height, after_height), (before_width, after_width))` unique pad widths for each axis.
            - `((before, after),)` yields same before and after pad for height and width.
            - `(pad,)` or int is a shortcut for before = after = pad width for all axes.
        mode (`PaddingMode`):
            The padding mode to use. Can be one of:
                - `"constant"`: pads with a constant value.
                - `"reflect"`: pads with the reflection of the vector mirrored on the first and last values of the
                  vector along each axis.
                - `"replicate"`: pads with the replication of the last value on the edge of the array along each axis.
                - `"symmetric"`: pads with the reflection of the vector mirrored along the edge of the array.
        constant_values (`float` or `Iterable[float]`, *optional*):
            The value to use for the padding if `mode` is `"constant"`.
        data_format (`str` or `ChannelDimension`, *optional*):
            The channel dimension format for the output image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            If unset, will use same as the input image.
        input_data_format (`str` or `ChannelDimension`, *optional*):
            The channel dimension format for the input image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            If unset, will use the inferred format of the input image.

    Returns:
        `np.ndarray`: The padded image.

    c                 ó  •— t        | t        t        f«      r	| | f| | ff} n«t        | t        «      r#t	        | «      dk(  r| d   | d   f| d   | d   ff} nxt        | t        «      r&t	        | «      dk(  rt        | d   t        «      r| | f} nBt        | t        «      r$t	        | «      dk(  rt        | d   t        «      r| } nt        d| › �«      ‚‰t        j                  k(  rdg| ¢­ng | ¢d‘­} ‰j                  dk(  rdg| ¢­} | S | } | S )za
        Convert values to be in the format expected by np.pad based on the data format.
        r   r   r   zUnsupported format: )r   r   é   )	r    r:   rS   rc   re   r(   r	   r%   rs   )Úvaluesr   r0   s    €€r*   Ú_expand_for_data_formatz$pad.<locals>._expand_for_data_formatß  s  ø€ ô �fœs¤E˜lÔ+Ø˜vÐ&¨°Ð(8Ð9‰FÜ˜¤Ô&¬3¨v«;¸!Ò+;Ø˜a‘y &¨¡)Ð,¨v°a©y¸&À¹)Ð.DÐE‰FÜ˜¤Ô&¬3¨v«;¸!Ò+;Ä
È6ÐRSÉ9ÔVYÔ@ZØ˜fÐ%‰FÜ˜¤Ô&¬3¨v«;¸!Ò+;Ä
È6ÐRSÉ9ÔV[Ô@\Ø‰FäÐ3°F°8Ð<Ó=Ð=ð '8Ô;K×;QÑ;QÒ&Q�&Ð"˜6Ò"ÐWhÐY_ÐWhÐagÑWhˆð "'§¡¨q¢�!��f‘ˆØˆð 7=ˆØˆr,   rÒ   )rI   rà   rÓ   rH   ÚedgerÕ   zInvalid padding mode: )
r   rÑ   rÚ   r!   ÚpadrÛ   rÜ   rÝ   r(   r+   )r   rß   rI   rà   r.   r0   rå   s   `    ` r*   rç   rç   ±  sï   ù€ ðV Ð Ü:¸5ÓAÐõñ, & gÓ.€GàŒ{×#Ñ#Ò#Ù1°/ÓBˆÜ—‘�u˜g¨JÈÔX‰Ø	”×$Ñ$Ò	$Ü—‘�u˜g¨IÔ6‰Ø	”×&Ñ&Ò	&Ü—‘�u˜g¨FÔ3‰Ø	”×&Ñ&Ò	&Ü—‘�u˜g¨KÔ8‰äÐ1°$°Ð8Ó9Ð9àR]ÐRiÔ'¨¨{Ð<MÓN€EØ€Lð pu€EØ€Lr,   c                 ó¸   — t        t        dg«       t        | t        j                  j                  «      s| S | j
                  dk(  r| S | j                  d«      } | S )zË
    Converts an image to RGB format. Only converts if the image is of type PIL.Image.Image, otherwise returns the image
    as is.
    Args:
        image (Image):
            The image to convert.
    rD   ÚRGB)r   Úconvert_to_rgbr    rK   rL   rI   Úconvert)r   s    r*   rê   rê     sK   € ô ”n x jÔ1ä�eœSŸY™YŸ_™_Ô-Øˆà‡z�z�UÒØˆà�M‰M˜%Ó €EØ€Lr,   c                 óØ   — |€t        | «      n|}|t        j                  k(  r| dddd…f   } n,|t        j                  k(  r| ddd…df   } nt	        d|› �«      ‚|�t        | ||¬«      } | S )a½  
    Flips the channel order of the image.

    If the image is in RGB format, it will be converted to BGR and vice versa.

    Args:
        image (`np.ndarray`):
            The image to flip.
        data_format (`ChannelDimension`, *optional*):
            The channel dimension format for the output image. Can be one of:
                - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            If unset, will use same as the input image.
        input_data_format (`ChannelDimension`, *optional*):
            The channel dimension format for the input image. Can be one of:
                - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `ChannelDimension.LAST`: image in (height, width, num_channels) format.
            If unset, will use the inferred format of the input image.
    N.rE   zUnsupported channel dimension: rp   )r   r	   r'   r%   r(   r+   )r   r.   r0   s      r*   Úflip_channel_orderrí     s‹   € ð0 BSÐAZÔ6°uÔ=Ð`qÐàÔ,×1Ñ1Ò1Ø�c™4˜R˜4�iÑ ‰Ø	Ô.×4Ñ4Ò	4Ø‘d˜�d˜C�iÑ ‰äÐ:Ð;LÐ:MÐNÓOÐOàÐÜ+¨E°;ÐRcÔdˆØ€Lr,   c                 óF   — | j                  «       r| S | j                  «       S ©N)Úis_floating_pointrS   )Úxs    r*   Ú_cast_tensor_to_floatrò   B  s   € Ø×ÑÔØˆØ�7‰7‹9Ðr,   Úimagesc           	      ó8  — i }i }t        | «      D ]G  \  }}|j                  dd }||vrg ||<   ||   j                  |«       |t        ||   «      dz
  f||<   ŒI |j	                  «       D �� ci c]  \  }} |t        j                  | d¬«      “Œ }}} ||fS c c} }w )a  
    Groups images by shape.
    Returns a dictionary with the shape as key and a list of images with that shape as value,
    and a dictionary with the index of the image in the original list as key and the shape and index in the grouped list as value.
    r   Nr   r™   )Ú	enumeraterO   rÈ   re   Úitemsr�   rž   )ró   Úgrouped_imagesÚgrouped_images_indexrÍ   r   rO   s         r*   Úgroup_images_by_shaperù   H  sÂ   € ð €NØÐÜ˜fÓ%ò J‰ˆˆ5Ø—‘˜A˜B�ˆØ˜Ñ&Ø$&ˆN˜5Ñ!Ø�uÑ×$Ñ$ UÔ+Ø#(¬#¨n¸UÑ.CÓ*DÀqÑ*HÐ"IÐ˜QÒðJð N\×MaÑMaÓMc×d¹M¸EÀ6�eœUŸ[™[¨°QÔ7Ñ7Ðd€NÑdØÐ/Ð/Ð/ùó es   Á-"BÚprocessed_imagesrø   c                 ót   — t        t        |«      «      D �cg c]  }| ||   d      ||   d      ‘Œ c}S c c}w )z>
    Reconstructs a list of images in the original order.
    r   r   )rÇ   re   )rú   rø   rÍ   s      r*   Úreorder_imagesrü   ]  sO   € ô ”sÐ/Ó0Ó1öàð 	Ð-¨aÑ0°Ñ3Ñ4Ð5IÈ!Ñ5LÈQÑ5OÓPòð ùò s   —5c                   ó0   — e Zd ZdZdej
                  fd„Zy)ÚNumpyToTensorz4
    Convert a numpy array to a PyTorch tensor.
    r   c                 ój   — t        j                  |j                  ddd«      «      j                  «       S )Nr   r   r   )r�   Ú
from_numpyr&   Ú
contiguous)Úselfr   s     r*   Ú__call__zNumpyToTensor.__call__n  s+   € ô ×Ñ §¡°°1°aÓ 8Ó9×DÑDÓFÐFr,   N)rÖ   r×   rØ   rÙ   r!   r"   r  rÞ   r,   r*   rþ   rþ   i  s   „ ñðG˜bŸj™jô Gr,   rþ   rï   )NNN)TNN)NNNTN)NN)r–   r@   r   r@   )r–   rA   r   rA   )r¦   r@   r   r@   )r¦   rA   r   rA   )IÚcollections.abcr   r   Úmathr   Útypingr   r   rM   r!   Úimage_utilsr	   r
   r   r   r   Úutilsr   r   r   r   r   Úutils.import_utilsr   r   r   r   r   rK   r   r�   Ú
tensorflowrª   Ú	jax.numpyÚjnpr"   Ústrr+   r|   rS   r/   r5   r?   ÚboolrJ   rc   r:   r_   rd   rk   rq   r€   rƒ   r¢   r§   r¬   r¯   r¶   r¹   r»   r½   rÃ   rÏ   rÑ   rÚ   rç   rê   rí   rò   Údictrù   rü   rþ   rÞ   r,   r*   ú<module>r     s  ð÷ 1Ý ß "ã ÷õ ÷ ZÕ Y÷õ ñ ÔÛå/áÔÛáÔÛáÔÝð AEñ$Ø�:‰:ð$àÐ'¨Ð,Ñ-ð$ð   Ð&6¸Ð&;Ñ <Ñ=ð$ð ‡Z�Zó	$ðT /3Ø—j‘jØ@Dñ#Ø�:‰:ð#àð#ð Ð*Ñ+ð#ð �8‰8ð	#ð
    cÐ+;Ð&;Ñ <Ñ=ð#ð ‡Z�Zó#òLð: "&Ø $Ø@Dñ	37Ø�—‘Ð.°ÀÈ]ÐZÑ[ð37à˜‘ð37ð ˜‘ð37ð    cÐ+;Ð&;Ñ <Ñ=ð	37ð
 ó37ñl$À5ÈÈcÈÁ?ó $ðV #Ø"Ø@Dñ@OØ—‘ð@Oà
��U˜3 ˜8‘_ d¨3¡i°°s±Ð;Ñ
<ð@Oð ð@Oð �s‰mð	@Oð
    cÐ+;Ð&;Ñ <Ñ=ð@Oð ó@OðL &*Ø"&Ø.2ØØ@DñDØ�:‰:ðDà
��S�‰/ðDð #ðDð ˜3‘-ð	Dð
 Ð*Ñ+ðDð ðDð    cÐ+;Ð&;Ñ <Ñ=ðDð ‡Z�ZóDðV /3Ø@Dñ:Ø�:‰:ð:à
��z %Ñ(Ð(Ñ
)ð:ð 
ˆu�j Ñ'Ð'Ñ	(ð:ð Ð*Ñ+ð	:ð
    cÐ+;Ð&;Ñ <Ñ=ð:ð ‡Z�Zó:ð@ ;?Ø@Dñ	QØ�:‰:ðQà
��S�‰/ðQð ˜% Ð%5Ð 5Ñ6Ñ7ðQð    cÐ+;Ð&;Ñ <Ñ=ð	Qð
 ‡Z�ZóQóhð°2·:±:ð À"Ç*Á*ó óðF¨Jð F¸:ó Fó*"ð°B·J±Jð À2Ç:Á:ó óðG¨Zð G¸Jó Gò.Aòô&�,ô ð $×,Ñ,Ø58Ø:>Ø@DñSØ�:‰:ðSà�3˜˜c 3˜h™¨°%¸¸S¸±/Ñ)BÐBÑCðSð ðSð ˜5 (¨5¡/Ð1Ñ2ð	Sð
 ˜% Ð%5Ð 5Ñ6Ñ7ðSð    cÐ+;Ð&;Ñ <Ñ=ðSð ‡Z�ZóSðn˜*ð ¨ó ð, /3Ø@Dñ#Ø�:‰:ð#àÐ*Ñ+ð#ð    cÐ+;Ð&;Ñ <Ñ=ð#ð ‡Z�Zó	#òLð0Ø�Ñ ð0à
ˆ4��c˜3�h‘  nÑ!5Ð5Ñ6¸¸SÀ%ÈÈcÐSVÈhÉÐY\ÐH\ÑB]Ð=]Ñ8^Ð^Ñ_ó0ð*	Ø˜5  c ™?¨NÐ:Ñ;ð	ØSWÐX[Ð]bÐcfÐhkÐckÑ]lÐXlÑSmð	à	ˆ.Ñó	÷Gò Gr,   