Ë
    S^(h—’  ã                   óR  — U d Z ddlZddlZddlmZ ddlmZmZmZ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 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%m&Z&  e%«       rddl'Z' e&jP                  e)«      Z*eZ+eZ,g d
¢Z-g d¢Z.dZ/e0e1d<    G d„ d«      Z2 G d„ de«      Z3dgZ4y)z Image processor class for Flava.é    N)Ú	lru_cache)ÚAnyÚDictÚIterableÚListÚOptionalÚTupleÚUnioné   )ÚBaseImageProcessorÚBatchFeatureÚget_size_dict)ÚresizeÚto_channel_dimension_format)ÚOPENAI_CLIP_MEANÚOPENAI_CLIP_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Úis_vision_availableÚlogging)ç        r    r    )ç      ð?r!   r!   gš™™™™™¹?ÚLOGIT_LAPLACE_EPSc                   óx   — e Zd Z	 	 	 	 	 	 ddeeeeef   f   dedee   dedee   dee   fd„Zd	„ Z	d
„ Z
d„ Zd„ Zy)ÚFlavaMaskingGeneratorNÚ
input_sizeÚtotal_mask_patchesÚmask_group_max_patchesÚmask_group_min_patchesÚmask_group_min_aspect_ratioÚmask_group_max_aspect_ratioc                 ó,  — t        |t        «      s|fdz  }|\  | _        | _        | j                  | j                  z  | _        || _        || _        |€|n|| _        |xs d|z  }t        j                  |«      t        j                  |«      f| _
        y )Né   é   )Ú
isinstanceÚtupleÚheightÚwidthÚnum_patchesr&   r(   r'   ÚmathÚlogÚlog_aspect_ratio)Úselfr%   r&   r'   r(   r)   r*   s          ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/flava/image_processing_flava.pyÚ__init__zFlavaMaskingGenerator.__init__;   s�   € ô ˜*¤eÔ,Ø$˜¨Ñ*ˆJØ",ÑˆŒ�T”ZàŸ;™;¨¯©Ñ3ˆÔØ"4ˆÔà&<ˆÔ#Ø<RÐ<ZÑ&8Ð`vˆÔ#à&AÒ&dÀQÐIdÑEdÐ#Ü!%§¡Ð*EÓ!FÌÏÉÐQlÓHmÐ nˆÕó    c           	      ó¶   — d| j                   | j                  | j                  | j                  | j                  | j
                  d   | j
                  d   fz  }|S )Nz<MaskingGenerator(%d, %d -> [%d ~ %d], max = %d, %.3f ~ %.3f)r   r-   )r0   r1   r(   r'   r&   r5   )r6   Úrepr_strs     r7   Ú__repr__zFlavaMaskingGenerator.__repr__Q   s^   € ØQØ�K‰KØ�J‰JØ×'Ñ'Ø×'Ñ'Ø×#Ñ#Ø×!Ñ! !Ñ$Ø×!Ñ! !Ñ$ðU
ñ 
ˆð ˆr9   c                 ó2   — | j                   | j                  fS )N©r0   r1   )r6   s    r7   Ú	get_shapezFlavaMaskingGenerator.get_shape]   s   € Ø�{‰{˜DŸJ™JÐ&Ð&r9   c           	      ó4  — d}t        d«      D �]†  }t        j                  | j                  |«      }t	        j
                  t        j                  | j                  Ž «      }t        t        t	        j                  ||z  «      «      «      }t        t        t	        j                  ||z  «      «      «      }|| j                  k  sŒ·|| j                  k  sŒÇt        j                  d| j                  |z
  «      }	t        j                  d| j                  |z
  «      }
||	|	|z   …|
|
|z   …f   j                  «       }d||z  |z
  cxk  r|k  rBn n?t        |	|	|z   «      D ]-  }t        |
|
|z   «      D ]  }|||f   dk(  sŒd|||f<   |dz  }Œ Œ/ |dkD  s�Œ† |S  |S )Nr   é
   r-   )ÚrangeÚrandomÚuniformr(   r3   Úexpr5   ÚintÚroundÚsqrtr1   r0   ÚrandintÚsum)r6   ÚmaskÚmax_mask_patchesÚdeltaÚ_attemptÚtarget_areaÚaspect_ratior0   r1   ÚtopÚleftÚ
num_maskedÚiÚjs                 r7   Ú_maskzFlavaMaskingGenerator._mask`   sƒ  € ØˆÜ˜b›	ó 	ˆHÜ Ÿ.™.¨×)DÑ)DÐFVÓWˆKÜŸ8™8¤F§N¡N°D×4IÑ4IÐ$JÓKˆLÜœœtŸy™y¨°|Ñ)CÓDÓEÓFˆFÜœœdŸi™i¨°lÑ(BÓCÓDÓEˆEØ�t—z‘zÓ! f¨t¯{©{Ó&:Ü—n‘n Q¨¯©°fÑ(<Ó=�Ü—~‘~ a¨¯©°eÑ);Ó<�à! #¨¨f©Ð"4°d¸TÀE¹\Ð6IÐ"IÑJ×NÑNÓP�
à�v ‘~¨
Ñ2ÔFÐ6FÕFÜ" 3¨¨f©Ó5ò +˜Ü!& t¨T°E©\Ó!:ò +˜AØ# A q D™z¨Q›Ø-.  Q¨ T¡
Ø %¨¡
¡ñ+ð+ð ˜1”9ØØˆð)	ð( ˆr9   c                 ó"  — t        j                  | j                  «       t        ¬«      }d}|| j                  k  rT| j                  |z
  }t        || j                  «      }| j                  ||«      }|dk(  r	 |S ||z  }|| j                  k  rŒT|S )N)ÚshapeÚdtyper   )ÚnpÚzerosr?   rF   r&   Úminr'   rV   )r6   rK   Ú
mask_countrL   rM   s        r7   Ú__call__zFlavaMaskingGenerator.__call__x   s–   € Ü�x‰x˜dŸn™nÓ.´cÔ:ˆØˆ
Ø˜4×2Ñ2Ò2Ø#×6Ñ6¸ÑCÐÜ"Ð#3°T×5PÑ5PÓQÐà—J‘J˜tÐ%5Ó6ˆEØ˜ŠzØð ˆð ˜eÑ#�
ð ˜4×2Ñ2Ó2ð ˆr9   )é   éK   Né   ç333333Ó?N)Ú__name__Ú
__module__Ú__qualname__r
   rF   r	   r   Úfloatr8   r<   r?   rV   r^   © r9   r7   r$   r$   :   sŽ   „ ð 35Ø"$Ø04Ø&(Ø7:Ø7;ñoà˜#˜u S¨# X™Ð.Ñ/ðoð  ðoð !)¨¡ð	oð
 !$ðoð &.¨e¡_ðoð &.¨e¡_óoò,
ò'òó0r9   r$   c            G       óØ  ‡ — e Zd ZdZdgZddej                  ddddddddddd	dd
ddddej                  dddddddd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ededededee   dedee   dededee   ded ed!ee   d"ed#eeef   d$ed%ed&eeeee   f      d'eeeee   f      d(df<ˆ fd)„Zed*e	e
ef   fˆ fd+„«       Z e«       d(efd,„«       Zej                  ddfd-ej0                  de	e
ef   ded.eee
ef      d/eee
ef      d(ej0                  fd0„Zd-ej0                  d(ej0                  fd1„Zdddddddddddej8                  dfd-edee   de	e
ef   dedee   d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      d2ee   d.ee   d/ee   d(ej0                  fd3„Z e «       ddddddddddddddddddddddddddddddej8                  df d4edee   d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e   dee   dee   dee   dee   dee   dee   dee   dee	e
ef      dee   d ee   d!ee	e
ef      d"ee   d#ee   d$ee   d%ee   d&eee      d'eee      d5eee
e!f      d.ed/eee
ef      d(e"jF                  jF                  fDd6„«       Z$ˆ xZ%S )7ÚFlavaImageProcessora  
    Constructs a Flava image processor.

    Args:
        do_resize (`bool`, *optional*, defaults to `True`):
            Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by the
            `do_resize` parameter in `preprocess`.
        size (`Dict[str, int]` *optional*, defaults to `{"height": 224, "width": 224}`):
            Size of the image after resizing. Can be overridden by the `size` parameter in `preprocess`.
        resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
            Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in
            `preprocess`.
        do_center_crop (`bool`, *optional*, defaults to `True`):
            Whether to center crop the images. Can be overridden by the `do_center_crop` parameter in `preprocess`.
        crop_size (`Dict[str, int]` *optional*, defaults to `{"height": 224, "width": 224}`):
            Size of image after the center crop `(crop_size["height"], crop_size["width"])`. Can be overridden by the
            `crop_size` parameter in `preprocess`.
        do_rescale (`bool`, *optional*, defaults to `True`):
            Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the `do_rescale`
            parameter in `preprocess`.
        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
            `preprocess`.
        do_normalize (`bool`, *optional*, defaults to `True`):
            Whether to normalize the image. Can be overridden by the `do_normalize` parameter in `preprocess`.
        image_mean (`float` or `List[float]`, *optional*, defaults to `IMAGENET_STANDARD_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.
        image_std (`float` or `List[float]`, *optional*, defaults to `IMAGENET_STANDARD_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.
        return_image_mask (`bool`, *optional*, defaults to `False`):
            Whether to return the image mask. Can be overridden by the `return_image_mask` parameter in `preprocess`.
        input_size_patches (`int`, *optional*, defaults to 14):
            Number of patches in the image in height and width direction. 14x14 = 196 total patches. Can be overridden
            by the `input_size_patches` parameter in `preprocess`.
        total_mask_patches (`int`, *optional*, defaults to 75):
            Total number of patches that should be masked. Can be overridden by the `total_mask_patches` parameter in
            `preprocess`.
        mask_group_min_patches (`int`, *optional*, defaults to 16):
            Minimum number of patches that should be masked. Can be overridden by the `mask_group_min_patches`
            parameter in `preprocess`.
        mask_group_max_patches (`int`, *optional*):
            Maximum number of patches that should be masked. Can be overridden by the `mask_group_max_patches`
            parameter in `preprocess`.
        mask_group_min_aspect_ratio (`float`, *optional*, defaults to 0.3):
            Minimum aspect ratio of the mask window. Can be overridden by the `mask_group_min_aspect_ratio` parameter
            in `preprocess`.
        mask_group_max_aspect_ratio (`float`, *optional*):
            Maximum aspect ratio of the mask window. Can be overridden by the `mask_group_max_aspect_ratio` parameter
            in `preprocess`.
        codebook_do_resize (`bool`, *optional*, defaults to `True`):
            Whether to resize the input for codebook to a certain. Can be overridden by the `codebook_do_resize`
            parameter in `preprocess`. `codebook_size`.
        codebook_size (`Dict[str, int]`, *optional*, defaults to `{"height": 224, "width": 224}`):
            Resize the input for codebook to the given size. Can be overridden by the `codebook_size` parameter in
            `preprocess`.
        codebook_resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.LANCZOS`):
            Resampling filter to use if resizing the codebook image. Can be overridden by the `codebook_resample`
            parameter in `preprocess`.
        codebook_do_center_crop (`bool`, *optional*, defaults to `True`):
            Whether to crop the input for codebook at the center. If the input size is smaller than
            `codebook_crop_size` along any edge, the image is padded with 0's and then center cropped. Can be
            overridden by the `codebook_do_center_crop` parameter in `preprocess`.
        codebook_crop_size (`Dict[str, int]`, *optional*, defaults to `{"height": 224, "width": 224}`):
            Desired output size for codebook input when applying center-cropping. Can be overridden by the
            `codebook_crop_size` parameter in `preprocess`.
        codebook_do_rescale (`bool`, *optional*, defaults to `True`):
            Whether to rescale the input for codebook by the specified scale `codebook_rescale_factor`. Can be
            overridden by the `codebook_do_rescale` parameter in `preprocess`.
        codebook_rescale_factor (`int` or `float`, *optional*, defaults to `1/255`):
            Defines the scale factor to use if rescaling the codebook image. Can be overridden by the
            `codebook_rescale_factor` parameter in `preprocess`.
        codebook_do_map_pixels (`bool`, *optional*, defaults to `True`):
            Whether to map the pixel values of the codebook input to (1 - 2e)x + e. Can be overridden by the
            `codebook_do_map_pixels` parameter in `preprocess`.
        codebook_do_normalize (`bool`, *optional*, defaults to `True`):
            Whether or not to normalize the input for codebook with `codebook_image_mean` and `codebook_image_std`. Can
            be overridden by the `codebook_do_normalize` parameter in `preprocess`.
        codebook_image_mean (`Optional[Union[float, Iterable[float]]]`, *optional*, defaults to `[0, 0, 0]`):
            The sequence of means for each channel, to be used when normalizing images for codebook. Can be overridden
            by the `codebook_image_mean` parameter in `preprocess`.
        codebook_image_std (`Optional[Union[float, Iterable[float]]]`, *optional*, defaults to `[0.5, 0.5, 0.5]`):
            The sequence of standard deviations for each channel, to be used when normalizing images for codebook. Can
            be overridden by the `codebook_image_std` parameter in `preprocess`.
    Úpixel_valuesTNgp?Fr_   r`   ra   rb   Ú	do_resizeÚsizeÚresampleÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚreturn_image_maskÚinput_size_patchesr&   r(   r'   r)   r*   Úreturn_codebook_pixelsÚcodebook_do_resizeÚcodebook_sizeÚcodebook_resampleÚcodebook_do_center_cropÚcodebook_crop_sizeÚcodebook_do_rescaleÚcodebook_rescale_factorÚcodebook_do_map_pixelsÚcodebook_do_normalizeÚcodebook_image_meanÚcodebook_image_stdÚreturnc                 óÀ  •— t        ‰| �  di |¤Ž |�|ndddœ}t        |«      }|�|ndddœ}t        |d¬«      }|�|ndddœ}t        |d¬«      }|�|ndddœ}t        |d¬«      }|| _        || _        || _        || _        || _        || _        || _	        || _
        |	�|	nt        | _        |
�|
nt        | _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _         |�|ntB        | _         |�|| _#        y tD        | _#        y )	Néà   r>   ro   ©Ú
param_nameép   ry   r|   rg   )$Úsuperr8   r   rk   rl   rm   rp   rq   rn   ro   rr   ÚFLAVA_IMAGE_MEANrs   ÚFLAVA_IMAGE_STDrt   ru   rv   r&   r(   r'   r)   r*   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   ÚFLAVA_CODEBOOK_MEANÚFLAVA_CODEBOOK_STDr‚   ) r6   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   r&   r(   r'   r)   r*   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   ÚkwargsÚ	__class__s                                   €r7   r8   zFlavaImageProcessor.__init__â   s¡  ø€ ôF 	‰ÑÑ"˜6Ò"ØÐ'‰t¸ÀcÑ-JˆÜ˜TÓ"ˆØ!*Ð!6‘IÀsÐUXÑ<Yˆ	Ü! )¸ÔDˆ	à)6Ð)B™ÐSVÐadÑHeˆÜ% mÀÔPˆØ3EÐ3QÑ/ÐbeÐpsÑWtÐÜ*Ð+=ÐJ^Ô_Ðà"ˆŒØˆŒ	Ø ˆŒØ$ˆŒØ,ˆÔØ,ˆÔØ"ˆŒØ(ˆÔØ(2Ð(>™*ÔDTˆŒØ&/Ð&;™ÄˆŒà!2ˆÔØ"4ˆÔØ"4ˆÔØ&<ˆÔ#Ø&<ˆÔ#Ø+FˆÔ(Ø+FˆÔ(à&<ˆÔ#Ø"4ˆÔØ*ˆÔØ!2ˆÔØ'>ˆÔ$Ø"4ˆÔØ#6ˆÔ Ø'>ˆÔ$Ø&<ˆÔ#Ø%:ˆÔ"Ø#6ˆÔ Ø:MÐ:YÑ#6Ô_rˆÔ Ø8JÐ8VÐ"4ˆÕÔ\nˆÕr9   Úimage_processor_dictc                 ó¤   •— |j                  «       }d|v r|j                  d«      |d<   d|v r|j                  d«      |d<   t        ‰| �  |fi |¤ŽS )zõ
        Overrides the `from_dict` method from the base class to make sure parameters are updated if image processor is
        created using from_dict and kwargs e.g. `FlavaImageProcessor.from_pretrained(checkpoint, codebook_size=600)`
        ry   r|   )ÚcopyÚpopr‰   Ú	from_dict)Úclsr�   rŽ   r�   s      €r7   r”   zFlavaImageProcessor.from_dict1  sd   ø€ ð  4×8Ñ8Ó:ÐØ˜fÑ$Ø4:·J±J¸Ó4OÐ  Ñ1Ø 6Ñ)Ø9?¿¹ÐDXÓ9YÐ Ð!5Ñ6Ü‰wÑ Ð!5Ñ@¸Ñ@Ð@r9   c                 ó$   — t        ||||||¬«      S )N)r%   r&   r(   r'   r)   r*   )r$   )r6   rv   r&   r(   r'   r)   r*   s          r7   Úmasking_generatorz%FlavaImageProcessor.masking_generator>  s#   € ô %Ø)Ø1Ø#9Ø#9Ø(CØ(Cô
ð 	
r9   ÚimageÚdata_formatÚinput_data_formatc                 ó–   — t        |«      }d|vsd|vrt        d|j                  «       › �«      ‚|d   |d   f}t        |f||||dœ|¤ŽS )a‹  
        Resize an image to `(size["height"], size["width"])`.

        Args:
            image (`np.ndarray`):
                Image to resize.
            size (`Dict[str, int]`):
                Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
            resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
                `PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.BICUBIC`.
            data_format (`ChannelDimension` or `str`, *optional*):
                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.
                - `"none"` or `ChannelDimension.NONE`: image in (height, width) 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.

        Returns:
            `np.ndarray`: The resized image.
        r0   r1   zFThe `size` dictionary must contain the keys `height` and `width`. Got )rl   rm   r™   rš   )r   Ú
ValueErrorÚkeysr   )r6   r˜   rl   rm   r™   rš   rŽ   Úoutput_sizes           r7   r   zFlavaImageProcessor.resizeR  sy   € ôF ˜TÓ"ˆØ˜4Ñ 7°$Ñ#6ÜÐeÐfj×foÑfoÓfqÐerÐsÓtÐtØ˜H‘~ t¨G¡}Ð5ˆÜØð
àØØ#Ø/ñ
ð ñ
ð 	
r9   c                 ó.   — ddt         z  z
  |z  t         z   S )Nr-   r,   )r"   )r6   r˜   s     r7   Ú
map_pixelszFlavaImageProcessor.map_pixels‚  s   € Ø�AÔ)Ñ)Ñ)¨UÑ2Ô5FÑFÐFr9   Údo_map_pixelsc                 óž  — t        |||	|
||||||¬«
       t        |«      }|r t        |«      rt        j	                  d«       |€t        |«      }|r| j                  ||||¬«      }|r| j                  |||¬«      }|r| j                  |||¬«      }|	r| j                  ||
||¬«      }|r| j                  |«      }|�t        |||¬«      }|S )zPreprocesses a single image.)
rp   rq   rr   rs   rt   rn   ro   rk   rl   rm   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˜   rl   rm   rš   )r˜   rl   rš   )r˜   Úscalerš   )r˜   ÚmeanÚstdrš   )Úinput_channel_dim)r   r   r   ÚloggerÚwarning_oncer   r   Úcenter_cropÚrescaleÚ	normalizer    r   )r6   r˜   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   r¡   r™   rš   s                  r7   Ú_preprocess_imagez%FlavaImageProcessor._preprocess_image…  sù   € ô& 	&Ø!Ø)Ø%Ø!ØØ)ØØØØõ	
ô ˜uÓ%ˆáœ/¨%Ô0Ü×Ñðsôð
 Ð$ä >¸uÓ EÐáØ—K‘K e°$ÀÐ]n�KÓoˆEáØ×$Ñ$¨5°yÐTeÐ$ÓfˆEáØ—L‘L u°NÐVg�LÓhˆEáØ—N‘N¨°ZÀYÐbs�NÓtˆEáØ—O‘O EÓ*ˆEàÐ"Ü/°°{ÐVgÔhˆEØˆr9   ÚimagesÚreturn_tensorsc"                 óª  — |�|n| j                   }|�|n| j                  }t        |«      }|�|n| j                  }|�|n| j                  }|�|n| j
                  }t        |d¬«      }|�|n| j                  }|�|n| j                  }|	�|	n| j                  }	|
�|
n| j                  }
|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j                  }|�|n| j                   }|�|n| j"                  }|�|n| j$                  }|�|n| j&                  }|�|n| j(                  }t        |d¬«      }|�|n| j*                  }|�|n| j,                  }|�|n| j.                  }|�|n| j0                  }|�|n| j2                  }t        |d¬«      }|�|n| j4                  }|�|n| j6                  }|�|n| j8                  }|�|n| j:                  }t=        |«      }t?        |«      stA        d«      ‚|D �"cg c]!  }"| jC                  |"||||||||	|
|d| |!¬«      ‘Œ# }#}"d|#i}$|r1|D �"cg c]!  }"| jC                  |"|||||||||||| |!¬«      ‘Œ# }%}"|%|$d	<   |r0| jE                  ||||||¬
«      }&|D �'cg c]	  }' |&«       ‘Œ }(}'|(|$d<   tG        |$|¬«      S c c}"w c c}"w c c}'w )aŽ  
        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`):
                Size of the image.
            resample (`int`, *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 center crop. Only has an effect if `do_center_crop` is set to `True`.
            do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
                Whether to rescale the image values between [0 - 1].
            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.
            image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
                Image standard deviation.
            return_image_mask (`bool`, *optional*, defaults to `self.return_image_mask`):
                Whether to return the image mask.
            input_size_patches (`int`, *optional*, defaults to `self.input_size_patches`):
                Size of the patches to extract from the image.
            total_mask_patches (`int`, *optional*, defaults to `self.total_mask_patches`):
                Total number of patches to extract from the image.
            mask_group_min_patches (`int`, *optional*, defaults to `self.mask_group_min_patches`):
                Minimum number of patches to extract from the image.
            mask_group_max_patches (`int`, *optional*, defaults to `self.mask_group_max_patches`):
                Maximum number of patches to extract from the image.
            mask_group_min_aspect_ratio (`float`, *optional*, defaults to `self.mask_group_min_aspect_ratio`):
                Minimum aspect ratio of the patches to extract from the image.
            mask_group_max_aspect_ratio (`float`, *optional*, defaults to `self.mask_group_max_aspect_ratio`):
                Maximum aspect ratio of the patches to extract from the image.
            return_codebook_pixels (`bool`, *optional*, defaults to `self.return_codebook_pixels`):
                Whether to return the codebook pixels.
            codebook_do_resize (`bool`, *optional*, defaults to `self.codebook_do_resize`):
                Whether to resize the codebook pixels.
            codebook_size (`Dict[str, int]`, *optional*, defaults to `self.codebook_size`):
                Size of the codebook pixels.
            codebook_resample (`int`, *optional*, defaults to `self.codebook_resample`):
                Resampling filter to use if resizing the codebook pixels. This can be one of the enum
                `PILImageResampling`, Only has an effect if `codebook_do_resize` is set to `True`.
            codebook_do_center_crop (`bool`, *optional*, defaults to `self.codebook_do_center_crop`):
                Whether to center crop the codebook pixels.
            codebook_crop_size (`Dict[str, int]`, *optional*, defaults to `self.codebook_crop_size`):
                Size of the center crop of the codebook pixels. Only has an effect if `codebook_do_center_crop` is set
                to `True`.
            codebook_do_rescale (`bool`, *optional*, defaults to `self.codebook_do_rescale`):
                Whether to rescale the codebook pixels values between [0 - 1].
            codebook_rescale_factor (`float`, *optional*, defaults to `self.codebook_rescale_factor`):
                Rescale factor to rescale the codebook pixels by if `codebook_do_rescale` is set to `True`.
            codebook_do_map_pixels (`bool`, *optional*, defaults to `self.codebook_do_map_pixels`):
                Whether to map the codebook pixels values.
            codebook_do_normalize (`bool`, *optional*, defaults to `self.codebook_do_normalize`):
                Whether to normalize the codebook pixels.
            codebook_image_mean (`float` or `List[float]`, *optional*, defaults to `self.codebook_image_mean`):
                Codebook pixels mean to normalize the codebook pixels by if `codebook_do_normalize` is set to `True`.
            codebook_image_std (`float` or `List[float]`, *optional*, defaults to `self.codebook_image_std`):
                Codebook pixels standard deviation to normalize the codebook pixels by if `codebook_do_normalize` is
                set to `True`.
            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 (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
                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.
            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.
        ro   r†   ry   r|   zkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.F)r˜   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   r¡   r™   rš   rj   Úcodebook_pixel_values)rv   r&   r(   r'   r)   r*   Úbool_masked_pos)ÚdataÚtensor_type)$rk   rl   r   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   r&   r(   r'   r)   r*   rw   rx   ry   rz   r}   r~   r{   r|   r   r€   r�   r‚   r   r   rœ   r¬   r—   r   ))r6   r­   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   r&   r(   r'   r)   r*   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   r®   r™   rš   ÚimgÚprocessed_imagesr²   Úcodebook_imagesÚmask_generatorÚ_Úmaskss)                                            r7   Ú
preprocesszFlavaImageProcessor.preprocessÅ  sð  € ð| "+Ð!6‘I¸D¿N¹Nˆ	ØÐ'‰t¨T¯Y©YˆÜ˜TÓ"ˆØ'Ð3‘8¸¿¹ˆØ+9Ð+E™È4×K^ÑK^ˆØ!*Ð!6‘I¸D¿N¹Nˆ	Ü! )¸ÔDˆ	Ø#-Ð#9‘Z¸t¿¹ˆ
Ø+9Ð+E™È4×K^ÑK^ˆØ'3Ð'?‘|ÀT×EVÑEVˆØ#-Ð#9‘Z¸t¿¹ˆ
Ø!*Ð!6‘I¸D¿N¹Nˆ	à1BÐ1NÑ-ÐTX×TjÑTjÐØ3EÐ3QÑ/ÐW[×WnÑWnÐØ3EÐ3QÑ/ÐW[×WnÑWnÐà&<Ð&HÑ"Èd×NiÑNið 	ð '=Ð&HÑ"Èd×NiÑNið 	ð
 +Ð6ñ (à×1Ñ1ð 	$ð +Ð6ñ (à×1Ñ1ð 	$ð '=Ð&HÑ"Èd×NiÑNið 	ð 4FÐ3QÑ/ÐW[×WnÑWnÐØ)6Ð)B™È×HZÑHZˆÜ% mÀÔPˆØ1BÐ1NÑ-ÐTX×TjÑTjÐØ5HÐ5TÑ1ÐZ^×ZrÑZrÐà'>Ð'JÑ#ÐPT×PlÑPlð 	 ð (?Ð'JÑ#ÐPT×PlÑPlð 	 ð 4FÐ3QÑ/ÐW[×WnÑWnÐÜ*Ð+=ÐJ^Ô_Ðà&<Ð&HÑ"Èd×NiÑNið 	ð &;Ð%FÑ!ÈD×LfÑLfð 	ð 6IÐ5TÑ1ÐZ^×ZrÑZrÐØ3EÐ3QÑ/ÐW[×WnÑWnÐä$ VÓ,ˆä˜FÔ#Üð:óð ð, ö#
ð" ð! ×"Ñ"ØØ#ØØ!Ø-Ø#Ø%Ø-Ø)Ø%Ø#Ø#Ø'Ø"3ð #õ ð
Ðð 
ð& Ð 0Ð1ˆá!ð$ "ö#ð" ð! ×&Ñ&ØØ0Ø&Ø.Ø#:Ø0Ø2Ø#:Ø!6Ø2Ø0Ø"8Ø +Ø&7ð 'õ ðˆOð ð& -<ˆDÐ(Ñ)áØ!×3Ñ3Ø#5Ø#5Ø'=Ø'=Ø,GØ,Gð 4ó ˆNð 06Ö6¨!‘^Õ%Ð6ˆEÐ6Ø&+ˆDÐ"Ñ#ä °>ÔBÐBùòo
ùò,ùò< 7s   È(&KÉ&KÊ$K)&rc   rd   re   Ú__doc__Úmodel_input_namesr   ÚBICUBICÚLANCZOSÚboolr   ÚstrrF   r
   rf   r   r   r8   Úclassmethodr   r”   r   r$   r—   rZ   Úndarrayr   r   r    ÚFIRSTr   r   r¬   r   r   ÚPILÚImagerº   Ú__classcell__)r�   s   @r7   ri   ri   ˆ   sz  ø„ ñUðn (Ð(Ðð Ø#Ø'9×'AÑ'AØ#Ø$(ØØ,3Ø!Ø>BØ=Aà"'Ø"$Ø"$Ø&(Ø04Ø-0Ø7;à',Ø#'Ø(,Ø!3×!;Ñ!;Ø(,Ø,0Ø$(Ø5<Ø'+Ø&*ØGKØFJñAMoàðMoð �3˜�8‰nðMoð %ð	Moð
 ðMoð ˜˜S˜‘>ðMoð ðMoð ˜c 5˜jÑ)ðMoð ðMoð ˜U 5¨(°5©/Ð#9Ñ:Ñ;ðMoð ˜E %¨°%©Ð"8Ñ9Ñ:ðMoð  ðMoð  ðMoð  ðMoð  !$ð!Moð" !)¨¡ð#Moð$ &+ð%Moð& &.¨e¡_ð'Moð* !%ð+Moð, !ð-Moð.   ‘~ð/Moð0 ð1Moð2 "&ð3Moð4 % S™Mð5Moð6 "ð7Moð8 "' s¨E zÑ!2ð9Moð: !%ð;Moð<  $ð=Moð> & e¨E°8¸E±?Ð,BÑ&CÑDð?Moð@ % U¨5°(¸5±/Ð+AÑ%BÑCðAMoðD 
õEMoð^ ð
A¨T°#°s°(©^ô 
Aó ð
Añ ƒ[ð
ð 
ò
ó ð
ð. (:×'AÑ'AØ>BØDHñ.
à�z‰zð.
ð �3˜�8‰nð.
ð %ð	.
ð
 ˜e CÐ)9Ð$9Ñ:Ñ;ð.
ð $ E¨#Ð/?Ð*?Ñ$@ÑAð.
ð 
�‰ó.
ð`G §
¡
ð G¨r¯z©zó Gð %)Ø#Ø'+Ø)-Ø$(Ø%)Ø*.Ø'+Ø:>Ø9=Ø(,Ø2B×2HÑ2HØ8<ñ>àð>ð ˜D‘>ð>ð �3˜�8‰nð	>ð
 %ð>ð ! ™ð>ð ˜˜S˜‘>ð>ð ˜T‘Nð>ð ! ™ð>ð ˜t‘nð>ð ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ð>ð ˜E %¨¨e©Ð"4Ñ5Ñ6ð>ð   ‘~ð>ð Ð.Ñ/ð>ð $Ð$4Ñ5ð>ð  
�‰ó!>ñ@ %Ó&ð %)Ø#Ø'+Ø)-Ø.2Ø%)Ø*.Ø'+Ø:>Ø9=à,0Ø,0Ø,0Ø04Ø04Ø7;Ø7;à15Ø-1Ø26Ø+/Ø26Ø7;Ø.2Ø37Ø15Ø04Ø9=Ø8<Ø;?Ø(8×(>Ñ(>ØDHñIvCàðvCð ˜D‘>ðvCð �3˜�8‰nð	vCð
 %ðvCð ! ™ðvCð ˜D  c ™NÑ+ðvCð ˜T‘NðvCð ! ™ðvCð ˜t‘nðvCð ˜U 5¨$¨u©+Ð#5Ñ6Ñ7ðvCð ˜E %¨¨e©Ð"4Ñ5Ñ6ðvCð $ D™>ðvCð % S™MðvCð  % S™Mð!vCð" !)¨¡ð#vCð$ !)¨¡ð%vCð& &.¨e¡_ð'vCð( &.¨e¡_ð)vCð, !)¨¡ð-vCð. % T™Nð/vCð0    S¨# X¡Ñ/ð1vCð2 $ C™=ð3vCð4 "*¨$¡ð5vCð6 % T¨#¨s¨(¡^Ñ4ð7vCð8 & d™^ð9vCð: "*¨%¡ð;vCð< !)¨¡ð=vCð>  (¨™~ð?vCð@ & h¨u¡oÑ6ðAvCðB % X¨e¡_Ñ5ðCvCðD !  s¨J Ñ!7Ñ8ðEvCðF &ðGvCðH $ E¨#Ð/?Ð*?Ñ$@ÑAðIvCðJ 
�‰�‰òKvCó 'ôvCr9   ri   )5r»   r3   rC   Ú	functoolsr   Útypingr   r   r   r   r   r	   r
   ÚnumpyrZ   Úimage_processing_utilsr   r   r   Úimage_transformsr   r   Úimage_utilsr   r   r   r   r   r   r   r   r   r   r   Úutilsr   r   r   r   rÄ   Ú
get_loggerrc   r§   rŠ   r‹   rŒ   r�   r"   rf   Ú__annotations__r$   ri   Ú__all__rg   r9   r7   ú<module>rÑ      s±   ðò 'ã Û Ý ß D× DÑ Dã ç UÑ Uß C÷÷ ÷ ñ ÷ _Ó ^ñ ÔÛð 
ˆ×	Ñ	˜HÓ	%€ð $Ð Ø!€Ú%Ð Ú$Ð ØÐ �5Ó ÷Kñ Kô\tCÐ,ô tCðn !Ð
!�r9   