Ë
    T^(hÚ@  ã                   óØ   — d 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 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mZmZ  ej@                  e!«      Z" G d	„ d
e	«      Z#d
gZ$y)z Image processor class for LeViT.é    )ÚDictÚIterableÚOptionalÚUnionNé   )ÚBaseImageProcessorÚBatchFeatureÚget_size_dict)Úget_resize_output_image_sizeÚresizeÚto_channel_dimension_format)ÚIMAGENET_DEFAULT_MEANÚIMAGENET_DEFAULT_STDÚChannelDimensionÚ
ImageInputÚPILImageResamplingÚinfer_channel_dimension_formatÚis_scaled_imageÚmake_list_of_imagesÚto_numpy_arrayÚvalid_imagesÚvalidate_preprocess_arguments)Ú
TensorTypeÚfilter_out_non_signature_kwargsÚloggingc            !       ó`  ‡ — e Zd ZdZdgZddej                  dddddeef
de	de
eef   ded	e	d
e
eef   de	deeef   de	deeeee   f      deeeee   f      ddfˆ fd„Zej                  ddfdej&                  de
eef   dedeeeef      deeeef      dej&                  fd„Z e«       dddddddddddej.                  dfdedee	   dee
eef      ded	ee	   d
ee
eef      d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deeeef      defd„«       Zˆ xZS )ÚLevitImageProcessora�  
    Constructs a LeViT image processor.

    Args:
        do_resize (`bool`, *optional*, defaults to `True`):
            Wwhether to resize the shortest edge of the input to int(256/224 *`size`). Can be overridden by the
            `do_resize` parameter in the `preprocess` method.
        size (`Dict[str, int]`, *optional*, defaults to `{"shortest_edge": 224}`):
            Size of the output image after resizing. If size is a dict with keys "width" and "height", the image will
            be resized to `(size["height"], size["width"])`. If size is a dict with key "shortest_edge", the shortest
            edge value `c` is rescaled to `int(c * (256/224))`. The smaller edge of the image will be matched to this
            value i.e, if height > width, then image will be rescaled to `(size["shortest_egde"] * height / width,
            size["shortest_egde"])`. Can be overridden by the `size` parameter in the `preprocess` method.
        resample (`PILImageResampling`, *optional*, defaults to `Resampling.BICUBIC`):
            Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in the
            `preprocess` method.
        do_center_crop (`bool`, *optional*, defaults to `True`):
            Whether or not to center crop the input to `(crop_size["height"], crop_size["width"])`. Can be overridden
            by the `do_center_crop` parameter in the `preprocess` method.
        crop_size (`Dict`, *optional*, defaults to `{"height": 224, "width": 224}`):
            Desired image size after `center_crop`. Can be overridden by the `crop_size` parameter in the `preprocess`
            method.
        do_rescale (`bool`, *optional*, defaults to `True`):
            Controls 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 `1/255`):
            Scale factor to use if rescaling the image. Can be overridden by the `rescale_factor` parameter in the
            `preprocess` method.
        do_normalize (`bool`, *optional*, defaults to `True`):
            Controls whether to normalize the image. Can be overridden by the `do_normalize` parameter in the
            `preprocess` method.
        image_mean (`List[int]`, *optional*, defaults to `[0.485, 0.456, 0.406]`):
            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.
        image_std (`List[int]`, *optional*, defaults to `[0.229, 0.224, 0.225]`):
            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.
    Úpixel_valuesTNgp?Ú	do_resizeÚsizeÚresampleÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚreturnc                 ó2  •— t        ‰| �  di |¤Ž |�|nddi}t        |d¬«      }|�|ndddœ}t        |d¬«      }|| _        || _        || _        || _        || _        || _        || _	        || _
        |	�|	nt        | _        |
�|
| _        y t        | _        y )	NÚshortest_edgeéà   F©Údefault_to_square©ÚheightÚwidthr#   ©Ú
param_name© )ÚsuperÚ__init__r
   r   r    r!   r"   r#   r$   r%   r&   r   r'   r   r(   )Úselfr   r    r!   r"   r#   r$   r%   r&   r'   r(   ÚkwargsÚ	__class__s               €ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/levit/image_processing_levit.pyr6   zLevitImageProcessor.__init__X   s­   ø€ ô 	‰ÑÑ"˜6Ò"ØÐ'‰t¨o¸sÐ-CˆÜ˜T°UÔ;ˆØ!*Ð!6‘IÀsÐUXÑ<Yˆ	Ü! )¸ÔDˆ	à"ˆŒØˆŒ	Ø ˆŒØ,ˆÔØ"ˆŒØ$ˆŒØ,ˆÔØ(ˆÔØ(2Ð(>™*ÔDYˆŒØ&/Ð&;˜ˆ�ÔAUˆ�ó    ÚimageÚdata_formatÚinput_data_formatc                 óô   — t        |d¬«      }d|v r+t        d|d   z  «      }t        ||d|¬«      }	|	d   |	d   dœ}d	|vsd
|vrt        d|j	                  «       › �«      ‚t        |f|d	   |d
   f|||dœ|¤ŽS )a-  
        Resize an image.

        If size is a dict with keys "width" and "height", the image will be resized to `(size["height"],
        size["width"])`.

        If size is a dict with key "shortest_edge", the shortest edge value `c` is rescaled to `int(c * (256/224))`.
        The smaller edge of the image will be matched to this value i.e, if height > width, then image will be rescaled
        to `(size["shortest_egde"] * height / width, size["shortest_egde"])`.

        Args:
            image (`np.ndarray`):
                Image to resize.
            size (`Dict[str, int]`):
                Size of the output image after resizing. If size is a dict with keys "width" and "height", the image
                will be resized to (height, width). If size is a dict with key "shortest_edge", the shortest edge value
                `c` is rescaled to int(`c` * (256/224)). The smaller edge of the image will be matched to this value
                i.e, if height > width, then image will be rescaled to (size * height / width, size).
            resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
                Resampling filter to use when resiizing the image.
            data_format (`str` or `ChannelDimension`, *optional*):
                The channel dimension format of the image. If not provided, it will be the same as the input image.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                The channel dimension format of the input image. If not provided, it will be inferred.
        Fr-   r+   g’$I’$Iò?)r    r.   r>   r   é   r/   r0   r1   zFSize dict must have keys 'height' and 'width' or 'shortest_edge'. Got )r    r!   r=   r>   )r
   Úintr   Ú
ValueErrorÚkeysr   )
r7   r<   r    r!   r=   r>   r8   Ú	size_dictr+   Úoutput_sizes
             r:   r   zLevitImageProcessor.resizew   sÂ   € ôD " $¸%Ô@ˆ	à˜dÑ"Ü ¨d°?Ñ.CÑ CÓDˆMÜ6Ø˜M¸UÐVgôˆKð $/¨q¡>¸KÈ¹NÑKˆIØ˜9Ñ$¨°yÑ(@ÜØXÐYb×YgÑYgÓYiÐXjÐkóð ô Øð
à˜HÑ% y°Ñ'9Ð:ØØ#Ø/ñ
ð ñ
ð 	
r;   ÚimagesÚreturn_tensorsc                 ó,  — |�|n| j                   }|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j                  }|	�|	n| j
                  }	|
�|
n| j                  }
|�|n| j                  }|�|n| j                  }t        |d¬«      }|�|n| j                  }t        |d¬«      }t        |«      }t        |«      st        d«      ‚t        |||	|
||||||¬«
       |D �cg c]  }t        |«      ‘Œ }}|r#t!        |d   «      rt"        j%                  d«       |€t'        |d   «      }|r"|D �cg c]  }| j)                  ||||¬	«      ‘Œ }}|r!|D �cg c]  }| j+                  |||¬	«      ‘Œ }}|r!|D �cg c]  }| j-                  |||¬	«      ‘Œ }}|	r"|D �cg c]  }| j/                  ||
||¬	«      ‘Œ }}|D �cg c]  }t1        |||¬
«      ‘Œ }}d|i}t3        ||¬«      S c c}w c c}w c c}w c c}w c c}w c c}w )a�  
        Preprocess an image or batch of images to be used as input to a LeViT model.

        Args:
            images (`ImageInput`):
                Image or batch of images 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`):
                Size of the output image after resizing. If size is a dict with keys "width" and "height", the image
                will be resized to (height, width). If size is a dict with key "shortest_edge", the shortest edge value
                `c` is rescaled to int(`c` * (256/224)). The smaller edge of the image will be matched to this value
                i.e, if height > width, then image will be rescaled to (size * height / width, size).
            resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
                Resampling filter to use when resiizing the image.
            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 center cropping. Crops images to (crop_size["height"],
                crop_size["width"]).
            do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
                Whether to rescale the image pixel values by `rescaling_factor` - typical to values between 0 and 1.
            rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
                Factor to rescale the image pixel values by.
            do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
                Whether to normalize the image pixel values by `image_mean` and `image_std`.
            image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
                Mean to normalize the image pixel values by.
            image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
                Standard deviation to normalize the image pixel values by.
            return_tensors (`str` or `TensorType`, *optional*):
                The type of tensors to return. Can be one of:
                    - Unset: Return a list of `np.ndarray`.
                    - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
                    - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
                    - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
                    - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
            data_format (`str` or `ChannelDimension`, *optional*, defaults to `ChannelDimension.FIRST`):
                The channel dimension format for the output image. If unset, the channel dimension format of the input
                image is used. 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.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                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.
        Fr-   r#   r2   zkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.)
r$   r%   r&   r'   r(   r"   r#   r   r    r!   r   z­It looks like you are trying to rescale already rescaled images. If the input images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again.)r>   )Úinput_channel_dimr   )ÚdataÚtensor_type)r   r!   r"   r$   r%   r&   r'   r(   r    r
   r#   r   r   rB   r   r   r   ÚloggerÚwarning_oncer   r   Úcenter_cropÚrescaleÚ	normalizer   r	   )r7   rF   r   r    r!   r"   r#   r$   r%   r&   r'   r(   rG   r=   r>   r<   rJ   s                    r:   Ú
preprocesszLevitImageProcessor.preprocess®   sn  € ðH "+Ð!6‘I¸D¿N¹Nˆ	Ø'Ð3‘8¸¿¹ˆØ+9Ð+E™È4×K^ÑK^ˆØ#-Ð#9‘Z¸t¿¹ˆ
Ø+9Ð+E™È4×K^ÑK^ˆØ'3Ð'?‘|ÀT×EVÑEVˆØ#-Ð#9‘Z¸t¿¹ˆ
Ø!*Ð!6‘I¸D¿N¹Nˆ	àÐ'‰t¨T¯Y©YˆÜ˜T°UÔ;ˆØ!*Ð!6‘I¸D¿N¹Nˆ	Ü! )¸ÔDˆ	Ü$ VÓ,ˆä˜FÔ#Üð:óð ô 	&Ø!Ø)Ø%Ø!ØØ)ØØØØõ	
ð 6<Ö<¨E”. Õ'Ð<ˆÐ<áœ/¨&°©)Ô4Ü×Ñðsôð
 Ð$ä >¸vÀa¹yÓ IÐáØkqÖrÐbg�d—k‘k %¨¨xÐK\�kÕ]ÐrˆFÐráØkqÖrÐbg�d×&Ñ& u¨iÐK\Ð&Õ]ÐrˆFÐráØlrÖsÐch�d—l‘l 5¨.ÐL]�lÕ^ÐsˆFÐsáàouöØfk�—‘˜u j°)ÐO`�ÕaðˆFð ð
 ouö
ØejÔ'¨¨{ÐN_Ö`ð
ˆð 
ð  Ð'ˆÜ °>ÔBÐBùò? =ùò sùò sùò tùòùò
s$   Ã5G8ÅG=Å(HÆHÆ.HÇH)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr   ÚBICUBICr   r   Úboolr   ÚstrrA   r   Úfloatr   r   r6   ÚnpÚndarrayr   r   r   ÚFIRSTr   r   r	   rQ   Ú__classcell__)r9   s   @r:   r   r   .   sÝ  ø„ ñ%ðN (Ð(Ðð Ø#Ø'9×'AÑ'AØ#Ø$(ØØ,3Ø!Ø>SØ=QñVàðVð �3˜�8‰nðVð %ð	Vð
 ðVð ˜˜S˜‘>ðVð ðVð ˜c 5˜jÑ)ðVð ðVð ˜U 5¨(°5©/Ð#9Ñ:Ñ;ðVð ˜E %¨°%©Ð"8Ñ9Ñ:ðVð 
õVðF (:×'AÑ'AØ>BØDHñ5
à�z‰zð5
ð �3˜�8‰nð5
ð %ð	5
ð
 ˜e CÐ)9Ð$9Ñ:Ñ;ð5
ð $ E¨#Ð/?Ð*?Ñ$@ÑAð5
ð 
�‰ó5
ñn %Ó&ð %)Ø)-Ø'+Ø)-Ø.2Ø%)Ø*.Ø'+Ø>BØ=AØ/3Ø(8×(>Ñ(>ØDHñCCàðCCð ˜D‘>ðCCð �t˜C ˜H‘~Ñ&ð	CCð
 %ðCCð ! ™ðCCð ˜D  c ™NÑ+ðCCð ˜T‘NðCCð ! ™ðCCð ˜t‘nðCCð ˜U 5¨(°5©/Ð#9Ñ:Ñ;ðCCð ˜E %¨°%©Ð"8Ñ9Ñ:ðCCð ! Ñ,ðCCð &ðCCð $ E¨#Ð/?Ð*?Ñ$@ÑAðCCð  
ò!CCó 'ôCCr;   r   )%rU   Útypingr   r   r   r   Únumpyr[   Úimage_processing_utilsr   r	   r
   Úimage_transformsr   r   r   Úimage_utilsr   r   r   r   r   r   r   r   r   r   r   Úutilsr   r   r   Ú
get_loggerrR   rL   r   Ú__all__r4   r;   r:   ú<module>rg      sp   ðñ 'ç 2Ó 2ã ç UÑ U÷ñ ÷
÷ ÷ ñ ÷ JÑ Ið 
ˆ×	Ñ	˜HÓ	%€ôDCÐ,ô DCðN !Ð
!�r;   