
    Z j"                         S 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  SS	KJr  SS
KJrJr  SrSr " S S\SS9r\ " S S\5      5       rS/rg)zImage processor class for Vilt.    N)
functional   )TorchvisionBackend)BatchFeature)group_images_by_shapereorder_images)IMAGENET_STANDARD_MEANIMAGENET_STANDARD_STDPILImageResamplingSizeDictget_max_height_width)ImagesKwargs)
TensorTypeauto_docstringi5  i   c                   $    \ rS rSr% Sr\\S'   Srg)ViltImageProcessorKwargs)   z
size_divisor (`int`, *optional*, defaults to `self.size_divisor`):
    The size by which to make sure both the height and width can be divided. Only has an effect if `do_resize`
    is set to `True`.
size_divisor N)__name__
__module____qualname____firstlineno____doc__int__annotations____static_attributes__r       /root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/vilt/image_processing_vilt.pyr   r   )   s     r   r   F)totalc                   \  ^  \ rS rSr\r\R                  r\	r
\rSS0rSrSrSrSrSrSrSS/r  SS
SS\SSS\S	-  SS4
U 4S jjjr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	-  S\4S jjr Sr!U =r"$ ) ViltImageProcessor3   shortest_edgei  T    Fpixel_values
pixel_maskNimagesztorch.Tensorsizeresamplez7PILImageResampling | tvF.InterpolationMode | int | Noner   returnc                   > UR                   n[        [        [        -  U-  5      nUR                  S   nUR                  S   nXx:  a
  Un	XU-  -  n
O	XuU-  -  n	Un
[        X5      U:  a  U[        X5      -  nX-  n	X-  n
[        U	S-   5      n	[        U
S-   5      n
Ub  X-  U-  n	X-  U-  n
[        TU ]  U[        XS9US9$ )a  
Resize an image or batch of images to specified size.

Args:
    images (`torch.Tensor`): Image or batch of images to resize.
    size (`SizeDict`): Size dictionary with shortest_edge key.
    resample (`PILImageResampling | tvF.InterpolationMode | int`, *optional*): Interpolation method to use.
    size_divisor (`int`, *optional*): Value to ensure height/width are divisible by.

Returns:
    `torch.Tensor`: Resized image or batch of images.
g      ?)heightwidth)r*   )	r$   r   MAX_LONGER_EDGEMAX_SHORTER_EDGEshapemaxsuperresizer   )selfr(   r)   r*   r   shorterlongerheightswidthsnew_heights
new_widthsscale	__class__s               r   r6   ViltImageProcessor.resizeB   s    * $$_'77'AB,,r"b! !KW#45J!v%56K J {'&0S99E%-K#+J++,c)*
 #%5DK#3lBJ w~fhk&T_g~hhr   return_tensorsdisable_groupingc                 P   [        U5      n[        XS9u  pV0 n0 nUR                  5        GH^  u  pUS:X  a?  [        U
5      S:  a0  U
R                  n[
        R                  " U[
        R                  US9nU
R                  SS nUS   US   :g  =(       d    US   US   :g  nU(       a  US   US   -
  nUS   US   -
  nSSUU/n[        R                  " U
USS9nWR                  5       nUSUS   2SUS   24   R                  S5        UR                  S5      R                  U
R                  S   SS5      nOFU
n[
        R                  " U
R                  S   US   US   4[
        R                  U
R                  S9nUXy'   UX'   GMa     [!        Xv5      n[!        X5      nUU4$ )	a(  
Pad a batch of images to the same size based on the maximum dimensions.

Args:
    images (`list[torch.Tensor]`): List of images to pad.
    return_tensors (`str` or `TensorType`, *optional*): The type of tensors to return.

Returns:
    `tuple`: Tuple containing padded images and pixel masks.
rB   ptr   )dtypedevicer-   N   )fill)r   r   itemslenrG   torchzerosint64r3   tvFpadclonefill_	unsqueezerepeatonesr   )r7   r(   rA   rB   max_sizegrouped_imagesgrouped_images_indexprocessed_imagesprocessed_masksr3   stacked_imagesrG   mask_templateoriginal_sizeneeds_paddingpadding_bottompadding_rightpaddingpadded_imagesr'   pixel_maskss                        r   
_pad_batchViltImageProcessor._pad_batchv   s   " (/ 0EV/o,%3%9%9%;!E%#n*=*A'.. %HEKKPV W*005M)!,;^}Q?OS[\]S^?^M!)!}Q/?!? (mA.> >a? #a H*002
-]1--/Aq1A/AABHHK(2215<<^=Q=QRS=TVWYZ[ .#jj#))!,hqk8A;G++)00 '4#%0O"9 &<> ''7N$_Kk))r   	do_resize
do_rescalerescale_factordo_normalize
image_mean	image_stddo_padc           	         [        XS9u  nn0 nUR                  5        H%  u  nnU(       a  U R                  UX4U5      nUUU'   M'     [        UU5      n[        U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5      n0 nU
(       a  U R                  UXS9u  nnUUS.nO US:X  a  [        R                  " U5      nSU0n[        UUS9$ )NrD   )r&   r'   rE   r&   )datatensor_type)	r   rJ   r6   r   rescale_and_normalizerd   rL   stackr   )r7   r(   rf   r)   r*   rg   rh   ri   rj   rk   rl   rB   rA   r   kwargsrW   rX   resized_images_groupedr3   r[   resized_imagesprocessed_images_groupedrY   rn   r&   r'   s                             r   _preprocessViltImageProcessor._preprocess   s4   $ 0EV/o,,!#%3%9%9%;!E>!%^T\!Z,:"5) &< ((>@TU 0E^fv/w,,#% %3%9%9%;!E>!77
LV_N /=$U+ &< **BDXY '+ . (7 ($L* %1
KD %#(;;/?#@ "$45D>BBr   r   )NN)N)#r   r   r   r   r   valid_kwargsr   BICUBICr*   r	   rj   r
   rk   r)   rf   rg   ri   r   rl   default_to_squaremodel_input_namesr   r   r6   liststrr   booltuplerd   floatr   rv   r   __classcell__)r?   s   @r   r"   r"   3   s   +L!))H'J%IS!DIJLLF'6 OS#'2i2i 2i L	2i
 Dj2i 
2i 2ih:*^$:* j(4/:* +	:*
 
:*T $(5C^$5C 5C 	5C
 L5C 5C 5C 5C DK'$.5C 4;&-5C t5C +5C j(4/5C Dj5C  
!5C 5Cr   r"   )r   rL   torchvision.transforms.v2r   rO   image_processing_backendsr   image_processing_utilsr   image_transformsr   r   image_utilsr	   r
   r   r   r   processing_utilsr   utilsr   r   r1   r2   r   r"   __all__r   r   r   <module>r      su    &  7 ; 2 E  -  |5  sC+ sC sCl  
 r   