
    Z j;(                         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
Jr  SSKJrJrJrJr  SSKJrJr  SS	KJrJr   " S
 S\SS9r\ " S S\5      5       rS/rg)    N)
functional   )TorchvisionBackend)BatchFeatureget_patch_output_sizeselect_best_resolution)divide_to_patches)ChannelDimensionPILImageResamplingSizeDictget_image_size)ImagesKwargsUnpack)
TensorTypeauto_docstringc                   N    \ rS rSr% Sr\\S'   \\S'   \\\      \S'   \\S'   Sr	g)	AriaImageProcessorKwargs   a  
max_image_size (`int`, *optional*, defaults to `self.max_image_size`):
    Maximum image size. Must be either 490 or 980.
min_image_size (`int`, *optional*, defaults to `self.min_image_size`):
    Minimum image size. Images smaller than this in any dimension will be scaled up.
split_resolutions (`list[list[int]]`, *optional*, defaults to `self.split_resolutions`):
    A list of possible resolutions as (height, width) pairs for splitting high-resolution images into patches.
split_image (`bool`, *optional*, defaults to `self.split_image`):
    Whether to split the image into patches using the best matching resolution from `split_resolutions`.
max_image_sizemin_image_sizesplit_resolutionssplit_image N)
__name__
__module____qualname____firstlineno____doc__int__annotations__listbool__static_attributes__r       /root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/aria/image_processing_aria.pyr   r      s)    	 DI&r$   r   F)totalc                     ^  \ rS rSr/ SQr\r\R                  r	/ SQr
/ SQrSrSrSrSrSrSrSrS	\\   4U 4S
 jjrS\S\S\\   4S jrSSS\SSSS4S jrSSS\SS4S jrSSS\\\      S\SSS\S   4
S jr     S)S\S   S\S\S\S\\\   -  S-  S\\\   -  S-  S\S-  S\\-  S-  S \S!\S"\\\      S-  S#\SSS\ 4S$ jjr!S*S%\S&\4S' jjr"S(r#U =r$$ )+AriaImageProcessor1   pixel_values
pixel_mask	num_crops)      ?r.   r.     P  FNTkwargsc                    > UR                  S5      c'  / SQnU Vs/ s H  o3S   S-  US   S-  /PM     snUS'   [        TU ]  " S0 UD6  g s  snf )Nr   ))      )r3   r   )r3      )r3      )r3      )r3      )r3      )r4   r5   )r4   r   )r4   r4   )r4   r3   )r   r3   )r   r4   )r5   r3   )r5   r4   )r6   r3   )r7   r3   )r8   r3   )r9   r3   r     r3   r   )getsuper__init__)selfr1   default_resolutionsel	__class__s       r%   r=   AriaImageProcessor.__init__A   sa    ::)*2 #{Pc*dPc"qECKA+EPc*dF&'"6" +es   Aoriginal_resolutiontarget_resolutionreturnc                 d    Uu  p4Uu  pV[        Xd-
  S5      u  px[        XS-
  S5      u  pXyXx-   X-   /$ )zNGet padding size for patching, returns [left, top, right, bottom] for tvF.pad.r4   )divmod)r>   rC   rD   original_heightoriginal_widthtarget_heighttarget_widthpaste_xr_xpaste_yr_ys              r%   _get_padding_size$AriaImageProcessor._get_padding_sizeG   sE    *='&7#l;Q?m=qA'-??r$   imageztorch.Tensorresamplez7PILImageResampling | tvF.InterpolationMode | int | Nonec                 j    [        X[        R                  S9u  pEU R                  U[	        XES9U5      $ )zFResize an image to a target resolution while maintaining aspect ratio.input_data_formatheightwidth)r   r
   FIRSTresizer   )r>   rR   rD   rS   
new_height	new_widths         r%   _resize_for_patching'AriaImageProcessor._resize_for_patchingO   s8     !68H8N8N!

 {{5(*"NPXYYr$   c                 |    [        X[        R                  S9nU R                  X25      n[        R
                  " XS9$ )zCPad an image to a target resolution while maintaining aspect ratio.rU   )padding)r   r
   rZ   rP   tvFpad)r>   rR   rD   new_resolutionra   s        r%   _pad_for_patching$AriaImageProcessor._pad_for_patching[   s6     /u[k[q[qr((Kwwu..r$   grid_pinpoints
patch_sizec                     [        U[        5      (       d  [        S5      e[        U[        R
                  S9n[        XR5      nU R                  XU5      nU R                  Xv5      n[        XS9n	U	$ )a:  
Process an image with variable resolutions by dividing it into patches.

Args:
    image (`torch.Tensor`):
        The input image to be processed (channels-first format).
    grid_pinpoints (`list[list[int]]`):
        A list of possible resolutions as (height, width) pairs.
    patch_size (`int`):
        Size of each square patch to divide the image into.
    resample (`PILImageResampling | tvF.InterpolationMode | int | None`):
        Resampling filter to use when resizing.

Returns:
    `list[torch.Tensor]`: A list of image patches in channels-first format.
z6grid_pinpoints must be a list of possible resolutions.)channel_dim)rh   )

isinstancer!   	TypeErrorr   r
   rZ   r   r^   re   r	   )
r>   rR   rg   rh   rS   
image_sizebest_resolutionresized_imagepadded_imagepatchess
             r%   get_image_patches$AriaImageProcessor.get_image_patchese   sk    . .$//TUU#E7G7M7MN
0L11%(S--mM#LHr$   images
do_rescalerescale_factordo_normalize
image_mean	image_stddisable_groupingreturn_tensorsr   r   r   r   c           
      X   U	S;  a  [        S5      e/ n/ nS nU GHA  nU(       a  U R                  UXU5      nOU/nUb  [        U5      U:  a  [        U5      nU H  nUR                  S   UR                  S   nnU	[	        UU5      -  nUU:  a  [	        [        UU-  5      U
5      nU	nOU	n[	        [        UU-  5      U
5      nU R                  U[        UUS9U5      nU	U-
  nU	U-
  n[        R                  " USSUU/5      n[        R                  " X4[        R                  S9nSUS U2S U24'   UR                  U5        UR                  U5        M     GMD     [        R                  " USS	9nU R                  UX#XEU5      n[        R                  " USS	9n[!        UUUS
.US9$ )N)r:   r/   z(max_image_size must be either 490 or 980rW   r   )dtypeT)dimr*   )datatensor_type)
ValueErrorrr   lenshapemaxr   r[   r   rb   rc   torchzerosr"   appendstackrescale_and_normalizer   )r>   rt   ru   rv   rw   rx   ry   rz   r{   r   r   r   r   rS   r1   pixel_masksprocessed_cropsr-   rR   crop_images
crop_imagehwscalenew_hnew_wpadding_bottompadding_rightr,   stacked_imagesstacked_maskss                                  r%   _preprocessAriaImageProcessor._preprocess   s   " +GHH	E"44U<M_gh$g C$4y$@,	)
!''+Z-=-=b-A1&Q26AI?E*E*EAI?E![[XURW5XZbc
!/%!7 . 6 WWZ!Q~1VW
"[[.)IQVQ[Q[\
-1
6E66E6>*"":.&&z2' * < _!<33JR[
 KQ7 .+&
 '
 	
r$   rX   rY   c                     UR                  SU R                  5      nUR                  SU R                  5      n[        X4U R                  5      u  pgU(       d  SnU$ Xe-  U-  U-  nU$ )aU  
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`, *optional*):
        Any kwargs to override defaults of the image processor.

Returns:
    `int`: Number of patches per image.
r   r   r3   )r;   r   r   r   r   )	r>   rX   rY   images_kwargsr   r   resized_heightresized_widthnum_patchess	            r%   get_number_of_image_patches.AriaImageProcessor.get_number_of_image_patches   sv     $''t7G7GH&**+;T=P=PQ(>PTPfPf(g%*a 1?0PS`0`dr0rr$   r   )r/   r0   NFN)N)%r   r   r   r   model_input_namesr   valid_kwargsr   BICUBICrS   rx   ry   r   r   r   r   do_convert_rgbru   rw   r   r=   tupler!   r   rP   r^   re   rr   r"   floatstrr   r   r   r   r#   __classcell__)rA   s   @r%   r(   r(   1   s   C+L!))H JINNKNJL#(@!A #@U @u @Y]^aYb @
Z
Z !
Z L	
Z
 

Z// !/ 
	/ T#Y 	
 L 
n	V "!48!NRC
^$C
 C
 	C

 C
 DK'$.C
 4;&-C
 +C
 j(4/C
 C
 C
  S	?T1C
 C
 LC
  
!C
J# c  r$   r(   )r   torchvision.transforms.v2r   rb   image_processing_backendsr   image_processing_utilsr   r   r   image_transformsr	   image_utilsr
   r   r   r   processing_utilsr   r   utilsr   r   r   r(   __all__r   r$   r%   <module>r      s]   (  7 ; a a 1 Y Y 4 /|5 $ m+ m m`  
 r$   