
    cCi8                     v   % S r SSKrSSKrSSKJr  SSKJr  SSKJrJ	r	J
r
  SSKrSSKJrJrJr  SSKJrJr  SS	KJrJrJrJrJrJrJrJrJrJrJr  SS
K J!r!J"r"J#r#J$r$  SSK%J&r&  \#" 5       (       a  SSK'r'\$RP                  " \)5      r*\r+\r,/ SQr-/ SQr.Sr/\0\1S'    " S S5      r2\&" SS9 " S S\5      5       r3S/r4g)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                       \ rS rSr      SS\\\\\4   4   S\S\\   S\S\\   S\\   4S	 jjr	S
 r
S rS rS rSrg)FlavaMaskingGenerator<   N
input_sizetotal_mask_patchesmask_group_max_patchesmask_group_min_patchesmask_group_min_aspect_ratiomask_group_max_aspect_ratioc                 B   [        U[        5      (       d  U4S-  nUu  U l        U l        U R                  U R                  -  U l        X l        X@l        Uc  UOUU l        U=(       d    SU-  n[        R                  " U5      [        R                  " U5      4U l
        g )N      )
isinstancetupleheightwidthnum_patchesr%   r'   r&   mathloglog_aspect_ratio)selfr$   r%   r&   r'   r(   r)   s          j/home/james-whalen/.local/lib/python3.13/site-packages/transformers/models/flava/image_processing_flava.py__init__FlavaMaskingGenerator.__init__=   s     *e,,$*J",TZ;;3"4&<#<R<Z&8`v#&A&dQIdEd#!%*E!FQlHm n    c           	          SU R                   U R                  U R                  U R                  U R                  U R
                  S   U R
                  S   4-  nU$ )Nz<MaskingGenerator(%d, %d -> [%d ~ %d], max = %d, %.3f ~ %.3f)r   r,   )r/   r0   r'   r&   r%   r4   )r5   repr_strs     r6   __repr__FlavaMaskingGenerator.__repr__S   s^    QKKJJ''''##!!!$!!!$U
 
 r9   c                 2    U R                   U R                  4$ )Nr/   r0   )r5   s    r6   	get_shapeFlavaMaskingGenerator.get_shape_   s    {{DJJ&&r9   c           	      H   Sn[        S5       GH  n[        R                  " U R                  U5      n[        R
                  " [        R                  " U R                  6 5      n[        [        [        R                  " XV-  5      5      5      n[        [        [        R                  " XV-  5      5      5      nXR                  :  d  M  XpR                  :  d  M  [        R                  " SU R                  U-
  5      n	[        R                  " SU R                  U-
  5      n
XX-   2XU-   24   R                  5       nSXx-  U-
  s=:  a  U::  aD  O  OA[        XU-   5       H/  n[        XU-   5       H  nXU4   S:X  d  M  SXU4'   US-  nM     M1     US:  d  GM    U$    U$ )Nr   
   r,   )rangerandomuniformr'   r2   expr4   introundsqrtr0   r/   randintsum)r5   maskmax_mask_patchesdelta_attempttarget_areaaspect_ratior/   r0   topleft
num_maskedijs                 r6   _maskFlavaMaskingGenerator._maskb   s\   b	H ..)D)DFVWK88FNND4I4I$JKLtyy)CDEFFdii(BCDEEzz!f{{&:nnQf(<=~~ae);<!"4dE\6I"IJNNP
v~
2F6FF"3f5!&tE\!:A#qDzQ-.T
 %
 "; 6 19) "( r9   c                    [         R                  " U R                  5       [        S9nSnX R                  :  aS  U R                  U-
  n[        X0R                  5      nU R                  X5      nUS:X  a   U$ X$-  nX R                  :  a  MS  U$ )N)shapedtyper   )npzerosr@   rH   r%   minr&   rX   )r5   rM   
mask_countrN   rO   s        r6   __call__FlavaMaskingGenerator.__call__z   s    xxdnn.c:
222#66C"#35P5PQJJt6Ez  #
 222 r9   )r/   r4   r&   r'   r1   r%   r0   )   K   N   333333?N)__name__
__module____qualname____firstlineno__r   rH   r.   r   floatr7   r<   r@   rX   ra   __static_attributes__ r9   r6   r"   r"   <   s     35"$04&(7:7;o#uS#X./o  o !)	o
 !$o &.e_o &.e_o,
'0r9   r"   )vision)backendsc            G         ^  \ rS rSrSrS/rSS\R                  SSSSSSSSSS	S
SSSSSS\R                  SSSSSSSS4S\	S\
\\\4      S\S\	S\
\\\4      S\	S\\\4   S\	S\
\\\\   4      S\
\\\\   4      S\	S\S\S\S\
\   S\S\
\   S\	S\	S\
\	   S \S!\	S"\
\   S#\	S$\\\4   S%\	S&\	S'\
\\\\   4      S(\
\\\\   4      S)S4<U 4S* jjjr\S+\\\4   4U 4S, jj5       r\S)\4S- j5       r\R                  SS4S.\R2                  S\\\4   S\S/\
\\\4      S0\
\\\4      S)\R2                  4S1 jjrS.\R2                  S)\R2                  4S2 jrSSSSSSSSSSS\R:                  S4S.\S\
\	   S\
\\\4      S\
\   S\
\	   S\
\\\4      S\
\	   S\
\   S\
\	   S\
\\\\   4      S\
\\\\   4      S3\
\	   S/\
\   S0\
\   S)\R2                  4S4 jjr \!" 5       SSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\R:                  S4 S5\S\
\	   S\
\\\4      S\
\   S\
\	   S\
\\\4      S\
\	   S\
\   S\
\	   S\
\\\\   4      S\
\\\\   4      S\
\	   S\
\   S\
\   S\
\   S\
\   S\
\   S\
\   S\
\	   S\
\	   S\
\\\4      S \
\   S!\
\	   S"\
\\\4      S#\
\	   S$\
\   S%\
\	   S&\
\	   S'\
\\      S(\
\\      S6\
\\\"4      S/\S0\
\\\4      S)\#RH                  RH                  4DS7 jj5       r%S8r&U =r'$ )9FlavaImageProcessor   a  
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?Frc   rd   re   rf   	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U ]  " S0 UD6  Ub  UOSSS.n[        U5      nUb  UOSSS.n[        USS9nUb  UOSSS.n[        USS9nUb  UOSSS.n[        USS9nXl        X l        X0l        X`l        Xpl        X@l        XPl	        Xl
        U	b  U	O[        U l        U
b  U
O[        U l        Xl        Xl        Xl        Xl        Xl        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l         Ub  UO[B        U l         Ub  UU l#        g [D        U l#        g )	N   r?   rx   
param_namep   r   r   rm   )$superr7   r   rt   ru   rv   ry   rz   rw   rx   r{   FLAVA_IMAGE_MEANr|   FLAVA_IMAGE_STDr}   r~   r   r%   r'   r&   r(   r)   r   r   r   r   r   r   r   r   r   r   r   FLAVA_CODEBOOK_MEANFLAVA_CODEBOOK_STDr   ) r5   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r%   r'   r&   r(   r)   r   r   r   r   r   r   r   r   r   r   r   r   kwargs	__class__s                                   r6   r7   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                    > UR                  5       nSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   [        TU ]  " U40 UD6$ )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)`
r   r   )copypopr   	from_dict)clsr   r   r   s      r6   r   FlavaImageProcessor.from_dict4  sd      488:f$4:JJ4O 16)9?DX9Y !56w !5@@@r9   c           	          [        UUUUUUS9$ )N)r$   r%   r'   r&   r(   r)   )r"   )r5   r   r%   r'   r&   r(   r)   s          r6   masking_generator%FlavaImageProcessor.masking_generatorA  s#     %)1#9#9(C(C
 	
r9   imagedata_formatinput_data_formatc                     [        U5      nSU;  d  SU;  a  [        SUR                  5        35      eUS   US   4n[        U4UUUUS.UD6$ )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.
r/   r0   zFThe `size` dictionary must contain the keys `height` and `width`. Got )ru   rv   r   r   )r   
ValueErrorkeysr   )r5   r   ru   rv   r   r   r   output_sizes           r6   r   FlavaImageProcessor.resizeU  sy    F T"47$#6efjfofofqersttH~tG}5
#/
 
 	
r9   c                 .    SS[         -  -
  U-  [         -   $ )Nr,   r+   )r    )r5   r   s     r6   
map_pixelsFlavaImageProcessor.map_pixels  s    A)))U25FFFr9   do_map_pixelsc                    [        UUU	U
UUUUUUS9
  [        U5      nU(       a%  [        U5      (       a  [        R	                  S5        Uc  [        U5      nU(       a  U R                  XXNS9nU(       a  U R                  XUS9nU(       a  U R                  XUS9nU	(       a  U R                  XXS9nU(       a  U R                  U5      nUb
  [        XUS9nU$ )zPreprocesses a single image.)
ry   rz   r{   r|   r}   rw   rx   rt   ru   rv   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   ru   rv   r   )r   ru   r   )r   scaler   )r   meanstdr   )input_channel_dim)r   r   r   loggerwarning_oncer   r   center_croprescale	normalizer   r   )r5   r   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r   r   r   s                  r6   _preprocess_image%FlavaImageProcessor._preprocess_image  s    & 	&!)%!)	
 u%/%00s
 $ >u EKKeKoE$$5Te$fELLuVgLhENNYNtEOOE*E"/VghEr9   imagesreturn_tensorsc"                    Ub  UOU R                   nUb  UOU R                  n[        U5      nUb  UOU R                  nUb  UOU R                  nUb  UOU R
                  n[        USS9nUb  UOU R                  nUb  UOU R                  nU	b  U	OU R                  n	U
b  U
OU R                  n
Ub  UOU R                  nUb  UOU R                  nUb  UOU R                  nUb  UOU R                  nUb  UOU R                  nUb  UOU R                  nUb  UOU R                   nUb  UOU R"                  nUb  UOU R$                  nUb  UOU R&                  nUb  UOU R(                  n[        USS9nUb  UOU R*                  nUb  UOU R,                  nUb  UOU R.                  nUb  UOU R0                  nUb  UOU R2                  n[        USS9nUb  UOU R4                  nUb  UOU R6                  nUb  UOU R8                  nUb  UOU R:                  n[=        U5      n[?        U5      (       d  [A        S5      eU V"s/ s H  n"U RC                  U"UUUUUUUU	U
USU U!S9PM!     n#n"SU#0n$U(       a1  U V"s/ s H  n"U RC                  U"UUUUUUUUUUUU U!S9PM!     n%n"U%U$S	'   U(       a0  U RE                  UUUUUUS
9n&U V's/ s H
  n'U&" 5       PM     n(n'U(U$S'   [G        U$US9$ s  sn"f s  sn"f s  sn'f )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.
rx   r   r   r   zkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.F)r   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r   r   r   rs   codebook_pixel_values)r   r%   r'   r&   r(   r)   bool_masked_pos)datatensor_type)$rt   ru   r   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r%   r'   r&   r(   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   ))r5   r   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r%   r'   r&   r(   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   imgprocessed_imagesr   codebook_imagesmask_generator_maskss)                                            r6   
preprocess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)&1F##: , #
" ! ""#!-#%-)%##'"3 #   # 	 
&  01!$ "#" "C! &&0&.#:02#:!620"8 +&7 '   "#  & -<D()!33#5#5'='=,G,G 4 N 066v!^%vE6&+D"#>BBo
,< 7s   &K&8&K+K0)r   r   r   r   r   r   r   r   r   r   r   rx   rw   r{   ry   rt   r|   r}   r   r)   r&   r(   r'   rv   rz   r   r~   ru   r%   )(rg   rh   ri   rj   __doc__model_input_namesr   BICUBICLANCZOSboolr   dictstrrH   r   rk   r   r7   classmethodr   r   r   r"   r   r]   ndarrayr   r   r   FIRSTr   listr   r   r   PILImager   rl   __classcell__)r   s   @r6   rq   rq      s   Un (( )-'9'A'A#.2,3!>B=A"'"$"$&(04-07;',#'(,!3!;!;(,,0$(5<'+&*GKFJA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^ 
AT#s(^ 
A 
A 
 

 
. (:'A'A>BDH.
zz.
 38n.
 %	.

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

 Grzz G %))-15)-.2%)*.'+:>9=(,2B2H2H8<>> 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 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r9   rq   )5r   r2   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_loggerrg   r   r   r   r   r   r    rk   __annotations__r"   rq   __all__rm   r9   r6   <module>r      s    '   $  ' '  U U C    _ ^ *  
		H	% $ !% $  5 K K\ 
;tC, tC  tCn !
!r9   