§
    [zni\„  ã                   óŠ  — d dl Z d dlmZmZmZ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! 	 d=dej"        d	ee
e#f         d
eee
e#f                  dej"        fd„Z$dej%        dfdej"        de&dee
         dej'        deee#e
f                  dej"        fd„Z(d„ Z)	 	 d>deej"        ddddf         dee*         deee#e
f                  ddfd„Z+	 	 	 d?dej"        dee,ee,e,f         ee,         ee,         f         de*dee,         deee#e
f                  de-fd„Z.	 	 	 	 	 d@dej"        dee,e,f         dd d!ee,         dee
         d"e*deee#e
f                  dej"        fd#„Z/	 	 d>dej"        d$ee&ee&         f         d%ee&ee&         f         dee
         deee#e
f                  dej"        fd&„Z0	 	 	 dAdej"        dee,e,f         deee#e
f                  deee#e
f                  d"ee*         dej"        fd'„Z1dBd)„Z2d(ej"        dej"        fd*„Z3dCd+„Z4d(edefd,„Z5dDd.„Z6d-ej"        dej"        fd/„Z7dEd0„Z8d-edefd1„Z9d2„ Z:d3„ Z; G d4„ d5e¦  «        Z<e<j=        d6ddfdej"        d7ee,ee,e,f         eee,e,f                  f         d8e<d9ee&ee&         f         deee#e
f                  deee#e
f                  dej"        fd:„Z>dedefd;„Z?	 	 d>dej"        dee
         deee#e
f                  dej"        fd<„Z@dS )Fé    N)ÚIterableÚListÚOptionalÚTupleÚUnioné   )Ú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                 ó¤  — t          | t          j        ¦  «        st          dt	          | ¦  «        › �¦  «        ‚|€t          | ¦  «        }t          |¦  «        }||k    r| S |t          j        k    r|                      d¦  «        } nH|t          j	        k    r|                      d¦  «        } n"t          d 
                    |¦  «        ¦  «        ‚| S )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 N)é   r   r   )r   r   r   z(Unsupported channel dimension format: {})Ú
isinstanceÚnpÚndarrayÚ
ValueErrorÚtyper   r	   ÚFIRSTÚ	transposeÚLASTÚformat)r   r   r   Útarget_channel_dims       ú}/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/image_transforms.pyÚto_channel_dimension_formatr+   5   sÏ   € õ& �e�RœZÑ(Ô(ð WÝÐUÍÈUÉÌÐUÐUÑVÔVÐVàÐ Ý:¸5ÑAÔAÐå)¨+Ñ6Ô6ÐØÐ.Ò.Ð.ØˆàÕ-Ô3Ò3Ð3Ø—’ 	Ñ*Ô*ˆˆØ	Õ/Ô4Ò	4Ð	4Ø—’ 	Ñ*Ô*ˆˆåÐC×JÒJÈ;ÑWÔWÑXÔXÐXà€Ló    ÚscaleÚdata_formatÚdtypeÚinput_data_formatc                 óÒ   — t          | t          j        ¦  «        st          dt	          | ¦  «        › �¦  «        ‚| |z  }|�t          |||¦  «        }|                     |¦  «        }|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$   r+   Úastype)r   r-   r.   r/   r0   Úrescaled_images         r*   Úrescaler4   \   sp   € õ4 �e�RœZÑ(Ô(ð WÝÐUÍÈUÉÌÐUÐUÑVÔVÐVà˜U‘]€NØÐÝ4°^À[ÐRcÑdÔdˆà#×*Ò*¨5Ñ1Ô1€NàÐr,   c                 óF  — | j         t          j        k    rd}�nt          j        | |                      t
          ¦  «        ¦  «        rmt          j        d| k    ¦  «        rt          j        | dk    ¦  «        rd}n§t          d|                      ¦   «         › d|  	                    ¦   «         › d�¦  «        ‚t          j        d| k    ¦  «        rt          j        | dk    ¦  «        rd}n:t          d	|                      ¦   «         › d|  	                    ¦   «         › d�¦  «        ‚|S )
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ÒÐØˆ
‰
Ý	Œ�U˜EŸLšL­Ñ-Ô-Ñ	.Ô	.ð 
ÝŒ6�!�u’*ÑÔð 	¥"¤&¨°#ªÑ"6Ô"6ð 	ØˆJˆJåðZØŸ	š	™œðZð ZØ',§y¢y¡{¤{ðZð Zð Zñô ð õ 
Œ��U’
Ñ	Ô	ð 
¥¤ u°¢zÑ 2Ô 2ð 
Øˆ
ˆ
åðVØ—I’I‘K”KðVð VØ#(§9¢9¡;¤;ðVð Vð Vñ
ô 
ð 	
ð Ðr,   zPIL.Image.Imageútorch.Tensorú	tf.Tensorzjnp.ndarrayr=   c                 óþ  — t          t          dg¦  «         t          | t          j        j        ¦  «        r| S t          | ¦  «        st          | ¦  «        r|                      ¦   «         } nmt          | ¦  «        rt          j
        | ¦  «        } nIt          | t          j        ¦  «        s/t          d                     t          | ¦  «        ¦  «        ¦  «        ‚t          | t           j        |¦  «        } | j        d         dk    rt          j        | d¬¦  «        n| } |€t)          | ¦  «        n|}|rt+          | d¦  «        } |                      t          j        ¦  «        } t          j                             | ¦  «        S )aI  
    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.
        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   ©ÚaxisNr6   )r   Úto_pil_imager    ÚPILÚImager   r   Únumpyr   r!   Úarrayr"   r#   r(   r$   r+   r	   r'   ÚshapeÚsqueezer>   r4   r2   r7   Ú	fromarray)r   r=   r0   s      r*   rF   rF   �   sY  € õ, •l X JÑ/Ô/Ð/å�%�œœÑ)Ô)ð Øˆõ �uÑÔð S¥¨eÑ!4Ô!4ð SØ—’‘”ˆˆÝ	�uÑ	Ô	ð SÝ”˜‘”ˆˆÝ˜�rœzÑ*Ô*ð SÝÐ=×DÒDÅTÈ%Á[Ä[ÑQÔQÑRÔRÐRõ (¨Õ/?Ô/DÐFWÑXÔX€Eð +0¬+°b¬/¸QÒ*>Ð*>�BŒJ�u 2Ð&Ñ&Ô&Ð&ÀE€Eð 8BÐ7IÕ,¨UÑ3Ô3Ð3Èz€Jàð $Ý˜˜sÑ#Ô#ˆà�LŠL�œÑ"Ô"€EÝŒ9×Ò˜uÑ%Ô%Ð%r,   TÚinput_imageÚsizeÚdefault_to_squareÚmax_sizec                 óê  — t          |t          t          f¦  «        rMt          |¦  «        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  ¦  «        }}
|�8||	k    rt	          d|› d|› �¦  «        ‚||k    rt          ||
z  |z  ¦  «        |}}
||k    r||
fn|
|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 tupleNzmax_size = zN must be strictly greater than the requested size for the smaller edge size = )r    ÚtupleÚlistÚlenr#   r   r9   )rN   rO   rP   rQ   r0   ÚheightÚwidthÚshortÚlongÚrequested_new_shortÚ	new_shortÚnew_longs               r*   Úget_resize_output_image_sizer]   Ñ   sM  € õJ �$�¥˜Ñ&Ô&ð XÝˆt‰9Œ9˜Š>ˆ>Ý˜‘;”;ÐÝ�‰YŒY˜!Š^ˆ^à˜”7ˆDˆDåÐVÑWÔWÐWàð Ø�dˆ|Ðå" ;Ð0AÑBÔB�M€FˆEØ%*¨f¢_ _�5˜&�/�/¸6À5¸/�K€Eˆ4ØÐà-­sÐ3FÈÑ3MÐPUÑ3UÑ/VÔ/Vˆx€IàÐØÐ*Ò*Ð*Ýð;˜hð ;ð ;Ø48ð;ð ;ñô ð ð �hÒÐÝ"% h°Ñ&:¸XÑ&EÑ"FÔ"FÈ�xˆIà$)¨V¢O OˆH�iÐ Ð ¸)ÀXÐ9NÐNr,   Úresampler   Úreducing_gapÚreturn_numpyc                 óX  — t          t          dg¦  «         |�|nt          j        }t	          |¦  «        dk    st          d¦  «        ‚|€t          | ¦  «        }|€|n|}d}t          | t          j	        j	        ¦  «        s!t          | ¦  «        }t          | ||¬¦  «        } |\  }}	|                      |	|f||¬¦  «        }
|rgt          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.
    rB   Nr   zsize must have 2 elementsF)r=   r0   )r^   r_   rC   rD   ©r   gp?)r   Úresizer   ÚBILINEARrU   r#   r   r    rG   rH   r>   rF   r!   rJ   ÚndimÚexpand_dimsr+   r	   r'   r4   )r   rO   r^   r_   r.   r`   r0   r=   rV   rW   Úresized_images              r*   rc   rc     sW  € õB •f˜x˜jÑ)Ô)Ð)à#Ð/ˆxˆxÕ5GÔ5P€Håˆt‰9Œ9˜Š>ˆ>ÝÐ4Ñ5Ô5Ð5ð Ð Ý:¸5ÑAÔAÐØ'2Ð':Ð#Ð#À€Kð €JÝ�e�SœYœ_Ñ-Ô-ð `Ý0°Ñ7Ô7ˆ
Ý˜U¨zÐM^Ð_Ñ_Ô_ˆØ�M€FˆEà—L’L %¨ ¸8ÐR^�LÑ_Ô_€Màð YÝœ Ñ/Ô/ˆð CPÔBTÐXYÒBYÐBY�œ }¸2Ð>Ñ>Ô>Ð>Ð_lˆå3Ø˜;Õ:JÔ:Oð
ñ 
ô 
ˆð
 <FÐX� ¨wÑ7Ô7Ð7È=ˆØÐr,   ÚmeanÚstdc                 óæ  — t          | t          j        ¦  «        st          d¦  «        ‚|€t	          | ¦  «        }t          | |¬¦  «        }| j        |         }t          |t          ¦  «        r6t          |¦  «        |k    r"t          d|› dt          |¦  «        › �¦  «        ‚n|g|z  }t          j	        || j
        ¬¦  «        }t          |t          ¦  «        r6t          |¦  «        |k    r"t          d|› dt          |¦  «        › �¦  «        ‚n|g|z  }t          j	        || j
        ¬¦  «        }|t          j        k    r	| |z
  |z  } n| j        |z
  |z  j        } |�t          | ||¦  «        n| } | 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 `Iterable[float]`):
            The mean to use for normalization.
        std (`float` or `Iterable[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 arrayN)r0   zmean must have z$ elements if it is an iterable, got ©r/   zstd must have )r    r!   r"   r#   r   r   rK   r   rU   rJ   r/   r	   r'   ÚTr+   )r   rh   ri   r.   r0   Úchannel_axisÚnum_channelss          r*   Ú	normalizero   [  s™  € õ0 �e�RœZÑ(Ô(ð 8ÝÐ6Ñ7Ô7Ð7àÐ Ý:¸5ÑAÔAÐÝ-¨eÐGXÐYÑYÔY€LØ”;˜|Ô,€Lå�$�Ñ!Ô!ð %Ýˆt‰9Œ9˜Ò$Ð$ÝÐl¨|ÐlÐlÕadÐeiÑajÔajÐlÐlÑmÔmÐmð %ð ˆv˜Ñ$ˆÝŒ8�D ¤Ð,Ñ,Ô,€Då�#•xÑ Ô ð #Ýˆs‰8Œ8�|Ò#Ð#ÝÐj¨lÐjÐjÕ`cÐdgÑ`hÔ`hÐjÐjÑkÔkÐkð $ð ˆe�lÑ"ˆÝ
Œ(�3˜eœkÐ
*Ñ
*Ô
*€CàÕ,Ô1Ò1Ð1Ø˜‘ Ñ$ˆˆà”'˜D‘. CÑ'Ô*ˆàR]ÐRiÕ'¨¨{Ð<MÑNÔNÐNÐot€EØ€Lr,   c                 óä  — t          t          dg¦  «         |�t          j        dt          ¦  «         |€dn|}t          | t          j        ¦  «        st          dt          | ¦  «        › �¦  «        ‚t          |t          ¦  «        rt          |¦  «        dk    rt          d¦  «        ‚|€t          | ¦  «        }|�|n|}t          | t          j        |¦  «        } t!          | t          j        ¦  «        \  }}|\  }}	t#          |¦  «        t#          |	¦  «        }	}||z
  dz  }
|
|z   }||	z
  dz  }||	z   }|
dk    r>||k    r8|dk    r2||k    r,| d	|
|…||…f         } t          | |t          j        ¦  «        } | S t%          ||¦  «        }t%          |	|¦  «        }| j        dd
…         ||fz   }t          j        | |¬¦  «        }||z
  dz  }||z   }||z
  dz  }||z   }| |d	||…||…f<   |
|z  }
||z  }||z  }||z  }|d	t%          d|
¦  «        t+          ||¦  «        …t%          d|¦  «        t+          ||¦  «        …f         }t          ||t          j        ¦  «        }|st-          |¦  «        }|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.
        return_numpy (`bool`, *optional*):
            Whether or not to return the cropped image as a numpy array. Used for backwards compatibility with the
            previous ImageFeatureExtractionMixin method.
                - Unset: will return the same type as the input image.
                - `True`: will return a numpy array.
                - `False`: will return a `PIL.Image.Image` object.
    Returns:
        `np.ndarray`: The cropped image.
    rB   Nz8return_numpy is deprecated and will be removed in v.4.33Tr   r   zOsize must have 2 elements representing the height and width of the output imager   .éþÿÿÿ)rK   )r   Úcenter_cropÚwarningsÚwarnÚFutureWarningr    r!   r"   r#   r$   r   rU   r   r+   r	   r%   r   r9   r<   rK   Ú
zeros_liker;   rF   )r   rO   r.   r0   r`   Ú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*   rr   rr   ’  sÜ  € õF •k H :Ñ.Ô.Ð.àÐÝŒÐPÕR_Ñ`Ô`Ð`à'Ð/�4�4°\€Lå�e�RœZÑ(Ô(ð WÝÐUÍÈUÉÌÐUÐUÑVÔVÐVå�d�HÑ%Ô%ð l­¨T©¬°aª¨ÝÐjÑkÔkÐkàÐ Ý:¸5ÑAÔAÐØ(3Ð(?˜˜ÐEVÐõ (¨Õ/?Ô/EÐGXÑYÔY€Eå,¨UÕ4DÔ4JÑKÔKÑ€K�Ø"Ñ€K�Ý! +Ñ.Ô.µ°J±´�€Kð ˜Ñ$¨Ñ
*€CØ�;Ñ€Fà˜Ñ#¨Ñ)€DØ�:Ñ€Eð ˆa‚x€x�F˜kÒ)Ð)¨d°aªi¨i¸EÀZÒ<OÐ<OØ�c˜3˜v˜: t¨E zÐ1Ô2ˆÝ+¨EÐ3EÕGWÔG]Ñ^Ô^ˆØˆõ �[ +Ñ.Ô.€JÝ�J 
Ñ+Ô+€IØ”˜C˜R˜CÔ  J°	Ð#:Ñ:€IÝ”˜e¨9Ð5Ñ5Ô5€Ið ˜KÑ'¨AÑ-€GØ˜;Ñ&€JØ˜JÑ&¨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ÐDÅcÈ!ÈTÁlÄlÕUXÐYbÐdiÑUjÔUjÐFjÐjÔk€IÝ+¨IÐ7IÕK[ÔKaÑbÔb€Iàð ,Ý  Ñ+Ô+ˆ	àÐr,   Úbboxes_centerc                 óž   — |                       d¦  «        \  }}}}t          j        |d|z  z
  |d|z  z
  |d|z  z   |d|z  z   gd¬¦  «        }|S )NrC   ç      à?©Údim©ÚunbindÚtorchÚstack)rˆ   Úcenter_xÚcenter_yrW   rV   Úbbox_cornerss         r*   Ú_center_to_corners_format_torchr”   õ  st   € Ø(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Š   rC   rD   ©rl   r!   r�   ©rˆ   r‘   r’   rW   rV   Úbboxes_cornerss         r*   Ú_center_to_corners_format_numpyr™   ÿ  sg   € Ø(5¬Ñ%€Hˆh˜˜vÝ”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 )NrC   rD   rŠ   ©ÚtfÚunstackr�   r—   s         r*   Ú_center_to_corners_format_tfrž   	  st   € Ý(*¬
°=ÀrÐ(JÑ(JÔ(JÑ%€Hˆh˜˜vÝ”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 coodinates 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¡     s�   € õ �}Ñ%Ô%ð ;Ý.¨}Ñ=Ô=Ð=Ý	�M¥2¤:Ñ	.Ô	.ð ;Ý.¨}Ñ=Ô=Ð=Ý	�mÑ	$Ô	$ð ;Ý+¨MÑ:Ô:Ð:å
ÐD­t°MÑ/BÔ/BÐDÐDÑ
EÔ
EÐEr,   r˜   c                 ó’   — |                       d¦  «        \  }}}}||z   dz  ||z   dz  ||z
  ||z
  g}t          j        |d¬¦  «        S )NrC   r   r‹   r�   )r˜   Ú
top_left_xÚ
top_left_yÚbottom_right_xÚbottom_right_yÚbs         r*   Ú_corners_to_center_format_torchr¨   )  sg   € Ø=K×=RÒ=RÐSUÑ=VÔ=VÑ:€J�
˜N¨Nà	�nÑ	$¨Ñ)Ø	�nÑ	$¨Ñ)Ø	˜*Ñ	$Ø	˜*Ñ	$ð		€Aõ Œ;�q˜bÐ!Ñ!Ô!Ð!r,   c                 óv   — | j         \  }}}}t          j        ||z   dz  ||z   dz  ||z
  ||z
  gd¬¦  «        }|S )Nr   rC   rD   r–   ©r˜   r£   r¤   r¥   r¦   rˆ   s         r*   Ú_corners_to_center_format_numpyr«   4  se   € Ø=KÔ=MÑ:€J�
˜N¨NÝ”Hà˜.Ñ(¨AÑ-Ø˜.Ñ(¨AÑ-Ø˜jÑ(Ø˜jÑ(ð		
ð ðñ ô €Mð Ðr,   c                 ó”   — t          j        | d¬¦  «        \  }}}}t          j        ||z   dz  ||z   dz  ||z
  ||z
  gd¬¦  «        }|S )NrC   rD   r   r›   rª   s         r*   Ú_corners_to_center_format_tfr­   B  sr   € Ý=?¼ZÈÐ]_Ð=`Ñ=`Ô=`Ñ:€J�
˜N¨NÝ”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¯   P  s�   € õ �~Ñ&Ô&ð <Ý.¨~Ñ>Ô>Ð>Ý	�N¥B¤JÑ	/Ô	/ð <Ý.¨~Ñ>Ô>Ð>Ý	�nÑ	%Ô	%ð <Ý+¨NÑ;Ô;Ð;å
ÐE­t°NÑ/CÔ/CÐEÐEÑ
FÔ
FÐFr,   c                 ó’  — t          | t          j        ¦  «        r�t          | j        ¦  «        dk    ri| j        t          j        k    r|                      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"   rU   rK   r/   r7   r2   Úint32r9   )Úcolors    r*   Ú	rgb_to_idrµ   g  sÌ   € õ �%�œÑ$Ô$ð R­¨U¬[Ñ)9Ô)9¸QÒ)>Ð)>ØŒ;�"œ(Ò"Ð"Ø—L’L¥¤Ñ*Ô*ˆEØ�Q�Q�Q˜˜˜˜1�WŒ~  e¨A¨A¨A¨q¨q¨q°!¨G¤nÑ 4Ñ4°yÀ5ÈÈÈÈAÈAÈAÈqÈÄ>Ñ7QÑQÐQÝˆu�QŒx˜#  a¤™.Ñ(¨9°u¸Q´xÑ+?Ñ?Ñ@Ô@Ð@r,   c                 ó”  — t          | t          j        ¦  «        r||                      ¦   «         }t	          t          | j        ¦  «        dgz   ¦  «        }t          j        |t          j        ¬¦  «        }t          d¦  «        D ]}|dz  |d|f<   |dz  }Œ|S g }t          d¦  «        D ]}| 
                    | dz  ¦  «         | dz  } Œ |S )z*
    Converts unique ID to RGB color.
    r±   rk   r²   .)r    r!   r"   ÚcopyrS   rT   rK   Úzerosr7   ÚrangeÚappend)Úid_mapÚid_map_copyÚ	rgb_shapeÚrgb_mapÚir´   Ú_s          r*   Ú	id_to_rgbrÁ   r  sÑ   € õ �&�"œ*Ñ%Ô%ð Ø—k’k‘m”mˆÝ�$˜vœ|Ñ,Ô,°¨sÑ2Ñ3Ô3ˆ	Ý”(˜9­B¬HÐ5Ñ5Ô5ˆÝ�q‘”ð 	 ð 	 ˆAØ)¨CÑ/ˆG�C˜�F‰OØ˜CÑˆKˆKØˆØ€EÝ�1‰XŒXð ð ˆØ�Š�V˜c‘\Ñ"Ô"Ð"Ø�3‰ˆˆØ€Lr,   c                   ó"   — e Zd ZdZdZdZdZdZdS )Ú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Ø€I€I€Ir,   rÃ   g        ÚpaddingÚmodeÚconstant_valuesc                 óô  ‡ ‡— ‰€t          ‰ ¦  «        Šˆ ˆfd„} ||¦  «        }|t          j        k    r$ ||¦  «        }t          j        ‰ |d|¬¦  «        Š nŠ|t          j        k    rt          j        ‰ |d¬¦  «        Š nb|t          j        k    rt          j        ‰ |d¬¦  «        Š n:|t          j        k    rt          j        ‰ |d¬¦  «        Š nt          d	|› �¦  «        ‚|�t          ‰ |‰¦  «        n‰ Š ‰ 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.

    Nc                 ó„  •— t          | t          t          f¦  «        r	| | f| | ff} nét          | t          ¦  «        r4t	          | ¦  «        dk    r!| d         | d         f| d         | d         ff} n t          | t          ¦  «        r3t	          | ¦  «        dk    r t          | d         t          ¦  «        r| | f} nXt          | t          ¦  «        r1t	          | ¦  «        dk    rt          | d         t          ¦  «        r| } nt          d| › �¦  «        ‚‰t          j        k    rdg| ¢R ng | ¢d‘R } ‰j        dk    rdg| ¢R n| } | 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    r9   ÚfloatrS   rU   r#   r	   r%   re   )Úvaluesr   r0   s    €€r*   Ú_expand_for_data_formatz$pad.<locals>._expand_for_data_format¾  sh  ø€ õ �f�s¥E˜lÑ+Ô+ð 		>Ø˜vÐ&¨°Ð(8Ð9ˆFˆFÝ˜¥Ñ&Ô&ð 	>­3¨v©;¬;¸!Ò+;Ð+;Ø˜a”y &¨¤)Ð,¨v°a¬y¸&À¼)Ð.DÐEˆFˆFÝ˜¥Ñ&Ô&ð 	>­3¨v©;¬;¸!Ò+;Ð+;Å
È6ÐRSÌ9ÕVYÑ@ZÔ@ZÐ+;Ø˜fÐ%ˆFˆFÝ˜¥Ñ&Ô&ð 	>­3¨v©;¬;¸!Ò+;Ð+;Å
È6ÐRSÌ9ÕV[Ñ@\Ô@\Ð+;ØˆFˆFåÐ<°FÐ<Ð<Ñ=Ô=Ð=ð '8Õ;KÔ;QÒ&QÐ&Q�&Ð"˜6Ð"Ð"Ð"ÐWhÐY_ÐWhÐagÐWhÐWhˆð "'¤¨q¢ �!��f���°fˆØˆr,   rÄ   )rÒ   rÓ   rÅ   )rÒ   ÚedgerÇ   zInvalid padding mode: )
r   rÃ   rÌ   r!   ÚpadrÍ   rÎ   rÏ   r#   r+   )r   rÑ   rÒ   rÓ   r.   r0   rÙ   s   `    ` r*   rÛ   rÛ   �  s/  øø€ ðV Ð Ý:¸5ÑAÔAÐðð ð ð ð ð ð, &Ð% gÑ.Ô.€Gà�{Ô#Ò#Ð#Ø1Ð1°/ÑBÔBˆÝ”�u˜g¨JÈÐXÑXÔXˆˆØ	•Ô$Ò	$Ð	$Ý”�u˜g¨IÐ6Ñ6Ô6ˆˆØ	•Ô&Ò	&Ð	&Ý”�u˜g¨FÐ3Ñ3Ô3ˆˆØ	•Ô&Ò	&Ð	&Ý”�u˜g¨KÐ8Ñ8Ô8ˆˆåÐ8°$Ð8Ð8Ñ9Ô9Ð9àR]ÐRiÕ'¨¨{Ð<MÑNÔNÐNÐot€EØ€Lr,   c                 óž   — t          t          dg¦  «         t          | t          j        j        ¦  «        s| S |                      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.
    rB   ÚRGB)r   Úconvert_to_rgbr    rG   rH   Úconvert)r   s    r*   rÞ   rÞ   ç  sG   € õ •n x jÑ1Ô1Ð1å�e�SœYœ_Ñ-Ô-ð Øˆà�MŠM˜%Ñ Ô €EØ€Lr,   c                 óð   — |€t          | ¦  «        n|}|t          j        k    r| dddd…f         } n0|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.rC   zUnsupported channel dimension: rb   )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˜4˜R˜4�iÔ ˆˆØ	Õ.Ô4Ò	4Ð	4Ø�d�d˜�d˜C�iÔ ˆˆåÐNÐ;LÐNÐNÑOÔOÐOàÐÝ+¨E°;ÐRcÐdÑdÔdˆØ€Lr,   )N)NN)TNN)NNNTN)NNN)rˆ   r?   r   r?   )rˆ   r@   r   r@   )r˜   r?   r   r?   )r˜   r@   r   r@   )Ars   Útypingr   r   r   r   r   rI   r!   Úimage_utilsr	   r
   r   r   r   Úutilsr   r   r   r   r   Úutils.import_utilsr   r   r   r   r   rG   r   r�   Ú
tensorflowrœ   Ú	jax.numpyÚjnpr"   Ústrr+   Úfloat32r×   r/   r4   r>   ÚboolrF   r9   rS   r]   rc   ro   rr   r”   r™   rž   r¡   r¨   r«   r­   r¯   rµ   rÁ   rÃ   rÌ   rÛ   rÞ   rá   rÐ   r,   r*   ú<module>rì      sè  ðð  €€€Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9à Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ZÐ YÐ YÐ YÐ YÐ YÐ YÐ YÐ YÐ YÐ YÐ YÐ YÐ Yðð ð ð ð ð ð ð ð ð ð ð ð ð ð ÐÑÔð 0Ø€J€J€Jà/Ð/Ð/Ð/Ð/Ð/àÐÑÔð Ø€L€L€Là€?ÑÔð ØÐÐÐàÐÑÔð ØÐÐÐÐÐð AEð$ð $ØŒ:ð$àÐ'¨Ð,Ô-ð$ð   Ð&6¸Ð&;Ô <Ô=ð$ð „Zð	$ð $ð $ð $ðT /3Ø”jØ@Dð#ð #ØŒ:ð#àð#ð Ð*Ô+ð#ð Œ8ð	#ð
    cÐ+;Ð&;Ô <Ô=ð#ð „Zð#ð #ð #ð #ðLð ð ð: "&Ø@Dð0&ð 0&Ø�”Ð.°ÀÈ]ÐZÔ[ð0&à˜”ð0&ð    cÐ+;Ð&;Ô <Ô=ð0&ð ð	0&ð 0&ð 0&ð 0&ðn #Ø"Ø@Dð@Oð @OØ”ð@Oà
��U˜3 ˜8”_ d¨3¤i°°s´Ð;Ô
<ð@Oð ð@Oð �sŒmð	@Oð
    cÐ+;Ð&;Ô <Ô=ð@Oð ð@Oð @Oð @Oð @OðL &*Ø"&Ø.2ØØ@DðDð DØŒ:ðDà
��S�Œ/ðDð #ðDð ˜3”-ð	Dð
 Ð*Ô+ðDð ðDð    cÐ+;Ð&;Ô <Ô=ðDð „ZðDð Dð Dð DðV /3Ø@Dð4ð 4ØŒ:ð4à
��x ”Ð&Ô
'ð4ð 
ˆu�h˜u”oÐ%Ô	&ð4ð Ð*Ô+ð	4ð
    cÐ+;Ð&;Ô <Ô=ð4ð „Zð4ð 4ð 4ð 4ðt ;?Ø@DØ#'ð`ð `ØŒ:ð`à
��S�Œ/ð`ð ˜% Ð%5Ð 5Ô6Ô7ð`ð    cÐ+;Ð&;Ô <Ô=ð	`ð
 ˜4”.ð`ð „Zð`ð `ð `ð `ðFð ð ð ð°2´:ð À"Ä*ð ð ð ð ðð ð ð ðF¨Jð F¸:ð Fð Fð Fð Fð*"ð "ð "ð "ð°B´Jð À2Ä:ð ð ð ð ðð ð ð ðG¨Zð G¸Jð Gð Gð Gð Gð.Að Að Aðð ð ð&ð ð ð ð �,ñ ô ð ð $Ô,Ø58Ø:>Ø@DðSð 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ðSð Sð Sð Sðn˜*ð ¨ð ð ð ð ð( /3Ø@Dð#ð #ØŒ:ð#àÐ*Ô+ð#ð    cÐ+;Ð&;Ô <Ô=ð#ð „Zð	#ð #ð #ð #ð #ð #r,   