+
    œ°³jy@  ã                   ó¶   € R t ^RIHt ^RIHtHtHt ^RIHtH	t	 ^RI
Ht ]! 4       '       d   ^ RIt^ RIHu Ht RR R lltRR R	 llt ! R
 R]4      tR.tR# )z"Video processor class for Videomt.)Ú'SemanticSegmentationPostProcessorOutput)ÚIMAGENET_DEFAULT_MEANÚIMAGENET_DEFAULT_STDÚPILImageResampling)Úis_torch_availableÚrequires_backends)ÚBaseVideoProcessorNc                ój   € V ^8„  d   QhRRRRR\         R\        R\        R\        \        R3,          /# )é   Úmask_labelsútorch.TensorÚ
mask_probsÚ	query_idxÚmask_thresholdÚoverlap_mask_area_thresholdÚreturn)ÚintÚfloatÚtupleÚbool)Úformats   "Úu/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/videomt/video_processing_videomt.pyÚ__annotate__r      sN   € ÷ *#ñ *#Øð*#àð*#ô ð*#ô ð	*#ô
 "'ð*#ô Œ4�ÐÕ ñ*#ó    c                ó"  € W8H  pVP                  4       pW,          V8¬  pVP                  4       pWW,          p	V	P                  4       p
V^ 8„  ;'       d    V^ 8„  ;'       d    V
^ 8„  pV'       d    Wh,          pVP                  4       V8”  g   RpW¹3# )aD  
Checks whether a predicted query produces a valid panoptic segment.

Args:
    mask_labels (`torch.Tensor`):
        Tensor of shape `(height, width)` containing the winning query index for each pixel.
    mask_probs (`torch.Tensor`):
        Tensor of shape `(num_queries, height, width)` containing per-query mask probabilities.
    query_idx (`int`):
        Index of the query to validate.
    mask_threshold (`float`, *optional*, defaults to 0.5):
        Threshold used to binarize the query mask probabilities.
    overlap_mask_area_threshold (`float`, *optional*, defaults to 0.8):
        Minimum overlap ratio required between the assigned query area and the original query mask area.

Returns:
    `tuple[bool, torch.Tensor]`: A tuple containing whether the segment is valid and the final boolean mask for
    that segment.
F)ÚsumÚitem)r   r   r   r   r   Ú
query_maskÚquery_mask_areaÚoriginal_maskÚoriginal_areaÚ
final_maskÚfinal_mask_areaÚmask_existsÚ
area_ratios   &&&&&        r   Úcheck_segment_validityr%      s•   € ð4 Ñ)€JØ —n‘nÓ&€OàÕ)¨^Ñ;€MØ!×%Ñ%Ó'€MàÕ+€JØ —n‘nÓ&€Oà! AÑ%×SÐS¨-¸!Ñ*;×SÐSÀÐRSÑ@S€KçØ$Õ4ˆ
Ø�‰Ó Ð#>Ô>ØˆKàÐ"Ð"r   c                ó  € V ^8„  d   QhRRRRRRR\         \        ,          R,          R\        R\        R	\        \        \        3,          R,          R
\        R\        \
        \        \        \        ,          3,          ,          3,          /# )r
   r   r   Úpred_scoresÚpred_labelsÚlabel_ids_to_fuseNr   r   Útarget_sizer   )Úsetr   r   r   ÚlistÚdictÚstr)r   s   "r   r   r   H   s”   € ÷ G"ñ G"ØðG"àðG"ð  ðG"ô œ3•x $•ð	G"ô
 ðG"ô "'ðG"ô ”sœC�x• 4Õ'ðG"ô ˆ>œ4¤¤S¬#´­+Ð%5Õ 6Õ7Ð7Õ8ñG"r   c           	     óÜ  € Vf   V P                   ^,          MV^ ,          pVf   V P                   ^,          MV^,          p\        P                  ! Wx3\        P                  V P                  R7      ^,
          p	. p
V P                  4       p VR,          V ,          P                  ^ 4      p^ p/ p\        VP                   ^ ,          4       Fœ  pW.,          P                  4       p\        W°WäV4      w  ppV'       g   K3  V'       d   Wó9   d   Wý9   d   Wß,          V	V&   KT  WÍV&   WÉV&   \        W,          P                  4       ^4      pV
P                  RVRVRV/4       V^,          pKž  	  Wš3# )aq  
Converts per-query mask predictions into a panoptic segmentation map.

Args:
    mask_probs (`torch.Tensor`):
        Tensor of shape `(num_queries, height, width)` containing per-query mask logits.
    pred_scores (`torch.Tensor`):
        Tensor of shape `(num_queries,)` containing the confidence score of each predicted query.
    pred_labels (`torch.Tensor`):
        Tensor of shape `(num_queries,)` containing the predicted class ID of each query.
    label_ids_to_fuse (`set[int]`, *optional*):
        Label IDs that should be fused across disconnected regions.
    mask_threshold (`float`, *optional*, defaults to 0.5):
        Threshold used to binarize the query mask probabilities.
    overlap_mask_area_threshold (`float`, *optional*, defaults to 0.8):
        Minimum overlap ratio required to keep a predicted segment.
    target_size (`tuple[int, int]`, *optional*):
        Final `(height, width)` of the segmentation map. If unset, uses the spatial size of `mask_probs`.

Returns:
    `tuple[torch.Tensor, list[dict[str, int | float]]]`: The panoptic segmentation map and the metadata for each
    predicted segment.
)ÚdtypeÚdeviceÚidÚlabel_idÚscore):NNNNN)ÚshapeÚtorchÚzerosÚlongr1   ÚsigmoidÚargmaxÚranger   r%   ÚroundÚappend)r   r'   r(   r)   r   r   r*   ÚheightÚwidthÚsegmentationÚsegmentsr   Úcurrent_segment_idÚstuff_memory_listr   Ú
pred_classr#   r!   Úsegment_scores   &&&&&&&            r   Úcompute_segmentsrF   H   sa  € ð@ %0Ò$7ˆZ×Ñ˜aÖ ¸[È½^€FØ#.Ò#6ˆJ×Ñ˜QÖ¸KÈ½N€Eä—;’; ˜´e·j±jÈ×IZÑIZÔ[Ð^_Õ_€LØ€Hà×#Ñ#Ó%€JØ˜}Õ-°
Õ:×BÑBÀ1ÓE€KàÐØ(*Ðä˜;×,Ñ,¨QÕ/Ö0ˆ	Ø Õ+×0Ñ0Ó2ˆ
ä"8Ø YÐ@[ó#
Ñˆ�Z÷ Ùç Ô!@ØÔ.Ø+<Õ+H�˜ZÑ(Ùà0B *Ñ-à#5�ZÑ Ü˜kÕ4×9Ñ9Ó;¸QÓ?ˆØ�‰àÐ(Ø˜JØ˜ðô	
ð 	˜aÕÒñ5 1ð6 Ð!Ð!r   c                   óÂ   a € ] tR t^’t o ]P
                  t]t]	t
RRRR/tRtRtRtRtRtRtRtR.tV 3R lR ltRV 3R	 lR
 lltRV 3R lR lltRV 3R lR lltRtV tR# )ÚVideomtVideoProcessorr>   i€  r?   TFÚpixel_values_videosc                ó^   <€ V ^8„  d   QhRRRS[ S[S[S[3,          ,          RS[ R,          /# )r
   Úmasks_queries_logitsr   Útarget_sizesr   )r,   r   r   )r   Ú__classdict__s   "€r   r   Ú"VideomtVideoProcessor.__annotate__    s;   ø€ ÷ ñ à,ðñ ™5¡¡c �?Õ+ðñ 
ˆnÕ	ñ	r   c                ó°   € . p\        V4       FD  w  rE\        P                  ! W,          R,          VRRR7      ^ ,          pVP                  V4       KF  	  V# )z=Interpolates mask logits to each frame's original resolution.ÚbilinearF)ÚsizeÚmodeÚalign_corners)N.)Ú	enumerateÚFÚinterpolater=   )ÚselfrK   rL   ÚresizedÚidxÚoriginal_sizeÚ	upsampleds   &&&    r   Ú_resize_mask_logitsÚ)VideomtVideoProcessor._resize_mask_logits    s\   € ð ˆÜ"+¨LÖ"9ÑˆCÜŸšØ$Õ)¨)Õ4Ø"ØØ#ô	ð
 õˆIð �N‰N˜9Ö%ñ #:ð ˆr   c                óP   <€ V ^8„  d   QhRS[ S[S[S[3,          ,          RS[RR/# )r
   rL   Úreturn_segmentation_scoresr   zBlist[torch.Tensor] | list[SemanticSegmentationPostProcessorOutput])r,   r   r   r   )r   rM   s   "€r   r   rN   ±   s9   ø€ ÷ 6%ñ 6%ñ ™5¡¡c �?Õ+ð6%ñ %)ð	6%ð
 
Nñ6%r   c           
     óÖ  € \        V R.4       VP                  pVP                  pVP                  4       P	                  RR7      RRR13,          pVP                  4       P                  4       p\        P                  ! VP                  ^^4      VP                  ^4      4      pVP                  VP                  ^ ,          VP                  R,          VP                  R	,          VP                  R,          4      pV P                  W‚4      p	V	 U
u. uF#  p
\        RV
P                  ^ R7      RV
/R7      NK%  	  pp
V'       g   V Uu. uF  qÌP                  NK  	  ppV# u up
i u upi )
aQ  
Converts the output of [`VideomtForUniversalSegmentation`] into semantic segmentation predictions.

Args:
    outputs ([`VideomtForUniversalSegmentationOutput`]):
        Raw outputs of the model.
    target_sizes (`list[tuple[int, int]]`):
        List of `(height, width)` tuples corresponding to the requested final size of each prediction.
        Length should match the number of frames in the output.
    return_segmentation_scores (`bool`, *optional*, defaults to `False`):
        Whether to return segmentation scores alongside the segmentation map. When `True`, each element of
        the returned list is a [`SemanticSegmentationPostProcessorOutput`] with fields `segmentation`
        (class IDs, shape `(height, width)`) and `segmentation_scores` (shape `(num_classes, height, width)`).

Returns:
    `list[torch.Tensor]` or `list[SemanticSegmentationPostProcessorOutput]`: When
    `return_segmentation_scores=False` (default), a list of length `batch_size` where each item is a
    segmentation map of shape `(height, width)` with class IDs. When `return_segmentation_scores=True`,
    a list of [`SemanticSegmentationPostProcessorOutput`] with fields `segmentation` (class IDs, shape
    `(height, width)`) and `segmentation_scores` (shape `(num_classes, height, width)`). In both cases,
    `(height, width)` corresponds to the target size.
r6   ©Údim.Nr@   Úsegmentation_scores)Údataéÿÿÿÿéþÿÿÿ)r   rK   Úclass_queries_logitsr   Úsoftmaxr9   r6   ÚmatmulÚ	transposeÚflattenÚreshaper5   r\   r   r:   r@   )rW   ÚoutputsrL   r_   rK   rg   Úmasks_classesÚmasks_probsÚsegmentation_logitsÚoutput_logitsÚlogitÚsemantic_segmentationr   s   &&&&         r   Ú"post_process_semantic_segmentationÚ8VideomtVideoProcessor.post_process_semantic_segmentation±   sd  € ô8 	˜$  	Ô*à&×;Ñ;ÐØ&×;Ñ;Ðð -×2Ñ2Ó4×<Ñ<ÀÐ<ÓDÀSÈ#È2È#ÀXÕNˆØ*×0Ñ0Ó2×:Ñ:Ó<ˆä#Ÿlšl¨=×+BÑ+BÀ1ÀaÓ+HÈ+×J]ÑJ]Ð^_ÓJ`ÓaÐØ1×9Ñ9Ø×Ñ˜aÕ  -×"5Ñ"5°bÕ"9¸;×;LÑ;LÈRÕ;PÐR]×RcÑRcÐdfÕRgó
Ðð ×0Ñ0Ð1DÓSˆñ 'ó	!
ñ '�ô 4Ø$ e§l¡l°q lÓ&9Ð;PÐRWÐX÷ñ 'ð	 	ð !
÷ *ÙCXÓ$YÑCX¸4×%6Ô%6ÑCXÐ!Ð$Yà$Ð$ùò!
ùò %Zs   Ä)E!Å	E&c                ób   <€ V ^8„  d   QhRS[ S[S[S[3,          ,          RS[RS[ S[,          /# )r
   rL   Ú	thresholdr   )r,   r   r   r   r-   )r   rM   s   "€r   r   rN   é   sA   ø€ ÷ Eñ Eñ ™5¡¡c �?Õ+ðEñ ð	Eñ
 
‰d�ñEr   c                óŽ  € \        V R.4       VP                  pVP                  pV P                  WR4      pVP                  pVP
                  ^ ,          pVP
                  R,          p	. p
\        V4       EFÊ  pWk,          pWK,          pVP                  4       P                  RR7      RRR13,          pVP                  R4      w  ppV^ 8„  pVP                  4       P                  4       pVP                  ^4      VP                  ^4      ,          P                  ^4      VP                  ^4      P                  ^4      R,           ,          pVV,          p\        P                  ! W+,          R\        P                  VR7      p. p^ p\        V	4       F“  pVV,          P!                  4       p\        P"                  ! VV,          4      '       g   K?  VV8¼  g   KH  VVVV,          &   VP%                  RVRVV,          P!                  4       R	\'        V^4      /4       V^,          pK•  	  V
P%                  R
VRV/4       EKÍ  	  V
# )a0  
Converts the output of [`VideomtForUniversalSegmentation`] into instance segmentation predictions.

Args:
    outputs ([`VideomtForUniversalSegmentationOutput`]):
        Raw outputs of the model.
    target_sizes (`list[tuple[int, int]]`):
        List of `(height, width)` tuples corresponding to the requested final size of each prediction.
        Length should match the number of frames in the output.
    threshold (`float`, *optional*, defaults to 0.5):
        Minimum combined score to keep an instance.

Returns:
    `list[dict]`: A list of dicts (one per frame), each containing:
        - `"segmentation"` -- A `torch.Tensor` of shape `(height, width)` with instance IDs (or -1 for background).
        - `"segments_info"` -- A list of dicts with `"id"`, `"label_id"`, and `"score"` for each instance.
r6   ra   .Ng�íµ ÷Æ°>©Ú
fill_valuer0   r1   r2   r3   r4   r@   Úsegments_inforf   re   )r   rg   rK   r\   r1   r5   r;   r   rh   Úmaxr9   rk   r   r6   Úfullr8   r   Úanyr=   r<   )rW   rm   rL   rw   rg   rK   Úmask_probs_batchr1   Ú
num_framesÚnum_queriesÚresultsÚ	frame_idxÚ	mask_predÚ
mask_classÚclass_probsÚscoresÚpred_classesÚ
pred_masksr   Úmask_scoresr'   r@   rA   rB   r   r4   s   &&&&                      r   Ú"post_process_instance_segmentationÚ8VideomtVideoProcessor.post_process_instance_segmentationé   s  € ô. 	˜$  	Ô*à&×;Ñ;ÐØ&×;Ñ;Ðà×3Ñ3Ð4HÓWÐà%×,Ñ,ˆØ)×/Ñ/°Õ2ˆ
Ø*×0Ñ0°Õ4ˆàˆä˜z×*ˆIØ(Õ3ˆIØ-Õ8ˆJà$×*Ñ*Ó,×4Ñ4¸Ð4Ó<¸SÀ#À2À#¸XÕFˆKØ#.§?¡?°2Ó#6Ñ ˆF�LØ" Q™ˆJà"Ÿ™Ó*×2Ñ2Ó4ˆJØ%×-Ñ-¨aÓ0°:×3EÑ3EÀaÓ3HÕH×MÑMÈaÓPØ×"Ñ" 1Ó%×)Ñ)¨!Ó,¨tÕ3õˆKð ! ;Õ.ˆKä Ÿ:š: lÕ&=È"ÔTY×T^ÑT^ÐgmÔnˆLàˆHØ!"ÐÜ" ;Ö/�	Ø# IÕ.×3Ñ3Ó5�ä—9’9˜Z¨	Õ2×3Ô3¸ÀÖ8JØ:L�L ¨IÕ!6Ñ7Ø—O‘Oà Ð"4Ø&¨°YÕ(?×(DÑ(DÓ(FØ#¤U¨5°!£_ðôð '¨!Õ+Ò&ñ 0ð �N‰N˜N¨L¸/È8ÐT×UñA +ðB ˆr   Nc                ó’   <€ V ^8„  d   QhRS[ S[S[S[3,          ,          RS[RS[RS[RS[S[,          R,          RS[ S[,          /# )r
   rL   rw   r   r   r)   Nr   )r,   r   r   r   r+   r-   )r   rM   s   "€r   r   rN   0  sj   ø€ ÷ Mñ Mñ ™5¡¡c �?Õ+ðMñ ð	Mñ
 ðMñ &+ðMñ ™s�8 d�?ðMñ 
‰d�ñMr   c                ó  € \        V R.4       VP                  pVP                  pVP                  ^ ,          p	VP                  R
,          ^,
          p
V P	                  Wr4      pVP                  4       P                  R
R7      P                  R
4      w  rÍ. p\        V	4       EF]  pW¿,          pWÏ,          pWß,          pVP                  ^ ,          VP                  ^ ,          u;8X  d   VP                  ^ ,          8X  g   M \        R4      hVP                  V
4      VV8„  ,          pVV,          pVV,          pVV,          pVP                  ^ ,          ^ 8:  do   Ve	   W/,          MVP                  R,          w  pp\        P                  ! VV3R
\        P                  VP                  R7      pVP                  RVR. /4       EK'  \!        TTTTTTVe	   W/,          MRR	7      w  ppVP                  RVRV/4       EK`  	  V# )a™  
Converts the output of [`VideomtForUniversalSegmentation`] into panoptic segmentation predictions.

Args:
    outputs ([`VideomtForUniversalSegmentationOutput`]):
        Raw outputs of the model.
    target_sizes (`list[tuple[int, int]]`):
        List of `(height, width)` tuples corresponding to the requested final size of each prediction.
        Length should match the number of frames in the output.
    threshold (`float`, *optional*, defaults to 0.8):
        Minimum score to keep a predicted segment.
    mask_threshold (`float`, *optional*, defaults to 0.5):
        Threshold for binarizing mask probabilities.
    overlap_mask_area_threshold (`float`, *optional*, defaults to 0.8):
        Overlap threshold to merge masks into a single segment.
    label_ids_to_fuse (`set[int]`, *optional*):
        Label IDs that should be fused across disconnected regions.

Returns:
    `list[dict]`: A list of dicts (one per frame), each containing:
        - `"segmentation"` -- A `torch.Tensor` of shape `(height, width)` with segment IDs (or -1 for background).
        - `"segments_info"` -- A list of dicts with `"id"`, `"label_id"`, and `"score"` for each segment.
r6   ra   z1mask, scores and labels must have the same shape!N:é   NNry   r@   r{   )r   r'   r(   r)   r   r   r*   re   )r   rK   rg   r5   r\   r   rh   r|   r;   Ú
ValueErrorÚner6   r}   r8   r1   r=   rF   )rW   rm   rL   rw   r   r   r)   rK   rg   r€   Ú
num_labelsr   Úpred_scores_batchÚpred_labels_batchr‚   rƒ   r   r'   r(   Úto_keepr>   r?   r@   rA   s   &&&&&&&                 r   Ú"post_process_panoptic_segmentationÚ8VideomtVideoProcessor.post_process_panoptic_segmentation0  së  € ô@ 	˜$  	Ô*à&×;Ñ;ÐØ&×;Ñ;Ðà)×/Ñ/°Õ2ˆ
Ø)×/Ñ/°Õ3°aÕ7ˆ
à×3Ñ3Ð4HÓWÐØ/C×/IÑ/IÓ/K×/SÑ/SÐXZÐ/SÓ/[×/_Ñ/_Ð`bÓ/cÑ,Ðàˆä˜z×*ˆIØ)Õ4ˆJØ+Õ6ˆKØ+Õ6ˆKà×$Ñ$ QÕ'¨;×+<Ñ+<¸QÕ+?ÖWÀ;×CTÑCTÐUVÕCWÖWÜ Ð!TÓUÐUà!—n‘n ZÓ0°KÀ)Ñ4KÕLˆGØ# GÕ,ˆJØ% gÕ.ˆKØ% gÕ.ˆKà×Ñ Õ" aÔ'Ø;GÒ;S Ö 7ÐYc×YiÑYiÐjlÕYm‘�˜Ü$ŸzšzØ˜U�O°¼%¿*¹*ÐMa×MhÑMhô �ð —‘ °¸oÈrÐRÔSÚä%5Ø%Ø'Ø'Ø"3Ø-Ø,GØ7CÒ7O˜LÖ3ÐUYô&Ñ"ˆL˜(ð �N‰N˜N¨L¸/È8ÐT×Uñ? +ð@ ˆr   © gp?)F)ç      à?)çš™™™™™é?r™   rš   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   ÚBILINEARÚresampler   Ú
image_meanr   Ú	image_stdrQ   Ú	do_resizeÚdo_center_cropÚ
do_rescaleÚrescale_factorÚdo_normalizeÚdo_convert_rgbÚdo_sample_framesÚmodel_input_namesr\   rt   r‹   r–   Ú__static_attributes__Ú__classdictcell__)rM   s   @r   rH   rH   ’   s‰   ø‡ € Ø!×*Ñ*€HØ&€JØ$€IØ�c˜7 CÐ(€DØ€IØ€NØ€JØ€NØ€LØ€NØÐØ.Ð/Ð÷ð ÷"6%ò 6%÷pEò E÷NM÷ Mð Mr   rH   )r™   rš   )r™   rš   N)Ú__doc__Úimage_processing_outputsr   Úimage_utilsr   r   r   Úutilsr   r   Úvideo_processing_utilsr   r6   Útorch.nn.functionalÚnnÚ
functionalrU   r%   rF   rH   Ú__all__r˜   r   r   Ú<module>r¶      sT   ðñ )å Oß ZÑ Zß :Ý 8ñ ×ÒÛß#Ð#÷*#÷ZG"ôTkÐ.ô kð\ #Ð
#‚r   