
    Z j6!                         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       }/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/tvp/image_processing_tvp.pyr   r   "   s-      T%[(4//Dj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+$ )-TvpImageProcessor1   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!&3F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[        XS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 ,1KK,<)N .%+n<!..

 23	&,}< --	 !23
7>xzCh "  
 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XxXU5      nU	(       a&  U R                  UXU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
LV_N
 !%.(iq!r!&^!C %!%!9!9.!I.<$U+/ &<2 **BDXdhiT!IYZIYvF :IYZ${{+;C.2B!CQ_``  [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*5E0F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%   