ó
    qyüi6!  ã                   ó¾   • 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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)zImage processor class for TVP.é    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_docstringc                   óP   • \ rS rSr% Sr\\S'   \\\   -  S-  \S'   \	S-  \S'   Sr
g)ÚTvpImageProcessorKwargsé"   uÎ  
do_flip_channel_order (`bool`, *optional*, defaults to `self.do_flip_channel_order`):
    Whether to flip the channel order of the image from RGB to BGR.
constant_values (`float` or `List[float]`, *optional*, defaults to `self.constant_values`):
    Value used to fill the padding area when `pad_mode` is `'constant'`.
pad_mode (`str`, *optional*, defaults to `self.pad_mode`):
    Padding mode to use â€” `'constant'`, `'edge'`, `'reflect'`, or `'symmetric'`.
Údo_flip_channel_orderNÚconstant_valuesÚpad_mode© )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚboolÚ__annotations__ÚfloatÚlistÚstrÚ__static_attributes__r   ó    Úi/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/models/tvp/image_processing_tvp.pyr   r   "   s-   ‡ ñð  ÓØ˜T %™[Ñ(¨4Ñ/Ó/Ø�D‰jÖr%   r   F)Útotalc            &       óÔ  ^ • \ rS rSr\R
                  r\r\	r
SS0rSrSSS.rSrSrSrSrSrSSS.rSrS	rSrSr\rS
\\   4U 4S jjr\S\\\   -  \\\      -  S
\\   S\4U 4S jj5       r S\S\4S jr!  S+SSS\"SSS\#SS4
U 4S jjjr$S,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(\#S-  S\4&S) jr)S*r*U =r+$ )-ÚTvpImageProcessoré1   Úlongest_edgeiÀ  F©ÚheightÚwidthTgp?r   ÚconstantÚkwargsc                 ó&   >• [         TU ]  " S0 UD6  g )Nr   )ÚsuperÚ__init__)Úselfr0   Ú	__class__s     €r&   r3   ÚTvpImageProcessor.__init__E   s   ø€ Ü‰ÒÑ"˜6Ó"r%   ÚvideosÚreturnc                 ó&   >• [         TU ]  " U40 UD6$ )zd
videos (`ImageInput` or `list[ImageInput]` or `list[list[ImageInput]]`):
    Frames to preprocess.
)r2   Ú
preprocess)r4   r7   r0   r5   s      €r&   r:   ÚTvpImageProcessor.preprocessH   s   ø€ ô ‰wÒ! &Ñ3¨FÑ3Ð3r%   Úimagesc                 ó<   • U R                  U5      n[        U40 UD6$ )z²
Prepare the images structure for processing.

Args:
    images (`ImageInput`):
        The input images to process.

Returns:
    `ImageInput`: The images with a valid nesting.
)Úfetch_imagesr   )r4   r<   r0   s      r&   Ú_prepare_images_structureÚ+TvpImageProcessor._prepare_images_structureT   s$   € ð ×"Ñ" 6Ó*ˆÜ)¨&Ñ;°FÑ;Ð;r%   NÚimageútorch.TensorÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚ	antialiasc                 ó*  >• UR                   (       ao  UR                  SS u  pgXg:¼  a"  US-  U-  nUR                   n	[        X˜-  5      n
O!US-  U-  nUR                   n
[        X¨-  5      n	[        TU ]  U[        XšS9X4S9$ [        TU ]  " X4X4S.UD6$ )a  
Resize an image to the specified size.

Args:
    image (`torch.Tensor`):
        Image to resize.
    size (`SizeDict`):
        Size dictionary. If `size` has `longest_edge`, resize the longest edge to that value
        while maintaining aspect ratio. Otherwise, use the base class resize method.
    resample (`tvF.InterpolationMode`, *optional*):
        Interpolation method to use.
    antialias (`bool`, *optional*, defaults to `True`):
        Whether to use antialiasing.

Returns:
    `torch.Tensor`: The resized image.
éþÿÿÿNg      ð?r,   )rD   rE   )r+   ÚshapeÚintr2   Úresizer   )r4   rA   rC   rD   rE   r0   Úcurrent_heightÚcurrent_widthÚratioÚ
new_heightÚ	new_widthr5   s              €r&   rJ   ÚTvpImageProcessor.resizef   sµ   ø€ ð6 ××à,1¯K©K¸¸Ð,<Ñ)ˆNð Ó.Ø%¨Ñ+¨nÑ<�Ø!×.Ñ.�
Ü 
Ñ 2Ó3‘	à&¨Ñ,¨}Ñ<�Ø ×-Ñ-�	Ü  Ñ!2Ó3�
ä‘7‘>Ø”x zÑCÈhð "ð ð ô
 ‰wŠ~˜eÐ\°HÑ\ÐU[Ñ\Ð\r%   c                 ó(   • UR                  S5      nU$ )a5  
Flip channel order from RGB to BGR.

The slow processor puts the red channel at the end (BGR format),
but the channel order is different. We need to match the exact
channel order of the slow processor:

Slow processor:
- Channel 0: Blue (originally Red)
- Channel 1: Green
- Channel 2: Red (originally Blue)
éýÿÿÿ)Úflip)r4   Úframess     r&   Ú_flip_channel_orderÚ%TvpImageProcessor._flip_channel_order–   s   € ð —‘˜R“ˆàˆr%   Ú	do_resizeÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_padÚpad_sizer   r   Údo_normalizeÚ
image_meanÚ	image_stdr   Úreturn_tensorsÚdisable_groupingc           	      ó.  • [        UUSS9u  nn0 nUR                  5        H–  u  nnU(       a  U R                  UX45      nU(       a  U R                  UU5      nU R	                  UXxXÞU5      nU	(       a&  U R                  UX«US9n[        R                  " USS9nU(       a  U R                  U5      nUUU'   M˜     [        UUSS9nUS:X  a:  U Vs/ s H  n[        R                  " USS9PM     nn[        R                  " USS9n[        SU0US	9$ s  snf )
zÑ
Preprocess videos using the fast image processor.

This method processes each video frame through the same pipeline as the original
TVP image processor but uses torchvision operations for better performance.
T)rb   Ú	is_nested)Ú
fill_valuer   r   )Údim)rd   ÚptÚpixel_values)ÚdataÚtensor_type)r   ÚitemsrJ   Úcenter_cropÚrescale_and_normalizeÚpadÚtorchÚstackrU   r   r   )r4   r<   rW   rC   rD   rX   rY   rZ   r[   r\   r]   r   r   r^   r_   r`   r   ra   rb   r0   Úgrouped_imagesÚgrouped_images_indexÚprocessed_images_groupedrH   Ústacked_framesÚprocessed_imagess                             r&   Ú_preprocessÚTvpImageProcessor._preprocess¨   s7  € ô8 0EØÐ%5Àñ0
Ñ,ˆÐ,ð $&Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆE�>æØ!%§¡¨^¸TÓ!L�ö Ø!%×!1Ñ!1°.À)Ó!L�ð "×7Ñ7Ø 
¸LÐV_óˆNö
 Ø!%§¡¨.¸(Ðiq Ð!r�Ü!&§¢¨^ÀÑ!C�ö %Ø!%×!9Ñ!9¸.Ó!I�à.<Ð$ UÓ+ñ/ &<ô2 *Ð*BÐDXÐdhÑiÐØ˜TÓ!ÙIYÓZÒIY¸v¤§¢¨F¸Ô :ÑIYÐÐZÜ$Ÿ{š{Ð+;ÀÑCÐä .Ð2BÐ!CÐQ_Ñ`Ð`ùò  [s   ÃDr   )NT)rT   rB   r8   rB   ),r   r   r   r   r   ÚBILINEARrD   r	   r_   r
   r`   rC   Údefault_to_squarerY   rW   rX   rZ   r[   r\   r]   r   r   r^   r   r   Úvalid_kwargsr   r3   r   r   r"   r   r:   r?   r   r   rJ   rU   r!   r#   r   rv   r$   Ú__classcell__)r5   s   @r&   r)   r)   1   sR  ø† à!×*Ñ*€HØ'€JØ%€IØ˜CÐ €DØÐØ¨Ñ-€IØ€IØ€NØ€JØ€NØ€FØ¨Ñ,€HØ€OØ€HØ€LØ ÐØ*€Lð# Ð(?Ñ!@÷ #ð ð	4à˜T *Ñ-Ñ-°°T¸*Ñ5EÑ0FÑFð	4ð Ð0Ñ1ð	4ð 
ö		4ó ð	4ð<àð<ð 
ô	<ð, OSØñ.]àð.]ð ð.]ð Lð	.]ð
 ð.]ð 
÷.]ð .]ô`ð$>aà�T˜.Ñ)Ñ*ð>að ð>að ð	>að
 Lð>að ð>að ð>að ð>að ð>að ð>að ð>að   e¡Ñ,ð>að ð>að ð>að ˜D ™KÑ'¨$Ñ.ð>að  ˜4 ™;Ñ&¨Ñ-ð!>að"  $ð#>að$ ˜jÑ(¨4Ñ/ð%>að&  ™+ð'>að* 
÷+>aò >ar%   r)   )r   ro   Útorchvision.transforms.v2r   ÚtvFÚimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr   r   Úimage_utilsr	   r
   r   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   r)   Ú__all__r   r%   r&   Ú<module>r…      sf   ðñ %ã Ý 7å ;Ý 2ß E÷÷ ÷ 5ß /ô˜l°%ò ð ôtaÐ*ó taó ðtaðn Ð
�r%   