§
    9²¸jÝ  ã                   óÌ   — d Z ddlZddlmc mc mZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZ ddlmZ ddlmZ dd	lmZmZmZ  G d
„ ded¬¦  «        Z G d„ de¦  «        ZdgZdS )z(Fast Video processor class for InternVL.é    Né   )ÚBatchFeature)ÚOPENAI_CLIP_MEANÚOPENAI_CLIP_STDÚPILImageResamplingÚSizeDict)ÚUnpackÚVideosKwargs)Ú
TensorType)ÚBaseVideoProcessor)ÚVideoMetadataÚgroup_videos_by_shapeÚreorder_videosc                   ó&   — e Zd ZU eez  ez  ed<   dS )Ú InternVLVideoProcessorInitKwargsÚinitial_shiftN)Ú__name__Ú
__module__Ú__qualname__ÚboolÚfloatÚintÚ__annotations__© ó    ú†/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/transformers/models/internvl/video_processing_internvl.pyr   r      s'   € € € € € € Ø˜%‘< #Ñ%Ð%Ð%Ñ%Ð%Ð%r   r   F)Útotalc                   ó<  ‡ — e Zd Zej        ZeZeZ	dddœZ
dZdZdZdZdZdZeZdee         fˆ fd„Z	 	 	 dded	edz  d
eez  dz  deez  ez  dz  fd„Z	 dded         dedededddedededededeee         z  dz  deee         z  dz  deez  dz  defd„Zˆ xZ S ) ÚInternVLVideoProcessori€  )ÚheightÚwidthTFÚkwargsc                 ó:   •—  t          ¦   «         j        di |¤Ž d S )Nr   )ÚsuperÚ__init__)Úselfr"   Ú	__class__s     €r   r%   zInternVLVideoProcessor.__init__,   s&   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ð"Ð"r   NÚmetadataÚ
num_framesÚfpsr   c                 óR  — |�|n| j         }|�|n| j        }|j        }|€4|�2|�|j        €t	          d¦  «        ‚t          ||j        z  |z  ¦  «        }|du r||z  dz  }||k    rt	          d|› d|› d�¦  «        ‚t          j        ||||z  ¦  «                             ¦   «         }|S )a  
        Default sampling function which uniformly samples the desired number of frames between 0 and total number of frames.
        If `fps` is passed along with metadata, `fps` frames per second are sampled uniformly. Arguments `num_frames`
        and `fps` are mutually exclusive.

        Args:
            metadata (`VideoMetadata`):
                Metadata of the video containing information about total duration, fps and total number of frames.
            num_frames (`int`, *optional*):
                Maximum number of frames to sample. Defaults to `self.num_frames`.
            fps (`int` or `float`, *optional*):
                Target frames to sample per second. Defaults to `self.fps`.
            initial_shift (`bool`, `float` or `int`, defaults to `self.initial_shift`):
                The initial shift to apply when sampling frames. If `True`, the shift is set so that frames are sampled from the middle of the video.

        Returns:
            np.ndarray:
                Indices to sample video frames.
        NzÈAsked to sample `fps` frames per second but no video metadata was provided which is required when sampling with `fps`. Please pass in `VideoMetadata` object or use a fixed `num_frames` per input videoTé   z(Video can't be sampled. The `num_frames=z` exceeds `total_num_frames=z`. )r)   r   Útotal_num_framesr*   Ú
ValueErrorr   ÚtorchÚarange)r&   r(   r)   r*   r   r"   r-   Úindicess           r   Úsample_framesz$InternVLVideoProcessor.sample_frames/   sø   € ð6 $.Ð#9�Z�Z¸t¼ˆ
Ø)6Ð)B˜˜ÈÔHZˆØ#Ô4Ðð Ð # /ØÐ 8¤<Ð#7Ý ðhñô ð õ Ð-°´Ñ<¸sÑBÑCÔCˆJà˜DÐ Ð Ø,¨zÑ9¸AÑ=ˆMàÐ(Ò(Ð(ÝØx¸:ÐxÐxÐcsÐxÐxÐxñô ð õ ”,˜}Ð.>Ð@PÐS]Ñ@]Ñ^Ô^×bÒbÑdÔdˆØˆr   Úvideosztorch.TensorÚdo_convert_rgbÚ	do_resizeÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚreturn_tensorsÚreturnc           	      óú  — t          |¦  «        \  }}i }|                     ¦   «         D ];\  }}|r|                      |¦  «        }|r|                      |||¬¦  «        }|||<   Œ<t	          ||¦  «        }t          |¦  «        \  }}i }|                     ¦   «         D ]<\  }}|r|                      ||¦  «        }|                      |||	|
||¦  «        }|||<   Œ=t	          ||¦  «        }t          d|i|¬¦  «        S )N)r6   r7   Úpixel_values_videos)ÚdataÚtensor_type)r   ÚitemsÚconvert_to_rgbÚresizer   Úcenter_cropÚrescale_and_normalizer   )r&   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r"   Úgrouped_videosÚgrouped_videos_indexÚresized_videos_groupedÚshapeÚstacked_videosÚresized_videosÚprocessed_videos_groupedÚprocessed_videoss                          r   Ú_preprocessz"InternVLVideoProcessor._preprocessb   sT  € õ$ 0EÀVÑ/LÔ/LÑ,ˆÐ,Ø!#ÐØ%3×%9Ò%9Ñ%;Ô%;ð 	;ð 	;Ñ!ˆE�>Øð EØ!%×!4Ò!4°^Ñ!DÔ!D�Øð [Ø!%§¢¨^À$ÐQY Ñ!ZÔ!Z�Ø,:Ð" 5Ñ)Ð)Ý'Ð(>Ð@TÑUÔUˆõ 0EÀ^Ñ/TÔ/TÑ,ˆÐ,Ø#%Ð Ø%3×%9Ò%9Ñ%;Ô%;ð 	=ð 	=Ñ!ˆE�>Øð MØ!%×!1Ò!1°.À)Ñ!LÔ!L�à!×7Ò7Ø 
¨N¸LÈ*ÐV_ñô ˆNð /=Ð$ UÑ+Ð+å)Ð*BÐDXÑYÔYÐåÐ"7Ð9IÐ!JÐXfÐgÑgÔgÐgr   )NNN)N)!r   r   r   r   ÚBICUBICr7   r   r=   r   r>   r6   r5   r:   r<   r4   r   Údo_sample_framesr   Úvalid_kwargsr	   r%   r   r   r   r   r2   Úlistr   Ústrr   r   rR   Ú__classcell__)r'   s   @r   r   r      sÞ  ø€ € € € € Ø!Ô)€HØ!€JØ€IØ CÐ(Ð(€DØ€IØ€JØ€LØ€NØ€MØÐØ3€Lð# Ð(HÔ!Ið #ð #ð #ð #ð #ð #ð "&Ø"&Ø37ð1ð 1àð1ð ˜$‘Jð1ð �5‰[˜4Ñð	1ð
 ˜e‘| cÑ)¨DÑ0ð1ð 1ð 1ð 1ðB 37ð+hð +hà�^Ô$ð+hð ð+hð ð	+hð
 ð+hð Lð+hð ð+hð ð+hð ð+hð ð+hð ð+hð ˜D œKÑ'¨$Ñ.ð+hð ˜4 œ;Ñ&¨Ñ-ð+hð ˜jÑ(¨4Ñ/ð+hð  
ð!+hð +hð +hð +hð +hð +hð +hð +hr   r   )Ú__doc__r/   Ú$torchvision.transforms.v2.functionalÚ
transformsÚv2Ú
functionalÚtvFÚimage_processing_utilsr   Úimage_utilsr   r   r   r   Úprocessing_utilsr	   r
   Úutilsr   Úvideo_processing_utilsr   Úvideo_utilsr   r   r   r   r   Ú__all__r   r   r   ú<module>rf      sE  ðð /Ð .à €€€Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2à 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZØ 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø Ð Ð Ð Ð Ð Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ Oð&ð &ð &ð &ð & |¸5ð &ñ &ô &ð &ðnhð nhð nhð nhð nhÐ/ñ nhô nhð nhðb $Ð
$€€€r   