
     `i8                        U d Z ddlZddlZddlmZ ddlmZ ddl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$ ddl%m&Z&  e#            rddl'Z' e$j(        e)          Z*eZ+eZ,g dZ-g dZ.dZ/e0e1d<    G d d          Z2 e&d           G d de                      Z3dgZ4dS )z Image processor class for Flava.    N)Iterable)	lru_cache)AnyOptional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_flat_list_of_imagesto_numpy_arrayvalid_imagesvalidate_preprocess_arguments)
TensorTypefilter_out_non_signature_kwargsis_vision_availablelogging)requires)        r   r   )      ?r   r   g?LOGIT_LAPLACE_EPSc                       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dS )FlavaMaskingGenerator   K   N   333333?
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|| _        |pd|z  }t          j	        |          t          j	        |          f| _
        d S )N      )
isinstancetupleheightwidthnum_patchesr(   r*   r)   mathloglog_aspect_ratio)selfr'   r(   r)   r*   r+   r,   s          /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/models/flava/image_processing_flava.py__init__zFlavaMaskingGenerator.__init__=   s     *e,, 	+$*J",TZ;3"4&<#<R<Z&8&8`v#&A&dQIdEd#!%*E!F!FQlHmHm 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/   )r2   r3   r*   r)   r(   r7   )r8   repr_strs     r9   __repr__zFlavaMaskingGenerator.__repr__S   sK    QKJ''#!!$!!$U
 
 r;   c                     | j         | j        fS )Nr2   r3   )r8   s    r9   	get_shapezFlavaMaskingGenerator.get_shape_   s    {DJ&&r;   c           	      (   d}t          d          D ]~}t          j        | j        |          }t	          j        t          j        | j                   }t          t          t	          j	        ||z                                }t          t          t	          j	        ||z                                }|| j
        k     r|| j        k     rt          j        d| j        |z
            }	t          j        d| j
        |z
            }
||	|	|z   |
|
|z   f                                         }d||z  |z
  cxk     r|k    rIn nFt          |	|	|z             D ]2}t          |
|
|z             D ]}|||f         dk    rd|||f<   |dz  }3|dk    r n|S )Nr   
   r/   )rangerandomuniformr*   r5   expr7   introundsqrtr3   r2   randintsum)r8   maskmax_mask_patchesdelta_attempttarget_areaaspect_ratior2   r3   topleft
num_maskedijs                 r9   _maskzFlavaMaskingGenerator._maskb   s   b		 	 	H .)DFVWWK8FND4I$JKKLty|)CDDEEFFFdil(BCCDDEEEtz!!ft{&:&:nQf(<==~ae);<<!#f"4dTE\6I"IJNNPP
v~
2FFFF6FFFFFF"3f55 + +!&tTE\!:!: + +A#AqDzQ-.QT
 %
+
 199Er;   c                    t          j        |                                 t                    }d}|| j        k     rL| j        |z
  }t          || j                  }|                     ||          }|dk    rn||z  }|| j        k     L|S )N)shapedtyper   )npzerosrA   rH   r(   minr)   rX   )r8   rM   
mask_countrN   rO   s        r9   __call__zFlavaMaskingGenerator.__call__z   s    xdnn..c:::
4222#6C"#3T5PQQJJt%566Ezze#
 4222 r;   )r#   r$   Nr%   r&   N)__name__
__module____qualname__r   rH   r1   r   floatr:   r>   rA   rX   r`    r;   r9   r"   r"   <   s         35"$04&(7:7;o o#uS#X./o  o !)	o
 !$o &.e_o &.e_o o o o,
 
 
' ' '  0    r;   r"   )vision)backendsc            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ef                  dedede	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j        de
eef         ded.e	eeef                  d/e	eeef                  d(ej        fd0Zd-ej        d(ej        fd1Z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	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                  d2e	e         d.e	e         d/e	e         d(ej        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j        df d4e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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"j#        j#        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$   r%   r&   	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                      j        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          | _         ||ntD          | _#        d S )	N   r@   ro   
param_namep   ry   r|   re   )$superr:   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   ) r8   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                                   r9   r:   zFlavaImageProcessor.__init__   s   F 	""6"""'ttc-J-JT""!*!6IIsUX<Y<Y	!)DDD	)6)BSVadHeHe%mPPP3E3Q//bepsWtWt*+=J^___"	 $,,"((2(>**DT&/&;!2"4"4&<#&<#+F(+F(&<#"4*!2'>$"4#6 '>$&<#%:"#6 :M:Y#6#6_r 8J8V"4"4\nr;   image_processor_dictc                     |                                 }d|v r|                    d          |d<   d|v r|                    d          |d<    t                      j        |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      r9   r   zFlavaImageProcessor.from_dict4  s}      488::f$$4:JJ4O4O 16))9?DX9Y9Y !56 uww !5@@@@@r;   c                 ,    t          ||||||          S )N)r'   r(   r*   r)   r+   r,   )r"   )r8   rv   r(   r*   r)   r+   r,   s          r9   masking_generatorz%FlavaImageProcessor.masking_generatorA  s-     %)1#9#9(C(C
 
 
 	
r;   imagedata_formatinput_data_formatc                     t          |          }d|vsd|vr$t          d|                                           |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.
        r2   r3   zFThe `size` dictionary must contain the keys `height` and `width`. Got )rl   rm   r   r   )r   
ValueErrorkeysr   )r8   r   rl   rm   r   r   r   output_sizes           r9   r   zFlavaImageProcessor.resizeU  s    F T""47$#6#6sfjfofofqfqsstttH~tG}5
#/
 
 
 
 	
r;   c                 2    ddt           z  z
  |z  t           z   S )Nr/   r.   )r    )r8   r   s     r9   
map_pixelszFlavaImageProcessor.map_pixels  s    A)))U25FFFr;   do_map_pixelsc                    t          |||	|
||||||
  
         t          |          }|r)t          |          rt                              d           |t          |          }|r|                     ||||          }|r|                     |||          }|r|                     |||          }|	r| 	                    ||
||          }|r| 
                    |          }|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.N)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   )r8   r   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   r   r   r   s                  r9   _preprocess_imagez%FlavaImageProcessor._preprocess_image  sW   & 	&!)%!)	
 	
 	
 	
 u%% 	/%00 	s  
 $ >u E E 	pKKe$]nKooE 	g$$5yTe$ffE 	iLLuNVgLhhE 	uNNZYbsNttE 	+OOE**E"/{VghhhEr;   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 j        n j        t          d          n j        n j        n j        n j        t=          |          }t?          |          stA          d           	
! fd|D             }"d|"i}#|r  ! fd	|D             }$|$|#d
<   |r. !                    ||||||          &&fd|D             }%|%|#d<   tE          |#|          S )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.
        Nro   r   ry   r|   zkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.c                 V    g | ]%}                     |	d 
          &S )Fr   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   r   r   r   r   ).0imgro   r   rn   rr   rp   rk   rs   rt   r   rm   rq   r8   rl   s     r9   
<listcomp>z2FlavaImageProcessor.preprocess.<locals>.<listcomp>  sj     
 
 
" ! ""#!-#%-)%##'"3 #  
 
 
r;   rj   c                 V    g | ]%}                     |
	           &S )r   r   )r   r   r|   r{   r   r   r}   rx   r   r   rz   r~   ry   r   r   r8   s     r9   r   z2FlavaImageProcessor.preprocess.<locals>.<listcomp>  sj       " ! &&0&.#:02#:!620"8 +&7 '    r;   codebook_pixel_values)rv   r(   r*   r)   r+   r,   c                 $    g | ]}             S re   re   )r   _mask_generators     r9   r   z2FlavaImageProcessor.preprocess.<locals>.<listcomp>  s!    666!^^%%666r;   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
   )'r8   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   processed_imagesr   codebook_imagesmasksr   s'   ` ``````````        ``````````` ``    @r9   
preprocesszFlavaImageProcessor.preprocess  sM   | "+!6IIDN	'ttTYT""'388+9+E4K^!*!6IIDN	!)DDD	#-#9ZZt
+9+E4K^'3'?||TEV#-#9ZZt
!*!6IIDN	1B1N--TXTj3E3Q//W[Wn3E3Q//W[Wn&<&H""dNi 	 '=&H""dNi 	
 +6 ('1 	$ +6 ('1 	$ '=&H""dNi 	 4F3Q//W[Wn)6)BHZ%mPPP1B1N--TXTj5H5T11Z^Zr'>'J##PTPl 	  (?'J##PTPl 	  4F3Q//W[Wn*+=J^___&<&H""dNi 	 &;%F!!DLf 	 6I5T11Z^Zr3E3Q//W[Wn)&11F## 	:  

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
" #
 
 
&  01! 	<                " "#  O& -<D() 
	,!33#5#5'='=,G,G 4  N 7666v666E&+D"#>BBBBr;   )&ra   rb   rc   __doc__model_input_namesr   BICUBICLANCZOSboolr   dictstrrH   r   rd   r   r:   classmethodr   r   r   r"   r   r\   ndarrayr   r   r   FIRSTr   listr   r   r   PILImager   __classcell__)r   s   @r9   ri   ri      sR       U Un (( )-'9'A#.2,3!>B=A"'"$"$&(04-07;',#'(,!3!;(,,0$(5<'+&*GKFJAMo MoMo tCH~&Mo %	Mo
 Mo DcN+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 %SM5M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 Mo Mo Mo Mo Mo^ 
AT#s(^ 
A 
A 
A 
A 
A [
A 
 

 
 
 Y
. (:'A>BDH.
 .
z.
 38n.
 %	.

 eC)9$9:;.
 $E#/?*?$@A.
 
.
 .
 .
 .
`G
 Grz G G G G %))-15)-.2%)*.'+:>9=(,2B2H8<> >> D>> tCH~&	>
 -.> !> DcN+> TN> !> tn> U5$u+#567> E%e"456>  ~> ./> $$45>  
!> > > >@ %$&& %))-15)-.2%)*.'+:>9=,0,0,004047;7;15-126+/267;.23715049=8<;?(8(>DHIvC vCvC D>vC tCH~&	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 vC '&vC vC vC vC vCr;   ri   )5r   r5   rE   collections.abcr   	functoolsr   typingr   r   r   numpyr\   image_processing_utilsr	   r
   r   image_transformsr   r   image_utilsr   r   r   r   r   r   r   r   r   r   r   utilsr   r   r   r   utils.import_utilsr   r   
get_loggerra   r   r   r   r   r   r    rd   __annotations__r"   ri   __all__re   r;   r9   <module>r      sX   ' & &   $ $ $ $ $ $       ' ' ' ' ' ' ' ' ' '     U U U U U U U U U U C C C C C C C C                          _ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ * * * * * *  JJJ 
	H	%	% $ !%oo $__  5   K K K K K K K K\ 
;tC tC tC tC tC, tC tC  tCn !
!r;   