ó
    qyüiô[  ã                   ó  • S r SSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJrJrJrJrJrJr  SS	KJrJr  SS
KJrJrJr  \R:                  " \5      rSr  " S S\SS9r! S%S\"S\"S\"S-  S\"S-  S\#\"\"4   4
S jjr$ S&S\"S\"S\%\&\"4   S-  S\#\"\"4   4S jjr'SSS\"S\#\"\"4   4S jr(S\)\)S      S\#\"\"4   4S jr*S\)\)S      S\"4S jr+S\)\)S      SS4S  jr,SSS!\#\"\"4   SS4S" jr-\ " S# S$\	5      5       r.S$/r/g)'z#Image processor class for Idefics3.é    N)Ú
functionalé   )ÚTorchvisionBackend)ÚBatchFeature)Úgroup_images_by_shapeÚreorder_images)ÚIMAGENET_STANDARD_MEANÚIMAGENET_STANDARD_STDÚ
ImageInputÚPILImageResamplingÚSizeDictÚmake_nested_list_of_images)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringÚloggingi   c                   óB   • \ rS rSr% Sr\\S'   \\\	4   \S'   \\S'   Sr
g)ÚIdefics3ImageProcessorKwargsé*   aZ  
do_image_splitting (`bool`, *optional*, defaults to `True`):
    Whether to split the image into sub-images concatenated with the original image. They are split into patches
    such that each patch has a size of `max_image_size["height"]` x `max_image_size["width"]`.
max_image_size (`Dict`, *optional*, defaults to `{"longest_edge": 364}`):
    Maximum resolution of the patches of images accepted by the model. This is a dictionary containing the key "longest_edge".
return_row_col_info (`bool`, *optional*, defaults to `False`):
    Whether to return the row and column information of the images.
Údo_image_splittingÚmax_image_sizeÚreturn_row_col_info© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚboolÚ__annotations__ÚdictÚstrÚintÚ__static_attributes__r   ó    Ús/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/models/idefics3/image_processing_idefics3.pyr   r   *   s#   ‡ ñð ÓØ˜˜c˜‘NÓ"ØÖr&   r   F)ÚtotalÚheightÚwidthÚmin_lenÚmax_lenÚreturnc                 óæ   • Uc  [        X5      OUnX-  nX:¼  a  Un[        X-  5      n U S-  S:w  a  U S-  n O"X:”  a  Un [        X-  5      nUS-  S:w  a  US-  n[        X5      n [        X5      nX4$ )aâ  
Get the output size of the image after resizing given a dictionary specifying the max and min sizes.
Args:
    height (`int`):
        Height of the input image.
    width (`int`):
        Width of the input image.
    min_len (`int`, *optional*, defaults to 1):
        Minimum size of the output image.
    max_len (`int`, *optional*, defaults to the maximum size of the image):
        Maximum size of the output image.
Returns:
    The output size of the image after resizing.
é   r   é   ©Úmaxr$   )r)   r*   r+   r,   Úaspect_ratios        r'   Ú&_resize_output_size_rescale_to_max_lenr4   :   s�   € ð" %,¡OŒc�&Ô ¸€GØ‘>€LàƒØˆÜ�UÑ)Ó*ˆØ�A‰:˜‹?Ø�a‰KˆFøØ	‹ØˆÜ�FÑ)Ó*ˆØ�1‰9˜‹>Ø�Q‰JˆEô �Ó!€FÜ�Ó€EØˆ=Ðr&   c                 óÆ   • Uc  [        X5      OUnX-  nX:¼  a  X:”  a  Un[        X-  5      n OX:”  a  X:”  a  Un [        X-  5      n[        U S5      n [        US5      nX4$ )až  
Get the output size of the image after resizing given a dictionary specifying the max and min sizes.
Args:
    height (`int`):
        Height of the input image.
    width (`int`):
        Width of the input image.
    max_len (`Dict[str, int]`, *optional*, defaults to the maximum size of the image):
        Defines the maximum dimensions of the image.
Returns:
    The output size of the image after resizing.
r0   r1   )r)   r*   r,   r3   s       r'   Ú+_resize_output_size_scale_below_upper_boundr6   _   sr   € ð %,¡OŒc�&Ô ¸€Gà‘>€LØƒ˜5›?ØˆÜ�UÑ)Ó*‰Ø	‹˜FÓ,ØˆÜ�FÑ)Ó*ˆô �˜‹^€FÜ��q‹M€EØˆ=Ðr&   Úimageútorch.TensorÚresolution_max_sidec                 ób   • U R                   SS u  p#[        X#US9u  p#[        X#[        S9u  p#X#4$ )a‹  
Get the output size of the image after resizing given a dictionary specifying the max and min sizes.
Args:
    image (`torch.Tensor`):
        Image to resize.
    resolution_max_side (`int`):
        The longest edge of the image will be resized to this value. The shortest edge will be resized to keep the
        input aspect ratio.
Returns:
    The output size of the image after resizing.
éþÿÿÿN©r,   )Úshaper4   r6   ÚMAX_IMAGE_SIZE)r7   r9   r)   r*   s       r'   Úget_resize_output_image_sizer?   ~   s>   € ð —K‘K  Ð$�M€Fô ;¸6ÐReÑf�M€Fä?ÀÔWeÑf�M€FØˆ=Ðr&   Úimages_listztorch.Tensor|np.ndarrayc                 ó´   • / nU  H*  nU H!  nUR                  UR                  SS 5        M#     M,     [        S U 5       5      n[        S U 5       5      nXE4$ )z@
Get the maximum height and width across all images in a batch.
r;   Nc              3   ó*   #   • U  H	  oS    v •  M     g7f)r   Nr   ©Ú.0Úsizes     r'   Ú	<genexpr>Ú'get_max_height_width.<locals>.<genexpr>Ÿ   s   é € Ð5ª ˜!–Wªùó   ‚c              3   ó*   #   • U  H	  oS    v •  M     g7f©r0   Nr   rC   s     r'   rF   rG       s   é € Ð4ª ˜–GªùrH   )Úappendr=   r2   )r@   Úimage_sizesÚimagesr7   Ú
max_heightÚ	max_widths         r'   Úget_max_height_widthrP   –   sa   € ð €KÛˆÛˆEØ×Ñ˜uŸ{™{¨2¨3Ð/Ö0ó ñ ô Ñ5©Ó5Ó5€JÜÑ4©Ó4Ó4€IØÐ"Ð"r&   c                 ó`   • U  H  nU(       d  M  US   R                   S   s  $    [        S5      e)zg
Get the number of channels across all images in a batch. Handle empty sublists like in [[], [image]].
r   zNo images found in the batch.)r=   Ú
ValueError©r@   rM   s     r'   Úget_num_channelsrT   ¤   s4   € ó ˆßˆ6Ø˜!‘9—?‘? 1Ñ%Ò%ñ ô Ð4Ó
5Ð5r&   ztorch.devicec                 óF   • U  H  nU(       d  M  US   R                   s  $    g)zz
Get the device from the first non-empty element in a nested list of images.
Handle empty sublists like in [[], [image]].
r   N)ÚdevicerS   s     r'   Úget_device_from_imagesrW   ¯   s#   € ó
 ˆßˆ6Ø˜!‘9×#Ñ#Ò#ò r&   Úoutput_sizec                 óš   • U R                   SS u  p#[        R                  " U[        R                  U R                  S9nSUSU2SU24'   U$ )zî
Make a pixel mask for the image, where 1 indicates a valid pixel and 0 indicates padding.

Args:
    image (`torch.Tensor`):
        Image to make the pixel mask for.
    output_size (`Tuple[int, int]`):
        Output size of the mask.
r;   N)ÚdtyperV   r0   )r=   ÚtorchÚzerosÚint64rV   )r7   rX   Úinput_heightÚinput_widthÚmasks        r'   Úmake_pixel_maskra   ¹   sM   € ð !&§¡¨B¨CÐ 0Ñ€LÜ�;Š;�{¬%¯+©+¸e¿l¹lÑK€DØ()€Dˆˆ,ˆ˜˜˜Ð	$Ñ%Ø€Kr&   c                    ót  ^ • \ rS rSr\R
                  r\r\	r
SS0rSS0rSrSrSrSrSrSrSr\rSS/rS	\\   4U 4S
 jjr\S\S	\\   S\4U 4S jj5       rS1S\S\S\4S jjr S2SSS\SSSS4U 4S jjjr  S2S\!RD                  S\#\$\4   SS4S jjr% S2S\!RD                  S\SS4S jjr&  S3S\!RD                  S\'\\4   S\S\(4S jjr)S\*\*S      S\(S\SSS \(S!\+S"\(S#\+\*\+   -  S-  S$\+\*\+   -  S-  S%\(S-  S&\(S-  S\#\$\4   S-  S'\(S-  S(\(S-  S)\$\,-  S-  S\4 S* jr-U 4S+ jr.S,\S-\S.\#4S/ jr/S0r0U =r1$ )4ÚIdefics3ImageProcessoréÉ   Úlongest_edgei°  il  TFÚpixel_valuesÚpixel_attention_maskÚkwargsc                 ó&   >• [         TU ]  " S0 UD6  g )Nr   )ÚsuperÚ__init__)Úselfrh   Ú	__class__s     €r'   rk   ÚIdefics3ImageProcessor.__init__Ú   s   ø€ Ü‰ÒÑ"˜6Ó"r&   rM   r-   c                 ó&   >• [         TU ]  " U40 UD6$ ©N)rj   Ú
preprocess)rl   rM   rh   rm   s      €r'   rq   Ú!Idefics3ImageProcessor.preprocessÝ   s   ø€ ä‰wÒ! &Ñ3¨FÑ3Ð3r&   Úexpected_ndimsc                 ó6   • U R                  U5      n[        XS9$ )z3
Prepare a nested images structure for processing.
)rs   )Úfetch_imagesr   )rl   rM   rs   s      r'   Ú_prepare_images_structureÚ0Idefics3ImageProcessor._prepare_images_structureá   s   € ð
 ×"Ñ" 6Ó*ˆÜ)¨&ÑPÐPr&   Nr7   r8   rE   Úresamplez7PILImageResampling | tvF.InterpolationMode | int | Nonec                 ó  >• UR                   (       a  [        XR                   S9nOFUR                  (       a*  UR                  (       a  UR                  UR                  4nO[	        S5      e[
        TU ]  " U[        US   US   S94SU0UD6$ )aÆ  
Resize an image. The longest edge of the image is resized to size.longest_edge, with the shortest edge
resized to keep the input aspect ratio. Can also be used with size.height and size.width.
Args:
    image (`torch.Tensor`):
        Image to resize.
    size (`SizeDict`):
        Size of the output image.
    resample (`PILImageResampling | tvF.InterpolationMode | int | None`, *optional*):
        Resampling filter to use when resizing the image.
)r9   zJsize must be a dictionary with key 'longest_edge' or 'height' and 'width'.r   r0   ©r)   r*   rx   )re   r?   r)   r*   rR   rj   Úresizer   )rl   r7   rE   rx   rh   Únew_sizerm   s         €r'   r{   ÚIdefics3ImageProcessor.resizeé   sv   ø€ ð$ ××Ü3°E×O`ÑO`Ña‰HØ�[�[˜TŸZŸZØŸ™ T§Z¡ZÐ0‰HäÐiÓjÐjä‰wŠ~˜e¤X°X¸a±[ÈÐQRÉÑ%TÑrÐ_gÐrÐkqÑrÐrr&   r   c                 ó"  • UR                  5       u  pEpgSu  p‰US   =p«/ nXj:”  d  X{:”  aÂ  [        R                  " Xj-  5      n[        R                  " X{-  5      nUR                  XŠU
S9R                  X›US9R	                  5       R                  XESX«5      R                  SSSSS	5      nX«nnU R                  U[        UUS
9US9n[        R                  " XÁR                  S5      4SS9nOSu  pÞUR                  S5      nU/U-  nU/U-  nXÍU4$ )a€  
Split an image into squares of side max_image_size and the original image resized to max_image_size.
That means that a single image becomes a sequence of images.
This is a "trick" to spend more compute on each image with no changes in the vision encoder.
1) If one side of the original image is larger than `max_image_size`, resize it to `max_image_size` while preserving the aspect ratio.
2) Divide the resulting image into `ceil(height / max_image_size)` x `ceil(width / max_image_size)`
sub-images of the same size each (image_size, image_size). Typically, 364x364.
3) Returns the list of the crops and the original image, in addition to the number of splits for the height and the width.
Args:
    images (`torch.Tensor`):
        Images to split.
    max_image_size (`Dict[str, int]`):
        Maximum size of the output image. If the image is larger than this size, it will be split into
        patches of this size, and the original image will be concatenated with the patches, resized to max_size.
    resample (`PILImageResampling | tvF.InterpolationMode | int | None`, *optional*):
        Resampling filter to use when resizing the image.
)r/   r   re   )rE   Ústepéÿÿÿÿr   r/   r0   r   é   rz   ©rx   )Údim)r   r   )rE   ÚmathÚceilÚunfoldÚ
contiguousÚviewÚpermuter{   r   r[   ÚcatÚ	unsqueeze)rl   rM   r   rx   Ú
batch_sizeÚnum_channelsr)   r*   Ú
height_dimÚ	width_dimrN   rO   ÚframesÚnum_splits_hÚnum_splits_wÚglobal_image_heightÚglobal_image_widths                    r'   Úsplit_imagesÚ#Idefics3ImageProcessor.split_images  s2  € ð. 39·+±+³-Ñ/ˆ
 &Ø $Ñˆ
à!/°Ñ!?Ð?ˆ
àˆØÓ %Ó"3äŸ9š9 VÑ%8Ó9ˆLÜŸ9š9 UÑ%6Ó7ˆLð —‘˜jÀ
�ÐKß‘˜	¸	�ÐBß‘“ß‘�j°°JÓJß‘˜˜A˜q ! QÓ'ð ð 7AÐ!3ÐØ—[‘[ØœÐ(;ÐCUÑVÐaið !ð ˆFô —Y’Y ×(8Ñ(8¸Ó(;Ð<À!ÑD‰Fà)-Ñ&ˆLØ×%Ñ% aÓ(ˆFà$�~¨
Ñ2ˆØ$�~¨
Ñ2ˆà \Ð1Ð1r&   Úvision_encoder_max_sizec                 óˆ  • UR                  5       SS u  pEXT-  nXT:¼  aD  [        R                  " XR-  5      U-  n[        XV-  5      n[        R                  " XB-  5      U-  nOHXE:”  aC  [        R                  " XB-  5      U-  n[        XF-  5      n[        R                  " XR-  5      U-  n[	        XES9nU R                  XUS9$ )a(  
Resize images to be multiples of `vision_encoder_max_size` while preserving the aspect ratio.
Args:
    image (`torch.Tensor`):
        Images to resize.
    vision_encoder_max_size (`int`):
        Maximum size of the output image. If the image is larger than this size, it will be split into
        patches of this size, and the original image will be concatenated with the patches, resized to max_size.
    resample (`PILImageResampling | tvF.InterpolationMode | int | None`, *optional*):
        Resampling filter to use when resizing the image.
r;   Nrz   )rE   rx   )rE   r„   r…   r$   r   r{   )rl   r7   r—   rx   r)   r*   r3   r|   s           r'   Úresize_for_vision_encoderÚ0Idefics3ImageProcessor.resize_for_vision_encoder?  s¼   € ð" Ÿ
™
› R SÐ)‰ˆà‘~ˆØ‹?Ü—I’I˜eÑ=Ó>ÐAXÑXˆEÜ˜Ñ-Ó.ˆFÜ—Y’Y˜vÑ?Ó@ÐCZÑZ‰FØ‹^Ü—Y’Y˜vÑ?Ó@ÐCZÑZˆFÜ˜Ñ-Ó.ˆEÜ—I’I˜eÑ=Ó>ÐAXÑXˆEÜ 6Ñ7ˆØ�{‰{˜5¸(ˆ{ÐCÐCr&   Úpadded_sizeÚfillÚreturn_pixel_maskc                 ó^  • UR                   SS  nUS   US   -
  nUS   US   -
  nUS:  d  US:  a  [        SU SU S35      eXR:w  a  SSXv4n[        R                  " XUSS9nS n	U(       a?  [        R
                  " US	SS S 2S S 24   [        R                  S
9n	SU	S US   2S US   24'   X4$ )Nr;   r   r0   zzPadding dimensions are negative. Please make sure that the padded size is larger than the original size. Got padded size: z, original size: Ú.Úconstant)rœ   Úpadding_mode.)rZ   )r=   rR   ÚtvFÚpadr[   Ú
zeros_liker]   )
rl   r7   r›   rœ   r�   Úoriginal_sizeÚpadding_bottomÚpadding_rightÚpaddingÚ
pixel_masks
             r'   r£   ÚIdefics3ImageProcessor.pad^  só   € ð Ÿ™ B CÐ(ˆØ$ Q™¨-¸Ñ*:Ñ:ˆØ# A™¨°qÑ)9Ñ9ˆà˜AÓ °Ó!2Üð3Ø3>°-Ð?PÐQ^ÐP_Ð_`ðbóð ð Ó'Ø˜!˜]Ð;ˆGÜ—G’G˜E°ÀJÑOˆEð ˆ
ÞÜ×)Ò)¨%°°Qºº1°Ñ*=ÄUÇ[Á[ÑQˆJØABˆJÐ)˜ qÑ)Ð)Ð+=¨]¸1Ñ-=Ð+=Ð=Ñ>àÐ Ð r&   Ú	do_resizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚdo_padr   r   Údisable_groupingÚreturn_tensorsc           	      ó”  • [        USUS9u  nn0 nUR                  5        H"  u  nnU(       a  U R                  UX4S9nUUU'   M$     [        UUSS9n[        USUS9u  nn0 nU(       a®  0 n0 nUR                  5        H=  u  nnU R	                  UUS   US9nU R                  UXÄS9u  nnnUUU'   UUU'   UUU'   M?     [        UUSS9n[        UUSS9n[        UUSS9n[        U5       H(  u  nnU VV s/ s H  nU  H  n U PM     M     sn nUU'   M*     O‡UR                  5        H*  u  nnU R                  U[        US   US   S9US9nUUU'   M,     [        UUSS9nU Vs/ s H  nS	/[        U5      -  PM     nnU Vs/ s H  nS	/[        U5      -  PM     nn[        USUS9u  nn0 n!UR                  5        H  u  nnU R                  UXVXxU	5      nUU!U'   M!     [        U!USS9nU
(       aÐ  [        S
 U 5       5      n"[        U5      u  n#n$[        U5      n%[        U5      n&[        R                  " [        U5      U"/U%U#U$4Q7SU&06n'[        R                  " [        U5      U"/U#U$4Q7SU&06n([        U5       H<  u  nn[        U5       H'  u  n)n U R!                  U U#U$45      u  U'UU)4'   U(UU)4'   M)     M>     U'nU
(       a  UW(S.n*OHUS:X  a>  S[        R"                  " U Vs/ s H  n[        R"                  " U5      PM     sn5      0n*OSU0n*[%        U*US9n+U(       a
  UU+S'   UU+S'   U+$ s  sn nf s  snf s  snf s  snf )z*
Process a batch of images for the model.
T)Ú	is_nestedr²   r‚   )rµ   re   )r   rx   rz   )r7   rE   rx   r   c              3   ó8   #   • U  H  n[        U5      v •  M     g 7frp   )Úlen)rD   Úimages_s     r'   rF   Ú5Idefics3ImageProcessor._preprocess.<locals>.<genexpr>Ï  s   é € Ð NÒ=M°'¤ W§ Ò=Mùs   ‚rV   )rf   rg   Úptrf   )ÚdataÚtensor_typeÚrowsÚcols)r   Úitemsr{   r   r™   r•   Ú	enumerater   r·   Úrescale_and_normalizer2   rP   rT   rW   r[   r\   r£   Ústackr   ),rl   rM   r«   rE   rx   r¬   r­   r®   r¯   r°   r±   r   r   r   r²   r³   rh   Úgrouped_imagesÚgrouped_images_indexÚresized_images_groupedr=   Ústacked_imagesÚresized_imagesÚsplit_images_groupedÚrows_groupedÚcols_groupedr½   r¾   Úprocessed_imagesÚiÚgroup_imagesÚsublistr7   Úprocessed_images_groupedÚmax_num_imagesrN   rO   r�   rV   Úprocessed_images_paddedÚpixel_attention_masksÚjr»   Úencodings,                                               r'   Ú_preprocessÚ"Idefics3ImageProcessor._preprocess|  sC  € ô. 0EØ˜dÐ5Eñ0
Ñ,ˆÐ,ð "$ÐØ%3×%9Ñ%9Ö%;Ñ!ˆE�>ÞØ!%§¡¨^¸T Ð!U�Ø,:Ð" 5Ó)ñ &<ô (Ð(>Ð@TÐ`dÑeˆä/DØ dÐ=Mñ0
Ñ,ˆÐ,ð  "ÐÞØˆLØˆLØ)7×)=Ñ)=Ö)?Ñ%��~Ø!%×!?Ñ!?Ø" N°>Ñ$BÈXð "@ð "�ð .2×->Ñ->Ø"°>ð .?ð .Ñ*�  dð /=Ð$ UÑ+Ø&*�˜UÑ#Ø&*�˜UÓ#ñ *@ô  .Ð.BÐDXÐdhÑiÐÜ! ,Ð0DÐPTÑUˆDÜ! ,Ð0DÐPTÑUˆDä#,Ð-=Ö#>‘��<Ù<HÔ&^ºL°ÔV]ÈU£uÑV]¡u¹LÒ&^Ð  Ó#ò $?ð *8×)=Ñ)=Ö)?Ñ%��~à!%§¡Ø(Ü!¨¸Ñ)GÈ~Ð^lÑOmÑnØ%ð "-ð "�ð
 /=Ð$ UÓ+ñ *@ô  .Ð.BÐDXÐdhÑiÐÙ4DÓEÒ4D¨&�Q�Cœ#˜f›+Ô%Ñ4DˆDÐEÙ4DÓEÒ4D¨&�Q�Cœ#˜f›+Ô%Ñ4DˆDÐEô 0EØ¨Ð?Oñ0
Ñ,ˆÐ,ð $&Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆE�>à!×7Ñ7Ø 
¸LÐV_óˆNð /=Ð$ UÓ+ñ &<ô *Ð*BÐDXÐdhÑiÐÞä Ñ NÑ=MÓ NÓNˆNÜ$8Ð9IÓ$JÑ!ˆJ˜	Ü+Ð,<Ó=ˆLÜ+Ð,<Ó=ˆFä&+§k¢kÜÐ$Ó%Øð'ð  
¨IÐ6ò'ð ñ	'Ð#ô %*§K¢KÜÐ$Ó%Øð%ð ˜iÐ(ò%ð ñ	%Ð!ô 'Ð'7Ö8‘	��6Ü )¨&Ö 1‘H�A�uØQU×QYÑQYØ 
¨IÐ6óRÑNÐ+¨A¨q¨DÑ1Ð3HÈÈAÈÓ3Nó !2ñ 9ð
  7ÐæØ$4ÐNcÑd‰DØ˜tÓ#Ø"¤E§K¢KÑScÓ0dÒScÈ´·²¸VÖ1DÑScÑ0dÓ$eÐf‰Dà"Ð$4Ð5ˆDä T°~ÑFˆæØ#ˆH�VÑØ#ˆH�VÑàˆùóC '_ùò FùÚEùòV 1es   Ã5L5Å$L;ÆM Ë+ M
c                 ól   >• [         TU ]  5       nUR                  SS 5        UR                  SS 5        U$ )NÚ_valid_processor_keysr   )rj   Úto_dictÚpop)rl   Úencoder_dictrm   s     €r'   rÙ   ÚIdefics3ImageProcessor.to_dictö  s7   ø€ Ü‘w‘Ó(ˆØ×ÑÐ0°$Ô7Ø×ÑÐ.°Ô5ØÐr&   r)   r*   Úimages_kwargsc                 óø  • UR                  SU R                  5      nUR                  SU R                  5      nUR                  SU R                  5      nS=n=p‰U(       Ga  [	        XUS   S9u  p[        X[        S9u  pX!-  n
X!:¼  aP  [        R                  " X%S   -  5      US   -  n[        X*-  5      n[        R                  " XS   -  5      US   -  nOTX:”  aO  [        R                  " XS   -  5      US   -  n[        X-  5      n[        R                  " X%S   -  5      US   -  nUS   =pÞWU:”  d  WU:”  a8  [        R                  " XÍ-  5      n[        R                  " WU-  5      n	X‰-  S-   nXxU	4$ )aG  
A utility that returns number of image patches for a given image size.

Args:
    height (`int`):
        Height of the input image.
    width (`int`):
        Width of the input image.
    images_kwargs (`dict`)
        Any kwargs to override defaults of the image processor.
Returns:
    `int`: Number of patches per image.
r   r   rE   r   re   r<   r0   )
Úgetr   r   rE   r4   r6   r>   r„   r…   r$   )rl   r)   r*   rÝ   r   r   rE   Únum_patchesÚnum_rowsÚnum_colsr3   Úresized_widthÚresized_heightrN   rO   s                  r'   Úget_number_of_image_patchesÚ2Idefics3ImageProcessor.get_number_of_image_patchesü  sŒ  € ð +×.Ñ.Ð/CÀT×E\ÑE\Ó]ÐØ&×*Ñ*Ð+;¸T×=PÑ=PÓQˆØ× Ñ  ¨¯©Ó3ˆà,-Ð-ˆÐ-�hßÜBÀ6ÐZ^Ð_mÑZnÑo‰MˆFÜGÈÔ_mÑn‰MˆFØ ™>ˆLà‹Ü $§	¢	¨%ÀÑ2PÑ*PÓ QÐTbÐcqÑTrÑ r�Ü!$ UÑ%9Ó!:�Ü!%§¢¨6À>Ñ4RÑ+RÓ!SÐVdÐesÑVtÑ!t‘Ø“Ü!%§¢¨6À>Ñ4RÑ+RÓ!SÐVdÐesÑVtÑ!t�Ü # FÑ$9Ó :�Ü $§	¢	¨%ÀÑ2PÑ*PÓ QÐTbÐcqÑTrÑ r�à%3°NÑ%CÐCˆJØ 
Ó*¨m¸iÓ.GäŸ9š9 ^Ñ%@ÓA�ÜŸ9š9 ]°YÑ%>Ó?�Ø&Ñ1°AÑ5�à hÐ.Ð.r&   r   )r   rp   )r   T)2r   r   r   r   r   ÚLANCZOSrx   r	   r¯   r
   r°   rE   r   r«   r¬   r®   Údo_convert_rgbr   r±   r   r   Úvalid_kwargsÚmodel_input_namesr   rk   r   r   r   rq   r$   rv   r   r{   r[   ÚTensorr"   r#   r•   r™   Útupler    r£   ÚlistÚfloatr   rÕ   rÙ   rå   r%   Ú__classcell__)rm   s   @r'   rc   rc   É   sÐ  ø† à!×)Ñ)€HØ'€JØ%€IØ˜GÐ$€DØ$ cÐ*€NØ€IØ€JØ€LØ€NØÐØ€FØÐØ/€LØ'Ð)?Ð@Ðð# Ð(DÑ!E÷ #ð ð4 ð 4°vÐ>ZÑ7[ð 4Ð`lö 4ó ð4ñQ°
ð QÈCð QÐXbõ Qð OSñ	sàðsð ðsð Lð	sð 
÷sð sð> OSñ	92à—‘ð92ð ˜S #˜X™ð92ð Lõ	92ð~ OSñ	Dà�|‰|ðDð "%ðDð Lõ	DðF Ø"&ñ!à�|‰|ð!ð ˜3 ˜8‘_ð!ð ð	!ð
  õ!ð<xà�T˜.Ñ)Ñ*ðxð ðxð ð	xð
 Lðxð ðxð ðxð ðxð ˜D ™KÑ'¨$Ñ.ðxð ˜4 ™;Ñ&¨Ñ-ðxð �t‘ðxð ! 4™Kðxð ˜S #˜X™¨Ñ-ðxð " D™[ðxð  ™+ðxð  ˜jÑ(¨4Ñ/ð!xð$ 
ô%xõtð(/°#ð (/¸cð (/ÐRV÷ (/ò (/r&   rc   rJ   rp   )0r   r„   ÚnumpyÚnpr[   Útorchvision.transforms.v2r   r¢   Úimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr   r   Úimage_utilsr	   r
   r   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   Ú
get_loggerr   Úloggerr>   r   r$   rì   r4   r"   r#   r6   r?   rí   rP   rT   rW   ra   rc   Ú__all__r   r&   r'   Ú<module>rü      s·  ðñ *ã ã Û Ý 7å ;Ý 2ß E÷÷ ÷ 5ß 8Ñ 8ð 
×	Ò	˜HÓ	%€à€ô <°uò ð" MQñ"Øð"Øð"Ø&)¨D¡jð"Ø?BÀT¹zð"à
ˆ3�ˆ8�_õ"ðL ?CñØðØðØ&*¨3°¨8¡n°tÑ&;ðà
ˆ3�ˆ8�_õð>Øðàðð ˆ3�ˆ8�_ôð0# d¨4Ð0IÑ+JÑ&Kð #ÐPUÐVYÐ[^ÐV^ÑP_ô #ð6 $ tÐ,EÑ'FÑ"Gð 6ÈCô 6ð$¨¨T°.Ñ-AÑ(Bð $À~ô $ð˜>ð ¸¸cÀ3¸h¹ð ÈNô ð  ôZ/Ð/ó Z/ó ðZ/ðz
 $Ð
$�r&   