
    cCi{                     V   S r SSKrSSKJrJr  SSKrSSKJrJ	r	J
r
  SSKJr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  SSKJrJrJrJrJrJ r J!r!  \" 5       (       a  SSK"r"\ RF                  " \$5      r%S	\\&\&\      \&\   \4   S
\&\&\      4S jr' " S S\	5      r( " S S\5      r)S/r*g)zImage processor class for Fuyu.    N)OptionalUnion   )BaseImageProcessorBatchFeatureget_size_dict)padresizeto_channel_dimension_format)
ChannelDimension
ImageInputPILImageResamplingget_image_sizeinfer_channel_dimension_formatis_scaled_imageis_valid_imagemake_list_of_imagesto_numpy_arrayvalidate_preprocess_arguments)
TensorTypefilter_out_non_signature_kwargsis_torch_availableis_torch_deviceis_torch_dtypeloggingrequires_backendsimagesreturnc                    [        U 5      (       a  U //$ [        U [        5      (       a  [        S U  5       5      (       a  U $ [        U [        5      (       a  U  Vs/ s H  n[	        U5      PM     sn$ [        S5      es  snf )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancelist).0images     h/home/james-whalen/.local/lib/python3.13/site-packages/transformers/models/fuyu/image_processing_fuyu.py	<genexpr>.make_list_of_list_of_images.<locals>.<genexpr>@   s     'TVE
5$(?(?Vs   zHimages must be a list of list of images or a list of images or an image.)r   r"   r#   allr   
ValueError)r   r%   s     r&   make_list_of_list_of_imagesr+   :   su     fz&$C'TV'T$T$T&$8>?u#E*??
_
`` @s   A?c                   D    \ rS rSrSrSS\\\\4      4S jjr	S	S jr
Srg)
FuyuBatchFeatureI   z
BatchFeature class for Fuyu image processor and processor.

The outputs dictionary from the processors contains a mix of tensors and lists of tensors.
Ntensor_typec                   ^^^^	 Uc  U $ U R                  US9u  mmUU4S jmUU	4S jnU R                  5        H  u  m	n[        U[        5      (       aG  [        US   [        5      (       a/  U VVs/ s H  oD Vs/ s H
  oR" U5      PM     snPM     snnU T	'   Mb  [        U[        5      (       a  U Vs/ s H
  oR" U5      PM     snU T	'   M  U" U5      U T	'   M     U $ s  snf s  snnf s  snf )a  
Convert the inner content to tensors.

Args:
    tensor_type (`str` or [`~utils.TensorType`], *optional*):
        The type of tensors to use. If `str`, should be one of the values of the enum [`~utils.TensorType`]. If
        `None`, no modification is done.
)r/   c                 2   > T" U 5      (       a  U $ T" U 5      $ r!    )elem	as_tensor	is_tensors    r&   _convert_tensor<FuyuBatchFeature.convert_to_tensors.<locals>._convert_tensor^   s    T?"    c                 X   >  T" U 5      $ !   TS:X  a  [        S5      e[        S5      e= f)Noverflowing_valueszKUnable to create tensor returning overflowing values of different lengths. zUnable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.)r*   )r3   r6   keys    r&   _safe_convert_tensorAFuyuBatchFeature.convert_to_tensors.<locals>._safe_convert_tensorc   sB    &t,,..$%rss X s    )r   )_get_is_as_tensor_fnsitemsr"   r#   )
selfr/   r<   valueelemsr3   r6   r4   r5   r;   s
         @@@@r&   convert_to_tensors#FuyuBatchFeature.convert_to_tensorsP   s     K#99k9R	9	#
		 **,JC%&&:eAh+E+EY^_Y^PUUKUT248UKY^_S	E4((DIJED1$7EJS	 17S	 '  L_ Ks   2	C$;CC$5C*C$c           
        ^^^^ [        U S/5        SSKm0 nTR                  S5      mTcz  [        T5      S:  ak  TS   n[	        U5      (       a  OU[        U[        5      (       d%  [        U5      (       d  [        U[        5      (       a  UmO[        S[        U5       S35      eUUUU4S jnU R                  5        H  u  pg[        U[        5      (       aP  [        US   [        5      (       a8  / nU H*  n	UR                  U	 V
s/ s H
  o" U
5      PM     sn
5        M,     XU'   Mj  [        U[        5      (       a  U V
s/ s H
  o" U
5      PM     sn
X6'   M  U" U5      X6'   M     X0l        U $ s  sn
f s  sn
f )a  
Send all values to device by calling `v.to(*args, **kwargs)` (PyTorch only). This should support casting in
different `dtypes` and sending the `BatchFeature` to a different `device`.

Args:
    args (`Tuple`):
        Will be passed to the `to(...)` function of the tensors.
    kwargs (`Dict`, *optional*):
        Will be passed to the `to(...)` function of the tensors.

Returns:
    [`BatchFeature`]: The same instance after modification.
torchr   Ndevicez*Attempting to cast a BatchFeature to type z. This is not supported.c                 ~   > TR                   " U 5      (       a  U R                  " T0 TD6$ Tb  U R                  TS9$ U $ )N)rG   )is_floating_pointto)r3   argsrG   kwargsrF   s    r&   _to FuyuBatchFeature.to.<locals>._to   sD    &&t,,ww///!wwfw--Kr8   )r   rF   getlenr   r"   strr   intr*   r?   r#   appenddata)r@   rK   rL   new_dataargrM   kvnew_vrB   r3   rG   rF   s    ``        @@r&   rJ   FuyuBatchFeature.to{   sK    	$	*H%>c$i!mq'Cc""C%%)=)=CQTAUAU !#McRUhZWo!pqq	 	 JJLDA!T""z!A$'='=ELL!>#d)!>? #At$$567QTs4yQ7!!f ! 	 "? 8s   E0E5rT   r!   )r   r   )__name__
__module____qualname____firstlineno____doc__r   r   rQ   r   rC   rJ   __static_attributes__r2   r8   r&   r-   r-   I   s'    )huS*_7M.N )V8r8   r-   c            !         ^  \ rS rSrSr/ SQrSS\R                  SSSSSSSS	S4S
\S\	\
\\4      S\S\S\S\S\S\\\\   4   S\\\\   4   S\S\S\	\
\\4      4U 4S jjjr\R                  SS4S\R$                  S\
\\4   S\S\	\\\4      S\	\\\4      S\R$                  4S jjr    S/S\R$                  S\
\\4   S\S\S\	\\\4      S\	\\\4      S\R$                  4S jjr\" 5       SSSSSSSSSSSS\R.                  SS4S
\	\   S\	\
\\4      S\	\   S\	\   S\	\   S\	\   S\	\   S\	\   S\	\   S\	\   S\	\   S\	\
\\4      S\	\\\4      S\	\\\4      S\	\   4S  jj5       rS0S!\S"\S\	\
\\4      S\4S# jjrS0SS$S\	\
\\4      SS$4S% jjr S0S&S$S'S$S(S$S)S$S*\S+\S,\S\	\
\\4      S\4S- jjrS.rU =r$ )1FuyuImageProcessor   a  
This class should handle the image processing part before the main FuyuForCausalLM. In particular, it should
handle:

- Processing Images:
    Taking a batch of images as input. If the images are variable-sized, it resizes them based on the desired patch
    dimensions. The image output is always img_h, img_w of (1080, 1920)

    Then, it patches up these images using the patchify_image function.

- Creating Image Input IDs:
    For each patch, a placeholder ID is given to identify where these patches belong in a token sequence. For
    variable-sized images, each line of patches is terminated with a newline ID.

- Image Patch Indices:
    For each image patch, the code maintains an index where these patches should be inserted in a token stream.


Args:
    do_resize (`bool`, *optional*, defaults to `True`):
        Whether to resize the image to `size`.
    size (`dict[str, int]`, *optional*, defaults to `{"height": 1080, "width": 1920}`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
    resample (`PILImageResampling`, *optional*, defaults to `Resampling.BILINEAR`):
        `PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.BILINEAR`.
    do_pad (`bool`, *optional*, defaults to `True`):
        Whether to pad the image to `size`.
    padding_value (`float`, *optional*, defaults to 1.0):
        The value to pad the image with.
    padding_mode (`str`, *optional*, defaults to `"constant"`):
        The padding mode to use when padding the image.
    do_normalize (`bool`, *optional*, defaults to `True`):
        Whether to normalize the image.
    image_mean (`float`, *optional*, defaults to 0.5):
        The mean to use when normalizing the image.
    image_std (`float`, *optional*, defaults to 0.5):
        The standard deviation to use when normalizing the image.
    do_rescale (`bool`, *optional*, defaults to `True`):
        Whether to rescale the image.
    rescale_factor (`float`, *optional*, defaults to `1 / 255`):
        The factor to use when rescaling the image.
    patch_size (`dict[str, int]`, *optional*, defaults to `{"height": 30, "width": 30}`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the patches.
r   image_input_idsimage_patchesimage_patch_indices_per_batch#image_patch_indices_per_subsequenceTN      ?constantg      ?gp?	do_resizesizeresampledo_padpadding_valuepadding_modedo_normalize
image_mean	image_std
do_rescalerescale_factor
patch_sizec                    > [         TU ]  " S0 UD6  Xl        Ub  UOSSS.U l        X0l        X@l        XPl        X`l        Xpl        Xl	        Xl
        Xl        Xl        Ub  Xl        g SSS.U l        g )Ni8  i  )heightwidth   r2   )super__init__rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   )r@   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rL   	__class__s                 r&   r}   FuyuImageProcessor.__init__   st      	"6"" ,DTD2Q	 *(($"$,(2(>*r\^D_r8   r%   data_formatinput_data_formatr   c           	          [        X5      u  pxUS   US   pX::  a  Xy::  a  U$ X-  nX-  n[        X5      n[        X}-  5      n[        X-  5      n[        SUX4UUUS.UD6nU$ )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.BILINEAR`):
        `PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.BILINEAR`.
    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.
ry   rz   )r%   rm   rn   r   r   r2   )r   minrR   r
   )r@   r%   rm   rn   r   r   rL   image_heightimage_widthtarget_heighttarget_widthheight_scale_factorwidth_scale_factoroptimal_scale_factor
new_height	new_widthscaled_images                    r&   r
   FuyuImageProcessor.resize
  s    F %35$L!&*8nd7m|&<+HL+:)7"#6K<=
:;	 
(#/
 
 r8   modeconstant_valuesc           	      n    [        X5      u  pxUS   US   pSnSnX-
  nX-
  n[        UX4X44UUUUS9nU$ )a0  
Pad an image to `(size["height"], size["width"])`.

Args:
    image (`np.ndarray`):
        Image to pad.
    size (`dict[str, int]`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
    data_format (`ChannelDimension` or `str`, *optional*):
        The data format of the output image. If unset, the same format as the input image is used.
    input_data_format (`ChannelDimension` or `str`, *optional*):
        The channel dimension format of the input image. If not provided, it will be inferred.
ry   rz   r   )paddingr   r   r   r   )r   r	   )r@   r%   rm   r   r   r   r   r   r   r   r   padding_toppadding_leftpadding_bottompadding_rightpadded_images                   r&   	pad_imageFuyuImageProcessor.pad_imageD  si    , %35$L!&*8nd7m|&5$2!2\4QR+#/
 r8   return_tensorsc                 
   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[        5      (       a"  [        S U 5       5      (       a  [        S5      e[!        U5      n[#        UUUU	U
UUUS9  U VVs/ s H  o Vs/ s H  n[%        U5      PM     snPM      nnnU Vs/ s H  o(       d  M  UPM     snS   S   nU(       a%  ['        U5      (       a  [(        R+                  S5        Uc  [-        U5      nU Vs/ s H  o(       d  M  [/        US   US9PM     nn[1        U5      nU(       a3  U VVs/ s H$  nU Vs/ s H  nU R3                  UX?S9PM     snPM&     nnnU Vs/ s H  o(       d  M  [/        US   US9PM     nnU Vs/ s H	  nUS   /PM     nnU Vs/ s H	  nUS   /PM     nn[5        UU5       VVs/ s H  u  nnUS   US   -  /PM     nnnU(       a6  U VVs/ s H'  nU Vs/ s H  nU R7                  UUUUUS	9PM     snPM)     nnnU(       a3  U VVs/ s H$  nU Vs/ s H  nU R9                  UXS
9PM     snPM&     nnnU(       a4  U VVs/ s H%  nU Vs/ s H  nU R;                  UXUS9PM     snPM'     nnnUb/  U VVs/ s H   nU Vs/ s H  n[=        UX5      PM     snPM"     nnnUUUUS.n[?        UUS9$ s  snf s  snnf s  snf s  snf s  snf s  snnf s  snf s  snf s  snf s  snnf s  snf s  snnf s  snf s  snnf s  snf s  snnf s  snf s  snnf )a  

Utility function to preprocess the images and extract necessary information about original formats.

Args:
    images (`ImageInput`):
        Images to preprocess. Expects a single image, a list or images or a list of lists of images. Pixel
        values range from 0 to 255, or between 0 and 1 if `do_rescale` is `False`.
    do_resize (`bool`, *optional*, defaults to `self.do_resize`):
        Whether to resize the image to `size`.
    size (`dict[str, int]`, *optional*, defaults to `self.size`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
    resample (`PILImageResampling`, *optional*, defaults to `self.resample`):
        `PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.BILINEAR`.
    do_pad (`bool`, *optional*, defaults to `self.do_pad`):
        Whether to pad the image to `size`.
    padding_value (`float`, *optional*, defaults to `self.padding_value`):
        The value to pad the image with.
    padding_mode (`str`, *optional*, defaults to `self.padding_mode`):
        The padding mode to use when padding the image.
    do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
        Whether to normalize the image.
    image_mean (`float`, *optional*, defaults to `self.image_mean`):
        The mean to use when normalizing the image.
    image_std (`float`, *optional*, defaults to `self.image_std`):
        The standard deviation to use when normalizing the image.
    do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
        Whether to rescale the image.
    rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
        The factor to use when rescaling the image.
    patch_size (`dict[str, int]`, *optional*, defaults to `self.patch_size`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the patches.
    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 of the output 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.
    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.
c              3   l   #    U  H*  n[        U[        5      =(       a    [        U5      S :  v   M,     g7f)   N)r"   r#   rP   )r$   r3   s     r&   r'   0FuyuImageProcessor.preprocess.<locals>.<genexpr>  s+     +ibhZ^JtT,B,Us4yTU~,Ubhs   24z:Multiple images for a single sample are not yet supported.)ru   rv   rr   rs   rt   rl   rm   rn   r   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.)channel_dim)rm   r      )rm   r   r   r   )scaler   )meanstdr   )r   image_unpadded_heightsimage_unpadded_widthsimage_scale_factors)rT   r/   ) rl   rm   rn   ro   ru   rv   rr   rs   rt   rp   rq   rw   r"   r#   anyr*   r+   r   r   r   loggerwarning_oncer   r   r   r
   zipr   rescale	normalizer   r-   )r@   r   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   r   r   r   batch_imagesr%   first_image_in_listoriginal_image_sizesimage_sizes
image_sizer   r   original_sizeresized_sizer   rT   s                                r&   
preprocessFuyuImageProcessor.preprocessj  s   L "+!6IDNN	'tTYY'38!-4;;#-#9Zt
+9+E4K^K^'3'?|TEVEV#-#9Zt
!*!6IDNN	)6)BHZHZ'3'?|TEVEV#-#9Zt
+9+E4K^K^#-#9Zt
fd##+ibh+i(i(iYZZ26:%!)%!		
 S__R^FCF5.FCR^_ 5AKL&FvLKANqQ/*=>>s
 $ >?R S T` 
S_ciDN6!92CDS_ 	  
 T" +*F bhhagX]USagh*  
 _ku^jTZntO~fQi=NO^juDO!PKj:a=/K!PCN O;Z*Q-; O
 033G/U
/U+| !_}Q//0/U 	 

  + +F "(	 "( NN!)(5*; #  "(	 +    +*F nttmsdie>_mst*  
  +
 +F "(!' NN5z\mNn!' +   " +*F bhhagX],UKSagh*   #&<%:#6	
  T~FF_ D_ L 
 i
 v!P O
	  u is   	N)N$$N)2
N/ N/
N4N4
N>N9)N>7
OOO	2OO;
OO"O8
O)O$O)2
O4<O/O4)
O?3O:	O?$N)9N>O$O)/O4:O?r   r   c                     Ub  UOU R                   nU R                   S   U R                   S   pTX-  S:w  a  [        SU< SU 35      eX%-  S:w  a  [        SU< SU 35      eX-  nX%-  nXg-  nU$ )a`  
Calculate number of patches required to encode an image.

Args:
    image_height (`int`):
        Height of the image.
    image_width (`int`):
        Width of the image.
    patch_size (`dict[str, int]`, *optional*, defaults to `self.patch_size`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the patches.
ry   rz   r   zimage_height=z must be divisible by zimage_width=)rw   r*   )	r@   r   r   rw   patch_heightpatch_widthnum_patches_per_dim_hnum_patches_per_dim_wnum_patchess	            r&   get_num_patches"FuyuImageProcessor.get_num_patches   s     $.#9Zt
$(OOH$=tw?Wk&!+.D\NSTT$)~-CK=QRR , < + :+Cr8   ztorch.Tensorc                 \   [        U S/5        Ub  UOU R                  nUS   US   pCUR                  u  pV  nUR                  SX35      nUR                  SXD5      n	U	R	                  5       n	U	R                  XVSX45      n	U	R                  SSSSS	5      n	U	R                  USXc-  U-  5      n	U	$ )
aD  
Convert an image into a tensor of patches.

Args:
    image (`torch.Tensor`):
        Image to convert. Shape: [batch, channels, height, width]
    patch_size (`dict[str, int]`, *optional*, defaults to `self.patch_size`):
        Dictionary in the format `{"height": int, "width": int}` specifying the size of the patches.
rF   ry   rz   r   r   r      r   )r   rw   shapeunfold
contiguousviewpermutereshape)
r@   r%   rw   r   r   
batch_sizechannels_unfolded_along_heightpatchess
             r&   patchify_image!FuyuImageProcessor.patchify_image9  s     	$	*#-#9Zt
$.x$8*W:Mk
 &+[["
a %Q K'..q+K$$&,,zRS//!Q1a0//*b(2IK2WXr8   image_inputimage_presentimage_unpadded_himage_unpadded_wimage_placeholder_idimage_newline_idvariable_sizedc	           
         [        U S/5        Ub  UOU R                  nUS   US   p/ n/ n/ n[        UR                  S   5       GH`  n/ n/ n[        UR                  S   5       GH  nX.U4   (       Ga  XU4   nUR                  S   UR                  S   nnU(       af  [	        U[
        R                  " X>U4   U	-  5      U	-  5      n[	        U[
        R                  " XNU4   U
-  5      U
-  5      nUSS2SU2SU24   nUUnnU R                  UUS9n[        R                  " U/U[        R                  UR                  S	9nU R                  UR                  S5      S
9R                  S5      nUUR                  S   :X  d   eU(       a{  UR                  SUU
-  5      n[        R                  " UR                  S   S/U[        R                  UR                  S	9n[        R                   " UU/SS9nUR                  S5      nUR#                  U/5        UR#                  U5        UR#                  U5        GM  UR#                  [        R$                  " / [        R                  UR                  S	95        GM     UR#                  U5        UR#                  U5        GMc     / n/ nU GH  nSn/ n/ n U H  n!U!U:H  n"[        R&                  " U"5      n[        R(                  " U[        R*                  U!R                  S	9R-                  U!5      n#[        R.                  " U!S5      n$[        R.                  " U!S5      n%[        R0                  " U"SS9S   n&U#U-   U$U&'   U#U%U&'   UR#                  U$5        U R#                  U%5        UU-  nM     UR#                  U5        UR#                  U 5        GM
     [3        UUUUUS.S9$ )a   Process images for model input. In particular, variable-sized images are handled here.

Args:
    image_input (`torch.Tensor` of shape [batch_size, subsequence_size, num_channels, height, width]):
        Tensor of images padded to model input size.
    image_present (`torch.Tensor` of shape [batch_size, subsequence_size, num_images]):
        Tensor of 1s and 0s indicating whether an image is present.
    image_unpadded_h (`torch.Tensor` of shape [batch_size, subsequence_size]):
        Tensor of unpadded image heights.
    image_unpadded_w (`torch.Tensor` of shape [batch_size, subsequence_size]):
        Tensor of unpadded image widths.
    image_placeholder_id (int):
        The id of the image placeholder token. Comes from an associated tokenizer.
    image_newline_id (int):
        The id of the image newline token. Comes from an associated tokenizer.
    variable_sized (bool):
        Whether to process images as variable-sized.
    patch_size (`dict[str, int]`, *optional*, defaults to `self.patch_size`):
        Size of the patches.
rF   Nry   rz   r   r   r   )r   r   )dtyperG   )r%   r   )dimT)as_tuplere   r[   )r   rw   ranger   r   mathceilr   rF   fullint32rG   r   	unsqueezesqueezer   catrS   tensorcount_nonzeroarangeint64type_as	full_likenonzeror-   )'r@   r   r   r   r   r   r   r   rw   r   r   r   batch_image_patchesbatch_image_input_idsbatch_indexrf   rg   subseq_indexr%   r   r   new_hnew_wr   tensor_of_image_idsr   newline_idsrh   ri   sample_image_input_idsindex_offsetper_batch_indicesper_subsequence_indicessubseq_image_input_idspatches_maskindicesindices_in_stream_per_batch!indices_in_stream_per_subsequencepatches_indss'                                          r&   preprocess_with_tokenizer_info1FuyuImageProcessor.preprocess_with_tokenizer_infoS  s   > 	$	*#-#9Zt
$.x$8*W:Mk ,.8::< !2!21!56K OM %k&7&7&: ; l!:;;'\(ABE05AA+L% !$( II&6L7P&QT`&`adpp! !$' II&6L7P&QT_&_`cnn! !&a%%&7 8495k"&"6"6L^i"6"jK*/**$';5;;WbWiWi+' #118J1KSSTUVG&'--*::::%.A.I.I"k]hNh.i+&+jj066q91=,"'++#.#5#5	' /4ii9Lk8Z`a.b+.A.I.I".M+MM5'*#**+>?!((1#**5<<%++VaVhVh+ijS !<V "((9&&}5_ 7f CE%HJ+&;"L "&(#*@&59MM#11,?,,{%++NdNkNkltt*
 /4oo>TVX.Y+49OODZ\^4_1$}}\DI!L<Cl<R+L9BI1,?!(()DE'../PQ+% +A( *001BC/667NO3 '<6   #8!41N7Z
 	
r8   )rr   ro   ru   rl   rs   rt   rq   rp   rw   rn   rv   rm   )rk   rj   NNr!   ) r\   r]   r^   r_   r`   model_input_namesr   BILINEARboolr   dictrQ   rR   floatr   r#   r}   npndarrayr   r
   r   r   FIRSTr   r   r   r   r-   r   ra   __classcell__)r~   s   @r&   rc   rc      sV   +Z )-'9'B'B"&!03/2 '/3`` tCH~&` %	`
 ` ` ` ` %e,-` U+,` ` ` T#s(^,` `D (:'B'B>BDH8zz8 38n8 %	8
 eC)9$9:;8 $E#/?*?$@A8 
8| !$>BDH$zz$ 38n$ 	$
 $ eC)9$9:;$ $E#/?*?$@A$ 
$L %& %))-15!%)-&*'+&*%)%)*./3>N>T>TDH/3#sG D>sG tCH~&	sG
 -.sG sG  sG smsG tnsG UOsG E?sG TNsG !sG T#s(^,sG eC)9$9:;sG  $E#/?*?$@A!sG" !,#sG 'sGjC c xX\]`be]eXfOg sv 2N cSVh@X dr F 04B
#B
 &B
 )	B

 )B
 "B
 B
 B
 T#s(^,B
 
B
 B
r8   rc   )+r`   r   typingr   r   numpyr  image_processing_utilsr   r   r   image_transformsr	   r
   r   image_utilsr   r   r   r   r   r   r   r   r   r   utilsr   r   r   r   r   r   r   rF   
get_loggerr\   r   r#   r+   r-   rc   __all__r2   r8   r&   <module>r     s    &  "  U U 
      
		H	%a$tJ'($z*:JFGa	$z
aj| jZ_
+ _
D  
 r8   