ó
    qyüi•  ã                   ó¢   • 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     €Úu/home/mande/repo/quber/.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[        X‰S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§¡Ñ'>ÜÐaÐbk×bpÑbpÓbrÐasÐtÓuÐuØŸ™ B CÐ(‰ˆÜ�fÓ$ˆÜ˜dŸk™k¨I×,<Ñ,<Ñ<ÀÑGÓHˆÜ˜TŸZ™Z¨)¯/©/Ñ9¸WÑ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XxXšU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Ø 
¸LÐV_óˆNð /=Ð$ UÓ+ñ	 &<ô
 *Ð*BÐDXÓYÐä .Ð2BÐ!CÐQ_Ñ`Ð`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"   