
    sg                     L   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      Z3y)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                   r    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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          c/var/www/html/venv/lib/python3.12/site-packages/transformers/models/flava/image_processing_flava.py__init__zFlavaMaskingGenerator.__init__;   s     *e,$*J",TZ;;3"4&<#<R<Z&8`v#&A&dQIdEd#!%*E!FQlHm 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KKJJ''''##!!!$!!!$U
 
 r9   c                 2    | j                   | j                  fS )Nr0   r1   )r6   s    r7   	get_shapezFlavaMaskingGenerator.get_shape]   s    {{DJJ&&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)DFVWK88FNND4I4I$JKLtyy|)CDEFFdiil(BCDEEtzz!ft{{&:nnQf(<=~~ae);<!#f"4dTE\6I"IJNNP
v~
2F6FF"3f5 +!&tTE\!: +A#AqDzQ-.QT
 %
++ 19)	( 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    xxdnn.c:
4222#66C"#3T5P5PQJJt%56E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:-1o#uS#X./o  o !)	o
 !$o &.e_o &+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ded ed!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de	e
ef   dedede	e
ef   dedededeeeee   f      deeeee   f      d2e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_namep   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"!*!6IsUX<Y	!)D	)6)BSVadHe%mP3E3Q/bepsWt*+=J^_"	 $,,"((2(>*DT&/&;!2"4"4&<#&<#+F(+F(&<#"4*!2'>$"4#6 '>$&<#%:"#6 :M:Y#6_r 8J8V"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:JJ4O 16)9?DX9Y !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efjfofofqersttH~tG}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25FFFr9   do_map_pixelsc                    t        |||	|
||||||
       t        |      }t        |      r|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   zIt 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%5!js
 $ >u EKKe$]nKoE$$5yTe$fELLuNVgLhENNZYbsNtEOOE*E"/{VghE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   | "+!6IDNN	'tTYYT"'38+9+E4K^K^!*!6IDNN	!)D	#-#9Zt
+9+E4K^K^'3'?|TEVEV#-#9Zt
!*!6IDNN	1B1N-TXTjTj3E3Q/W[WnWn3E3Q/W[WnWn&<&H"dNiNi 	 '=&H"dNiNi 	
 +6 (11 	$ +6 (11 	$ '=&H"dNiNi 	 4F3Q/W[WnWn)6)BHZHZ%mP1B1N-TXTjTj5H5T1Z^ZrZr'>'J#PTPlPl 	  (?'J#PTPlPl 	  4F3Q/W[WnWn*+=J^_&<&H"dNiNi 	 &;%F!DLfLf 	 6I5T1Z^ZrZr3E3Q/W[WnWn$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!^%6E6&+D"#>BBo
,< 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-07;',#'"!3!;!;(,"&$(5<'+&*GKFJAMoMo 38nMo %	Mo
 Mo S>Mo Mo c5j)Mo Mo U5(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  5Mo6 "7Mo8 "'sEz!29Mo: !%;Mo<  $=Mo> &eE8E?,B&CD?Mo@ %U5(5/+A%BCAMoD 
EMo^ 
AT#s(^ 
A 
A [
 

 
. (:'A'A>BDH.
zz.
 38n.
 %	.

 eC)9$9:;.
 $E#/?*?$@A.
 
.
`G

 Grzz G #'+#$( $!:>9="2B2H2H8<>> > 38n	>
 %> > S>> > > > U5$u+#567> E%e"456> > ./> $$45>  
!>@ %& %)#'+)-.2%)*.'+:>9=,0,0,004047;7;15-126+/267;.23715049=8<;?(8(>(>DHIvCvC D>vC 38n	vC
 %vC !vC DcN+vC TNvC !vC tnvC U5$u+#567vC E%e"456vC $D>vC %SMvC  %SM!vC" !)#vC$ !)%vC& &.e_'vC( &.e_)vC, !)-vC. %TN/vC0  S#X/1vC2 $C=3vC4 "*$5vC6 %T#s(^47vC8 &d^9vC: "*%;vC< !)=vC>  (~?vC@ &huo6AvCB %Xe_5CvCD !sJ!78EvCF &GvCH $E#/?*?$@AIvCJ 
KvC 'vCr9   ri   )4r   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   rg   r9   r7   <module>r      s    '    D D D  U U C    _ ^  
		H	% $ !% $  5 K K\tC, tCr9   