
    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  SS	KJrJr  SS
KJrJr  \ " S S\5      5       rS/rg)z$Image processor class for Perceiver.    N)
functional   )TorchvisionBackend)BatchFeature)group_images_by_shapereorder_images)IMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STDPILImageResamplingSizeDict)ImagesKwargsUnpack)
TensorTypeauto_docstringc                    0  ^  \ rS rSrSr\R                  r\r	\
rSSS.rSSS.rSrSrSrSrS\\   4U 4S jjrS	S
S\S\SS
4U 4S j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-  S\4 S jrSrU =r$ ) PerceiverImageProcessor    z:Torchvision backend for Perceiver with custom center crop.   heightwidth   Tkwargsc                 &   > [         TU ]  " S0 UD6  g )N )super__init__)selfr   	__class__s     ډ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/perceiver/image_processing_perceiver.pyr    PerceiverImageProcessor.__init__.   s    "6"    imageztorch.Tensorsize	crop_sizereturnc                   > UR                   b  UR                  c  [        SUR                  5        35      eUR                   b  UR                  c  [        SUR                  5        35      eUR                  SS u  pV[        XV5      n[        UR                   UR                   -  U-  5      n[        UR                  UR                  -  U-  5      n	[        T
U ]   " U[        XS940 UD6$ )a,  
Center crop an image to ((size.height / crop_size.height) * min_dim, (size.width / crop_size.width) * min_dim),
where min_dim is the minimum of the image height and width.
If the requested crop size exceeds the image dimensions along any edge, the image is padded with zeros before
center cropping.
Nz=The size dictionary must have keys 'height' and 'width'. Got zBThe crop_size dictionary must have keys 'height' and 'width'. Got r   )
r   r   
ValueErrorkeysshapeminintr   center_cropr   )r   r#   r$   r%   r   r   r   min_dimcropped_heightcropped_widthr   s             r    r.   #PerceiverImageProcessor.center_crop1   s     ;;$**"4\]a]f]f]h\ijkk#y'>abkbpbpbrastuuBC(f$dkkI,<,<<GHTZZ)//9WDEw"N@
 
 	
r"   images	do_resizeresamplez7PILImageResampling | tvF.InterpolationMode | int | Nonedo_center_crop
do_rescalerescale_factordo_normalize
image_meanN	image_stddo_padpad_sizedisable_groupingreturn_tensorsc           	         [        XS9u  nn0 nUR                  5        H"  u  nnU(       a  U R                  UX6S9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(       a  U R	                  UX4S9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XxXU5      nUUU'   M!     [        UU5      n[        SU0US9$ )zSCustom preprocessing for Perceiver: center_crop -> resize -> rescale and normalize.)r>   )r$   r%   )r#   r$   r5   pixel_values)datatensor_type)r   itemsr.   r   resizerescale_and_normalizer   )r   r3   r4   r$   r5   r6   r%   r7   r8   r9   r:   r;   r<   r=   r>   r?   r   grouped_imagesgrouped_images_indexcropped_images_groupedr+   stacked_imagescropped_imagesresized_images_groupedresized_imagesprocessed_images_groupedprocessed_imagess                              r    _preprocess#PerceiverImageProcessor._preprocessL   sD   ( 0EV/o,,!#%3%9%9%;!E>!%!1!1.t!1!a,:"5) &< ((>@TU/D^fv/w,,!#%3%9%9%;!E>!%>!`,:"5) &< ((>@TU/D^fv/w,,#% %3%9%9%;!E>!77
LV_N /=$U+	 &<
 **BDXY.2B!CQ_``r"   r   ) __name__
__module____qualname____firstlineno____doc__r   BICUBICr5   r	   r:   r
   r;   r$   r%   r4   r6   r7   r9   r   r   r   r   r.   listboolfloatstrr   r   rP   __static_attributes____classcell__)r   s   @r    r   r       sq   D!))H&J$IC(D-IINJL#!5 #

 
 	
 

6-a^$-a -a 	-a
 L-a -a -a -a -a -a DK'$.-a 4;&--a t-a T/-a +-a  j(4/!-a$ 
%-a -ar"   r   )rV   torchtorchvision.transforms.v2r   tvFimage_processing_backendsr   image_processing_utilsr   image_transformsr   r   image_utilsr	   r
   r   r   processing_utilsr   r   utilsr   r   r   __all__r   r"   r    <module>rh      sX    +  7 ; 2 E  5 / Xa0 Xa Xav %
%r"   