Ë
    S^(h½€  ã                   ó€  — d dl mZ d dlmZmZ d dlmZmZmZm	Z	 d dl
Zddl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mZmZmZmZm Z m!Z! dd	l"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+  e*«       rddlm,Z,  e'«       rd dl-Z- e(«       rddlm.Z.  e)«       rd dl/m0Z1 nd dl2m0Z1  e+jf                  e4«      Z5 ed¬«      dddddddddddddejl                  fdee7   dee8   dee7   dee	e8e9e8   f      dee	e8e9e8   f      dee7   dee:   dee7   dee   dee7   dee   ded   dee	e;e%f      dee   fd„«       Z<d7d d!d"ee:   d#d!fd$„Z=d%ee   d#e9e   fd&„Z>d'e9d!   d#e?e:   fd(„Z@d)e	ej‚                  d!f   d*e:d#e9e	ej‚                  d!f      fd+„ZB G d,„ d-ed.¬/«      ZCd0ZDd1ZE e&d2eD«       G d3„ d4e«      «       ZF G d5„ d6«      ZGy)8é    )ÚIterable)Ú	lru_cacheÚpartial)ÚAnyÚOptionalÚ	TypedDictÚUnionNé   )ÚBaseImageProcessorÚBatchFeatureÚget_size_dict)Úconvert_to_rgbÚget_resize_output_image_sizeÚget_size_with_aspect_ratioÚgroup_images_by_shapeÚreorder_images)ÚChannelDimensionÚ
ImageInputÚ	ImageTypeÚSizeDictÚget_image_sizeÚ#get_image_size_for_max_height_widthÚget_image_typeÚinfer_channel_dimension_formatÚmake_flat_list_of_imagesÚvalidate_kwargsÚvalidate_preprocess_arguments)ÚUnpack)Ú
TensorTypeÚadd_start_docstringsÚis_torch_availableÚis_torchvision_availableÚis_torchvision_v2_availableÚis_vision_availableÚlogging)ÚPILImageResampling)Úpil_torch_interpolation_mapping)Ú
functionalé
   ©ÚmaxsizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚdo_padÚsize_divisibilityÚdo_center_cropÚ	crop_sizeÚ	do_resizeÚsizeÚresampler&   Úreturn_tensorsÚdata_formatc                 ó’   — t        | |||||||||	|
|¬«       |�|dk7  rt        d«      ‚|t        j                  k7  rt        d«      ‚y)z¥
    Checks validity of typically used arguments in an `ImageProcessorFast` `preprocess` method.
    Raises `ValueError` if arguments incompatibility is caught.
    )r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   NÚptz6Only returning PyTorch tensors is currently supported.z6Only channel first data format is currently supported.)r   Ú
ValueErrorr   ÚFIRST)r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   s                 úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/image_processing_utils_fast.pyÚ"validate_fast_preprocess_argumentsr?   K   sk   € ô* "ØØ%Ø!ØØØØ+Ø%ØØØØõð Ð! n¸Ò&<ÜÐQÓRÐRàÔ&×,Ñ,Ò,ÜÐQÓRÐRð -ó    Útensorútorch.TensorÚaxisÚreturnc                 ón   — |€| j                  «       S 	 | j                  |¬«      S # t        $ r | cY S w xY w)zF
    Squeezes a tensor, but only if the axis specified has dim 1.
    )rC   )Úsqueezer<   )rA   rC   s     r>   Úsafe_squeezerG   v   s@   € ð €|Ø�~‰~ÓÐðØ�~‰~ 4ˆ~Ó(Ð(øÜò ØŠðús   ”& ¦4³4Ú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.
    )ÚzipÚmax)rH   Úvalues_is     r>   Úmax_across_indicesrM   ƒ   s    € ô +.¨v¨,Ö7˜hŒC��MÒ7Ð7ùÒ7s   ‹ Úimagesc                 ób   — t        | D �cg c]  }|j                  ‘Œ c}«      \  }}}||fS c c}w )zH
    Get the maximum height and width across all images in a batch.
    )rM   Úshape)rN   ÚimgÚ_Ú
max_heightÚ	max_widths        r>   Úget_max_height_widthrU   Š   s5   € ô
  2ÈÖ2OÀ°3·9³9Ò2OÓPÑ€A€z�9à˜	Ð"Ð"ùò 3Ps   Š,ÚimageÚ
patch_sizec                 óØ   — g }t        | t        j                  ¬«      \  }}t        d||«      D ]9  }t        d||«      D ]'  }| dd…|||z   …|||z   …f   }|j	                  |«       Œ) Œ; |S )a6  
    Divides an image into patches of a specified size.

    Args:
        image (`Union[np.array, "torch.Tensor"]`):
            The input image.
        patch_size (`int`):
            The size of each patch.
    Returns:
        list: A list of Union[np.array, "torch.Tensor"] representing the patches.
    )Úchannel_dimr   N)r   r   r=   ÚrangeÚappend)rV   rW   ÚpatchesÚheightÚwidthÚiÚjÚpatchs           r>   Údivide_to_patchesrb   ”   s†   € ð €GÜ" 5Ô6F×6LÑ6LÔM�M€FˆEÜ�1�f˜jÓ)ò "ˆÜ�q˜% Ó,ò 	"ˆAØš!˜Q  Z¡Ð/°°Q¸±^Ð1CÐCÑDˆEØ�N‰N˜5Õ!ñ	"ð"ð
 €Nr@   c                   óf  — e Zd ZU ee   ed<   eeeef      ed<   ee   ed<   ee	d      ed<   ee   ed<   eeeef      ed<   ee   ed<   ee	ee
f      ed	<   ee   ed
<   ee	e
ee
   f      ed<   ee	e
ee
   f      ed<   ee   ed<   ee	eef      ed<   ee   ed<   ee	eef      ed<   ed   ed<   y)ÚDefaultFastImageProcessorKwargsr5   r6   Údefault_to_square©r&   úF.InterpolationModer7   r3   r4   r,   r-   r.   r/   r0   Údo_convert_rgbr8   r9   Úinput_data_formatútorch.deviceÚdeviceN)Ú__name__Ú
__module__Ú__qualname__r   ÚboolÚ__annotations__ÚdictÚstrÚintr	   ÚfloatÚlistr   r   © r@   r>   rd   rd   ¬   sü   … Ø˜‰~ÓØ
�4˜˜S˜‘>Ñ
"Ó"Ø ‘~Ó%Ø�uÐHÑIÑJÓJØ˜T‘NÓ"Ø˜˜S #˜X™Ñ'Ó'Ø˜‘ÓØ˜U 3¨ :Ñ.Ñ/Ó/Ø˜4‘.Ó Ø˜˜u d¨5¡kÐ1Ñ2Ñ3Ó3Ø˜˜e T¨%¡[Ð0Ñ1Ñ2Ó2Ø˜T‘NÓ"Ø˜U 3¨
 ?Ñ3Ñ4Ó4ØÐ*Ñ+Ó+Ø  cÐ+;Ð&;Ñ <Ñ=Ó=Ø�^Ñ$Ô$r@   rd   F)Útotala–  

    Args:
        do_resize (`bool`, *optional*, defaults to `self.do_resize`):
            Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by the
            `do_resize` parameter in the `preprocess` method.
        size (`dict`, *optional*, defaults to `self.size`):
            Size of the output image after resizing. Can be overridden by the `size` parameter in the `preprocess`
            method.
        default_to_square (`bool`, *optional*, defaults to `self.default_to_square`):
            Whether to default to a square image when resizing, if size is an int.
        resample (`PILImageResampling`, *optional*, defaults to `self.resample`):
            Resampling filter to use if resizing the image. Only has an effect if `do_resize` is set to `True`. Can be
            overridden by the `resample` parameter in the `preprocess` method.
        do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`):
            Whether to center crop the image to the specified `crop_size`. Can be overridden by `do_center_crop` in the
            `preprocess` method.
        crop_size (`Dict[str, int]` *optional*, defaults to `self.crop_size`):
            Size of the output image after applying `center_crop`. Can be overridden by `crop_size` in the `preprocess`
            method.
        do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
            Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the
            `do_rescale` parameter in the `preprocess` method.
        rescale_factor (`int` or `float`, *optional*, defaults to `self.rescale_factor`):
            Scale factor to use if rescaling the image. Only has an effect if `do_rescale` is set to `True`. Can be
            overridden by the `rescale_factor` parameter in the `preprocess` method.
        do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
            Whether to normalize the image. Can be overridden by the `do_normalize` parameter in the `preprocess`
            method. Can be overridden by the `do_normalize` parameter in the `preprocess` method.
        image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
            Mean to use if normalizing the image. This is a float or list of floats the length of the number of
            channels in the image. Can be overridden by the `image_mean` parameter in the `preprocess` method. Can be
            overridden by the `image_mean` parameter in the `preprocess` method.
        image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
            Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
            number of channels in the image. Can be overridden by the `image_std` parameter in the `preprocess` method.
            Can be overridden by the `image_std` parameter in the `preprocess` method.
        do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
            Whether to convert the image to RGB.
        return_tensors (`str` or `TensorType`, *optional*, defaults to `self.return_tensors`):
            Returns stacked tensors if set to `pt, otherwise returns a list of tensors.
        data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.data_format`):
            Only `ChannelDimension.FIRST` is supported. Added for compatibility with slow processors.
        input_data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.input_data_format`):
            The channel dimension format for the input image. If unset, the channel dimension format is inferred
            from 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.
            - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
        device (`torch.device`, *optional*, defaults to `self.device`):
            The device to process the images on. If unset, the device is inferred from the input images.aQ  
    Preprocess an image or batch of images.

    Args:
        images (`ImageInput`):
            Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
            passing in images with pixel values between 0 and 1, set `do_rescale=False`.
        do_resize (`bool`, *optional*, defaults to `self.do_resize`):
            Whether to resize the image.
        size (`Dict[str, int]`, *optional*, defaults to `self.size`):
            Describes the maximum input dimensions to the model.
        resample (`PILImageResampling` or `InterpolationMode`, *optional*, defaults to `self.resample`):
            Resampling filter to use if resizing the image. This can be one of the enum `PILImageResampling`. Only
            has an effect if `do_resize` is set to `True`.
        do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`):
            Whether to center crop the image.
        crop_size (`Dict[str, int]`, *optional*, defaults to `self.crop_size`):
            Size of the output image after applying `center_crop`.
        do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
            Whether to rescale the image.
        rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
            Rescale factor to rescale the image by if `do_rescale` is set to `True`.
        do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
            Whether to normalize the image.
        image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
            Image mean to use for normalization. Only has an effect if `do_normalize` is set to `True`.
        image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
            Image standard deviation to use for normalization. Only has an effect if `do_normalize` is set to
            `True`.
        do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
            Whether to convert the image to RGB.
        return_tensors (`str` or `TensorType`, *optional*, defaults to `self.return_tensors`):
            Returns stacked tensors if set to `pt, otherwise returns a list of tensors.
        data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.data_format`):
            Only `ChannelDimension.FIRST` is supported. Added for compatibility with slow processors.
        input_data_format (`ChannelDimension` or `str`, *optional*, defaults to `self.input_data_format`):
            The channel dimension format for the input image. If unset, the channel dimension format is inferred
            from 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.
            - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
        device (`torch.device`, *optional*, defaults to `self.device`):
            The device to process the images on. If unset, the device is inferred from the input images.z'Constructs a fast base image processor.c                   óž  ‡ — e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZej"                  ZdZdZdgZeZdZdee   ddfˆ fd„Z	 	 d5dd	d
edddedd	f
d„Zdd	dedd	fd„Zdd	de ee!e   f   de ee!e   f   dd	fd„Z" e#d¬«      	 	 	 	 	 	 d6de$e   de$e ee%e   f      de$e ee%e   f      de$e   de$e   de$d   de&fd„«       Z'dd	dededede ee%e   f   de ee%e   f   dd	fd„Z(dd	d
e)e*e+f   dd	fd „Z,de-de-fd!„Z.de)fd"„Z/de-de-fd#„Z0	 	 	 d7de-d$e$e   d%e$e e*ef      de$d   dd	f
d&„Z1	 	 	 d7de-d$e$e   d%e$e e*ef      de$d   de%d	   f
d'„Z2	 	 	 	 	 	 d6d
e$e   d(e$e   d)e$e   de$e ee%e   f      de$e ee%e   f      d*e$e   de)fd+„Z3	 	 	 	 	 	 	 	 	 	 	 	 d8de$e   de$e   de$e   de$e ee&e   f      de$e ee&e   f      d,e$e   d
e$e   d-e$e   d(e$e   d.e$e d/      d0e$e e*e4f      d*e$e   fd1„Z5 e6e7«      de-dee   de8fd2„«       Z9de%d	   d,ed
ede$d   d-ed(edededede$e ee%e   f      de$e ee%e   f      d0e$e e*e4f      de8fd3„Z:ˆ fd4„Z;ˆ xZ<S )9ÚBaseImageProcessorFastNTgp?Úpixel_valuesÚkwargsrD   c           
      ó  •— t        ‰| �  di |¤Ž | j                  |«      }|j                  d| j                  «      }|�'t        ||j                  d| j                  «      ¬«      nd | _        |j                  d| j                  «      }|�t        |d¬«      nd | _        | j                  j                  j                  «       D ]<  }|j                  |d «      }|�t        | ||«       Œ%t        | |t        | |d «      «       Œ> y )Nr6   re   ©r6   re   r4   ©Ú
param_namerv   )ÚsuperÚ__init__Úfilter_out_unused_kwargsÚpopr6   r   re   r4   Úvalid_kwargsrp   ÚkeysÚsetattrÚgetattr)Úselfr{   r6   r4   ÚkeyÚkwargÚ	__class__s         €r>   r�   zBaseImageProcessorFast.__init__9  sñ   ø€ ô 	‰ÑÑ"˜6Ò"Ø×.Ñ.¨vÓ6ˆØ�z‰z˜& $§)¡)Ó,ˆð Ðô ˜t°v·z±zÐBUÐW[×WmÑWmÓ7nÕoàð 	Œ	ð
 —J‘J˜{¨D¯N©NÓ;ˆ	ØMVÐMbœ y¸[ÕIÐhlˆŒØ×$Ñ$×4Ñ4×9Ñ9Ó;ò 	=ˆCØ—J‘J˜s DÓ)ˆEØÐ Ü˜˜c 5Õ)ä˜˜c¤7¨4°°dÓ#;Õ<ñ	=r@   rV   rB   r6   Úinterpolationrg   Ú	antialiasc                 ó„  — |�|nt         j                  j                  }|j                  r?|j                  r3t        |j                  «       dd |j                  |j                  «      }n¿|j                  r(t        ||j                  dt        j                  ¬«      }n‹|j                  r?|j                  r3t        |j                  «       dd |j                  |j                  «      }n@|j                  r%|j                  r|j                  |j                  f}nt        d|› d�«      ‚t        j                   ||||¬«      S )a;  
        Resize an image to `(size["height"], size["width"])`.

        Args:
            image (`torch.Tensor`):
                Image to resize.
            size (`SizeDict`):
                Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
            resample (`InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`):
                `InterpolationMode` filter to use when resizing the image e.g. `InterpolationMode.BICUBIC`.

        Returns:
            `torch.Tensor`: The resized image.
        NéþÿÿÿF)r6   re   ri   zjSize must contain 'height' and 'width' keys, or 'max_height' and 'max_width', or 'shortest_edge' key. Got ú.)rŒ   r�   )ÚFÚInterpolationModeÚBILINEARÚshortest_edgeÚlongest_edger   r6   r   r   r=   rS   rT   r   r]   r^   r<   Úresize)rˆ   rV   r6   rŒ   r�   r{   Únew_sizes          r>   r–   zBaseImageProcessorFast.resizeN  s  € ð, *7Ð)B™Ì×H[ÑH[×HdÑHdˆØ×Ò $×"3Ò"3ô 2Ø—
‘
“˜R˜SÐ!Ø×"Ñ"Ø×!Ñ!ó‰Hð
 ×ÒÜ3ØØ×'Ñ'Ø"'Ü"2×"8Ñ"8ô	‰Hð �_Š_ §¢Ü:¸5¿:¹:»<ÈÈÐ;LÈdÏoÉoÐ_c×_mÑ_mÓn‰HØ�[Š[˜TŸZšZØŸ™ T§Z¡ZÐ0‰HäðØ�6˜ðóð ô �x‰x˜˜x°}ÐPYÔZÐZr@   Úscalec                 ó   — ||z  S )a?  
        Rescale an image by a scale factor. image = image * scale.

        Args:
            image (`torch.Tensor`):
                Image to rescale.
            scale (`float`):
                The scaling factor to rescale pixel values by.

        Returns:
            `torch.Tensor`: The rescaled image.
        rv   )rˆ   rV   r˜   r{   s       r>   ÚrescalezBaseImageProcessorFast.rescale  s   € ð$ �u‰}Ðr@   ÚmeanÚstdc                 ó0   — t        j                  |||«      S )aã  
        Normalize an image. image = (image - image_mean) / image_std.

        Args:
            image (`torch.Tensor`):
                Image to normalize.
            mean (`torch.Tensor`, `float` or `Iterable[float]`):
                Image mean to use for normalization.
            std (`torch.Tensor`, `float` or `Iterable[float]`):
                Image standard deviation to use for normalization.

        Returns:
            `torch.Tensor`: The normalized image.
        )r‘   Ú	normalize)rˆ   rV   r›   rœ   r{   s        r>   rž   z BaseImageProcessorFast.normalize“  s   € ô* �{‰{˜5 $¨Ó,Ð,r@   r)   r*   r.   r/   r0   r,   r-   rk   rj   c                 óŒ   — |r>|r<t        j                  ||¬«      d|z  z  }t        j                  ||¬«      d|z  z  }d}|||fS )N)rk   g      ð?F)ÚtorchrA   )rˆ   r.   r/   r0   r,   r-   rk   s          r>   Ú!_fuse_mean_std_and_rescale_factorz8BaseImageProcessorFast._fuse_mean_std_and_rescale_factorª  sO   € ñ ™,äŸ™ j¸Ô@ÀCÈ.ÑDXÑYˆJÜŸ™ Y°vÔ>À#ÈÑBVÑWˆIØˆJØ˜9 jÐ0Ð0r@   rN   c                 óâ   — | j                  ||||||j                  ¬«      \  }}}|r3| j                  |j                  t        j
                  ¬«      ||«      }|S |r| j                  ||«      }|S )z/
        Rescale and normalize images.
        )r.   r/   r0   r,   r-   rk   )Údtype)r¡   rk   rž   Útor    Úfloat32rš   )rˆ   rN   r,   r-   r.   r/   r0   s          r>   Úrescale_and_normalizez,BaseImageProcessorFast.rescale_and_normalize»  s   € ð -1×,RÑ,RØ%Ø!ØØ!Ø)Ø—=‘=ð -Só -
Ñ)ˆ
�I˜zñ Ø—^‘^ F§I¡I´E·M±M IÓ$BÀJÐPYÓZˆFð ˆñ Ø—\‘\ &¨.Ó9ˆFàˆr@   c                 ó¦   — |j                   �|j                  €t        d|j                  «       › �«      ‚t	        j
                  ||d   |d   f«      S )aº  
        Center crop an image to `(size["height"], size["width"])`. If the input size is smaller than `crop_size` along
        any edge, the image is padded with 0's and then center cropped.

        Args:
            image (`"torch.Tensor"`):
                Image to center crop.
            size (`Dict[str, int]`):
                Size of the output image.

        Returns:
            `torch.Tensor`: The center cropped image.
        z=The size dictionary must have keys 'height' and 'width'. Got r]   r^   )r]   r^   r<   r…   r‘   Úcenter_crop)rˆ   rV   r6   r{   s       r>   r¨   z"BaseImageProcessorFast.center_crop×  sS   € ð& �;‰;Ð $§*¡*Ð"4ÜÐ\Ð]a×]fÑ]fÓ]hÐ\iÐjÓkÐkÜ�}‰}˜U T¨(¡^°T¸'±]Ð$CÓDÐDr@   c                 ó   — t        |«      S )a'  
        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 (ImageInput):
                The image to convert.

        Returns:
            ImageInput: The converted image.
        )r   )rˆ   rV   s     r>   r   z%BaseImageProcessorFast.convert_to_rgbî  s   € ô ˜eÓ$Ð$r@   c                 ó¢   — | j                   €|S | j                   D ]1  }||v sŒt        j                  d|› d�«       |j                  |«       Œ3 |S )zJ
        Filter out the unused kwargs from the kwargs dictionary.
        z!This processor does not use the `z ` parameter. It will be ignored.)Úunused_kwargsÚloggerÚwarning_oncerƒ   )rˆ   r{   Ú
kwarg_names      r>   r‚   z/BaseImageProcessorFast.filter_out_unused_kwargsþ  s^   € ð ×ÑÐ%ØˆMà×,Ñ,ò 	'ˆJØ˜VÒ#Ü×#Ñ#Ð&GÈ
À|ÐSsÐ$tÔuØ—
‘
˜:Õ&ð	'ð ˆr@   c                 ó   — t        |«      S )zê
        Prepare the images structure for processing.

        Args:
            images (`ImageInput`):
                The input images to process.

        Returns:
            `ImageInput`: The images with a valid nesting.
        )r   )rˆ   rN   s     r>   Ú_prepare_images_structurez0BaseImageProcessorFast._prepare_images_structure  s   € ô (¨Ó/Ð/r@   rh   ri   c                 ó&  — t        |«      }|t        j                  t        j                  t        j                  fvrt        d|› �«      ‚|r| j                  |«      }|t        j                  k(  rt        j                  |«      }n6|t        j                  k(  r#t        j                  |«      j                  «       }|€t        |«      }|t        j                  k(  r!|j                  ddd«      j                  «       }|�|j!                  |«      }|S )NzUnsupported input image type é   r   r
   )r   r   ÚPILÚTORCHÚNUMPYr<   r   r‘   Úpil_to_tensorr    Ú
from_numpyÚ
contiguousr   r   ÚLASTÚpermuter¤   )rˆ   rV   rh   ri   rk   Ú
image_types         r>   Ú_process_imagez%BaseImageProcessorFast._process_image  sæ   € ô $ EÓ*ˆ
ØœiŸm™m¬Y¯_©_¼i¿o¹oÐNÑNÜÐ<¸Z¸LÐIÓJÐJáØ×'Ñ'¨Ó.ˆEàœŸ™Ò&Ü—O‘O EÓ*‰EØœ9Ÿ?™?Ò*ä×$Ñ$ UÓ+×6Ñ6Ó8ˆEð Ð$Ü >¸uÓ EÐàÔ 0× 5Ñ 5Ò5à—M‘M ! Q¨Ó*×5Ñ5Ó7ˆEð ÐØ—H‘H˜VÓ$ˆEàˆr@   c                 óš   — | j                  |«      }t        | j                  |||¬«      }g }|D ]  }|j                   ||«      «       Œ |S )z:
        Prepare the input images for processing.
        )rh   ri   rk   )r°   r   r¼   r[   )rˆ   rN   rh   ri   rk   Úprocess_image_fnÚprocessed_imagesrV   s           r>   Ú_prepare_input_imagesz,BaseImageProcessorFast._prepare_input_images=  sd   € ð ×/Ñ/°Ó7ˆÜ"Ø×ÑØ)Ø/Øô	
Ðð ÐØò 	=ˆEØ×#Ñ#Ñ$4°UÓ$;Õ<ð	=ð  Ðr@   r4   re   r9   c                 ó:  — |€i }|�t        d	i t        ||¬«      ¤Ž}|�t        d	i t        |d¬«      ¤Ž}t        |t        «      rt	        |«      }t        |t        «      rt	        |«      }|€t
        j                  }||d<   ||d<   ||d<   ||d<   ||d<   ||d<   |S )
z¢
        Update kwargs that need further processing before being validated
        Can be overridden by subclasses to customize the processing of kwargs.
        r}   r4   r~   r6   re   r/   r0   r9   rv   )r   r   Ú
isinstanceru   Útupler   r=   )rˆ   r6   r4   re   r/   r0   r9   r{   s           r>   Ú_further_process_kwargsz.BaseImageProcessorFast._further_process_kwargsU  s½   € ð ˆ>ØˆFØÐÜÑ\œm°ÐIZÔ[Ñ\ˆDØÐ Ü ÑT¤=°À{Ô#SÑTˆIÜ�j¤$Ô'Ü˜zÓ*ˆJÜ�i¤Ô&Ü˜iÓ(ˆIØÐÜ*×0Ñ0ˆKàˆˆv‰Ø'ˆˆ{ÑØ&7ˆÐ"Ñ#Ø)ˆˆ|ÑØ'ˆˆ{ÑØ +ˆˆ}Ñàˆr@   r5   r3   r7   rf   r8   c                 ó2   — t        |||||||||	|
||¬«       y)z@
        validate the kwargs for the preprocess method.
        )r,   r-   r.   r/   r0   r5   r6   r3   r4   r7   r8   r9   N)r?   )rˆ   r,   r-   r.   r/   r0   r5   r6   r3   r4   r7   r8   r9   r{   s                 r>   Ú_validate_preprocess_kwargsz2BaseImageProcessorFast._validate_preprocess_kwargsy  s0   € ô& 	+Ø!Ø)Ø%Ø!ØØØØ)ØØØ)Ø#ö	
r@   c           	      óš  — t        |j                  «       | j                  j                  j                  «       ¬«       | j                  j                  D ]  }|j	                  |t        | |d «      «       Œ! |j                  d«      }|j                  d«      }|j                  d«      }| j                  ||||¬«      } | j                  di |¤Ž} | j                  di |¤Ž |j                  d«      }t        |t        t        f«      r	t        |   n||d<   |j                  d«       |j                  d	«        | j                  dd
|i|¤ŽS )N)Úcaptured_kwargsÚvalid_processor_keysrh   ri   rk   )rN   rh   ri   rk   r7   rŒ   re   r9   rN   rv   )r   r…   r„   rp   Ú
setdefaultr‡   rƒ   rÀ   rÄ   rÆ   rÂ   r&   rs   r'   Ú_preprocess)rˆ   rN   r{   r®   rh   ri   rk   r7   s           r>   Ú
preprocessz!BaseImageProcessorFast.preprocess›  sF  € ä¨¯©«ÈD×L]ÑL]×LmÑLm×LrÑLrÓLtÕuð ×+Ñ+×;Ñ;ò 	KˆJØ×Ñ˜j¬'°$¸
ÀDÓ*IÕJð	Kð  Ÿ™Ð$4Ó5ˆØ"ŸJ™JÐ':Ó;ÐØ—‘˜HÓ%ˆà×+Ñ+Ø¨.ÐL]Ðflð ,ó 
ˆð
 .�×-Ñ-Ñ7°Ñ7ˆð 	)ˆ×(Ñ(Ñ2¨6Ò2ð —:‘:˜jÓ)ˆä9CÀHÔOaÔcfÐNgÔ9hÔ+¨HÒ5Ðnvð 	ˆÑð
 	�
‰
Ð&Ô'Ø�
‰
�=Ô!àˆt×ÑÑ8 vÐ8°Ñ8Ð8r@   c           	      óº  — t        |«      \  }}i }|j                  «       D ]   \  }}|r| j                  |||¬«      }|||<   Œ" t        ||«      }t        |«      \  }}i }|j                  «       D ]4  \  }}|r| j	                  ||«      }| j                  ||||	|
|«      }|||<   Œ6 t        ||«      }|rt        j                  |d¬«      n|}t        d|i|¬«      S )N)rV   r6   rŒ   r   ©Údimrz   )ÚdataÚtensor_type)	r   Úitemsr–   r   r¨   r¦   r    Ústackr   )rˆ   rN   r5   r6   rŒ   r3   r4   r,   r-   r.   r/   r0   r8   r{   Úgrouped_imagesÚgrouped_images_indexÚresized_images_groupedrP   Ústacked_imagesÚresized_imagesÚprocessed_images_groupedr¿   s                         r>   rË   z"BaseImageProcessorFast._preprocess¾  s  € ô" 0EÀVÓ/LÑ,ˆÐ,Ø!#ÐØ%3×%9Ñ%9Ó%;ò 	;Ñ!ˆE�>ÙØ!%§¡°>ÈÐ\i Ó!j�Ø,:Ð" 5Ò)ð	;ô (Ð(>Ð@TÓUˆô 0EÀ^Ó/TÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ó%;ò 	=Ñ!ˆE�>ÙØ!%×!1Ñ!1°.À)Ó!L�à!×7Ñ7Ø 
¨N¸LÈ*ÐV_óˆNð /=Ð$ UÒ+ð	=ô *Ð*BÐDXÓYÐÙCQœ5Ÿ;™;Ð'7¸QÕ?ÐWgÐä .Ð2BÐ!CÐQ_Ô`Ð`r@   c                 óH   •— t         ‰| �  «       }|j                  dd «       |S )NÚ_valid_processor_keys)r€   Úto_dictrƒ   )rˆ   Úencoder_dictr‹   s     €r>   rÜ   zBaseImageProcessorFast.to_dicté  s&   ø€ Ü‘w‘Ó(ˆØ×ÑÐ0°$Ô7ØÐr@   )NT)NNNNNN)NNN)NNNNNNNNNNNN)=rl   rm   rn   r7   r/   r0   r6   re   r4   r5   r3   r,   r-   r.   rh   r8   r   r=   r9   ri   rk   Úmodel_input_namesrd   r„   r«   r   r�   r   ro   r–   rt   rš   r	   r   rž   r   r   ru   rÃ   r¡   r¦   rq   rr   rs   r¨   r   r   r‚   r°   r¼   rÀ   rÄ   r   rÆ   r    Ú.BASE_IMAGE_PROCESSOR_FAST_DOCSTRING_PREPROCESSr   rÌ   rË   rÜ   Ú__classcell__)r‹   s   @r>   ry   ry      s  ø„ ð
 €HØ€JØ€IØ€DØÐØ€IØ€IØ€NØ€JØ€NØ€LØ€NØ€NØ"×(Ñ(€KØÐØ€FØ'Ð(ÐØ2€LØ€Mð=àÐ8Ñ9ð=ð 
õ=ð2 04Øñ/[àð/[ð ð/[ð -ð	/[ð
 ð/[ð 
ó/[ðbàðð ðð
 
óð(-àð-ð �E˜8 E™?Ð*Ñ+ð-ð �5˜( 5™/Ð)Ñ*ð	-ð 
ó-ñ. �rÔð (,Ø:>Ø9=Ø%)Ø*.Ø+/ñ1à˜t‘nð1ð ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ð1ð ˜E %¨¨e©Ð"4Ñ5Ñ6ð	1ð
 ˜T‘Nð1ð ! ™ð1ð ˜Ñ(ð1ð 
ò1ó ð1ð àðð ðð ð	ð
 ðð ˜%  e¡Ð,Ñ-ðð ˜  U¡Ð+Ñ,ðð 
óð8EàðEð �3˜�8‰nðEð
 
óEð.%àð%ð 
ó%ð ¨tó ð0àð0ð 
ó0ð& *.ØDHØ+/ñ àð ð ! ™ð ð $ E¨#Ð/?Ð*?Ñ$@ÑAð	 ð
 ˜Ñ(ð ð 
ó ðJ *.ØDHØ+/ñ àð ð ! ™ð ð $ E¨#Ð/?Ð*?Ñ$@ÑAð	 ð
 ˜Ñ(ð ð 
ˆnÑ	ó ð4 $(Ø(,Ø,0Ø:>Ø9=Ø26ñ"à�xÑ ð"ð ˜HÑ%ð"ð $ D™>ð	"ð
 ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ð"ð ˜E %¨¨e©Ð"4Ñ5Ñ6ð"ð Ð.Ñ/ð"ð 
ó"ðL &*Ø*.Ø'+Ø;?Ø:>Ø$(Ø#'Ø)-Ø(,ØQUØ;?Ø26ñ 
à˜T‘Nð 
ð ! ™ð 
ð ˜t‘nð	 
ð
 ˜U 5¨%°©,Ð#6Ñ7Ñ8ð 
ð ˜E %¨¨u©Ð"5Ñ6Ñ7ð 
ð ˜D‘>ð 
ð �xÑ ð 
ð ! ™ð 
ð ˜HÑ%ð 
ð ˜5Ð!LÑMÑNð 
ð !  s¨J Ñ!7Ñ8ð 
ð Ð.Ñ/ó 
ñD ÐHÓIð 9 ð  9°vÐ>]Ñ7^ð  9Ðcoò  9ó Jð 9ðD)aà�^Ñ$ð)að ð)að ð	)að
  Ð 5Ñ6ð)að ð)að ð)að ð)að ð)að ð)að ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ð)að ˜E %¨¨e©Ð"4Ñ5Ñ6ð)að !  s¨J Ñ!7Ñ8ð)að 
ó)a÷Vð r@   ry   c                   ó    — e Zd Zddee   fd„Zy)ÚSemanticSegmentationMixinNÚtarget_sizesc                 óð  — |j                   }|�¨t        |«      t        |«      k7  rt        d«      ‚g }t        t        |«      «      D ]k  }t        j
                  j                  j                  ||   j                  d¬«      ||   dd¬«      }|d   j                  d¬«      }|j                  |«       Œm |S |j                  d¬«      }t        |j                  d   «      D �cg c]  }||   ‘Œ	 }}|S c c}w )aD  
        Converts the output of [`MobileNetV2ForSemanticSegmentation`] into semantic segmentation maps. Only supports PyTorch.

        Args:
            outputs ([`MobileNetV2ForSemanticSegmentation`]):
                Raw outputs of the model.
            target_sizes (`List[Tuple]` of length `batch_size`, *optional*):
                List of tuples corresponding to the requested final size (height, width) of each prediction. If unset,
                predictions will not be resized.

        Returns:
            semantic_segmentation: `List[torch.Tensor]` of length `batch_size`, where each item is a semantic
            segmentation map of shape (height, width) corresponding to the target_sizes entry (if `target_sizes` is
            specified). Each entry of each `torch.Tensor` correspond to a semantic class id.
        zTMake sure that you pass in as many target sizes as the batch dimension of the logitsr   rÎ   ÚbilinearF)r6   ÚmodeÚalign_cornersr
   )ÚlogitsÚlenr<   rZ   r    Únnr(   ÚinterpolateÚ	unsqueezeÚargmaxr[   rP   )	rˆ   Úoutputsrã   rè   Úsemantic_segmentationÚidxÚresized_logitsÚsemantic_mapr_   s	            r>   Ú"post_process_semantic_segmentationz<SemanticSegmentationMixin.post_process_semantic_segmentationð  s  € ð  —‘ˆð Ð#Ü�6‹{œc ,Ó/Ò/Ü Øjóð ð %'Ð!äœS ›[Ó)ò ;�Ü!&§¡×!4Ñ!4×!@Ñ!@Ø˜3‘K×)Ñ)¨aÐ)Ó0°|ÀCÑ7HÈzÐinð "Aó "�ð  .¨aÑ0×7Ñ7¸AÐ7Ó>�Ø%×,Ñ,¨\Õ:ð;ð %Ð$ð %+§M¡M°a MÓ$8Ð!ÜGLÐMb×MhÑMhÐijÑMkÓGlÖ$mÀ!Ð%:¸1Ó%=Ð$mÐ!Ð$mà$Ð$ùò %ns   Ã#C3©N)rl   rm   rn   ru   rÃ   ró   rv   r@   r>   râ   râ   ï  s   „ ñ(%ÈÈUÉô (%r@   râ   rô   )HÚcollections.abcr   Ú	functoolsr   r   Útypingr   r   r   r	   ÚnumpyÚnpÚimage_processing_utilsr   r   r   Úimage_transformsr   r   r   r   r   Úimage_utilsr   r   r   r   r   r   r   r   r   r   r   Úprocessing_utilsr   Úutilsr   r    r!   r"   r#   r$   r%   r&   r    r'   Útorchvision.transforms.v2r(   r‘   Útorchvision.transformsÚ
get_loggerrl   r¬   r=   ro   rt   ru   rs   rr   r?   rG   rM   rÃ   rU   Úarrayrb   rd   Ú#BASE_IMAGE_PROCESSOR_FAST_DOCSTRINGrß   ry   râ   rv   r@   r>   ú<module>r     s¿  ðõ %ß (ß 2Ó 2ã ÷ñ ÷
õ ÷÷ ÷ ñ õ %÷÷ ñ ñ ÔÝ/áÔÛáÔÝ<á"Ô$Þ=å:à	ˆ×	Ñ	˜HÓ	%€ñ �2Ôà!%Ø&*Ø#'Ø6:Ø59Ø!Ø'+Ø%)Ø$(Ø $Ø#Ø/3Ø7;Ø.>×.DÑ.Dñ'SØ˜‘ð'Sà˜U‘Oð'Sð ˜4‘.ð'Sð ˜˜u d¨5¡kÐ1Ñ2Ñ3ð	'Sð
 ˜˜e T¨%¡[Ð0Ñ1Ñ2ð'Sð �T‰Nð'Sð   ‘}ð'Sð ˜T‘Nð'Sð ˜Ñ!ð'Sð ˜‰~ð'Sð �8Ñ
ð'Sð Ð+Ñ,ð'Sð ˜U 3¨
 ?Ñ3Ñ4ð'Sð Ð*Ñ+ò'Só ð'SñT
˜ð 
¨x¸©}ð 
Èó 
ð8˜x¨™}ð 8°°c±ó 8ð#  nÑ!5ð #¸%À¹*ó #ðØ�—‘˜>Ð)Ñ*ðØ8;ðà	ˆ%�—‘˜.Ð(Ñ
)Ñ*óô0% i°uõ %ð&2'lÐ #ðh*2lÐ .ñZ Ø-Ø'óôHÐ/ó Hó	ðH÷V)%ò )%r@   