+
    œ°³jmp  ã                   ó  € R t ^ RIHt ^ RIt^RIHt ^RIHt ^RI	H
t
HtHt ^RIHtHtHtHt ^RIHt ]P(                  ! ]4      t]! 4       '       d   ^ RItR tR	 tR
 tR tR tR tR t]! RR7      ] ! R R]4      4       4       tR.t R# )z
Processor class for SAM3.
)ÚdeepcopyN)Ú
ImageInput)ÚProcessorMixin)ÚBatchEncodingÚPreTokenizedInputÚ	TextInput)Ú
TensorTypeÚauto_docstringÚis_torch_availableÚlogging)Úrequiresc                 óÖ   € V P                  R4      w  rr4VRV,          ,
          VRV,          ,
          VRV,          ,           VRV,          ,           .p\        P                  ! VRR7      # ©é   ç      à?©Údiméÿÿÿÿ©ÚunbindÚtorchÚstack©ÚxÚx_cÚy_cÚwÚhÚbs   &     Úi/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/sam3/processing_sam3.pyÚbox_cxcywh_to_xyxyr    #   sR   € Ø—X‘X˜b“\�N€CˆaØ
��a•�-˜3  q¥�=¨C°#¸µ'­M¸SÀ3ÈÅ7½]ÐL€AÜ�;Š;�q˜bÔ!Ð!ó    c                 óœ   € V P                  R4      w  rr4VRV,          ,
          VRV,          ,
          W4.p\        P                  ! VRR7      # r   r   r   s   &     r   Úbox_cxcywh_to_xywhr#   )   s@   € Ø—X‘X˜b“\�N€CˆaØ
��a•�-˜3  q¥�=¨AÐ4€AÜ�;Š;�q˜bÔ!Ð!r!   c                 ó|   € V P                  R4      w  rr#WW,           W,           .p\        P                  ! VRR7      # ©r   r   r   r   ©r   Úyr   r   r   s   &    r   Úbox_xywh_to_xyxyr(   /   ó4   € Ø—‘˜"“�J€Aˆ!Ø
�A•E˜Q�UÐ$€AÜ�;Š;�q˜bÔ!Ð!r!   c                 óœ   € V P                  R4      w  rr#V RV,          ,           VRV,          ,           W#.p\        P                  ! VRR7      # r   r   r&   s   &    r   Úbox_xywh_to_cxcywhr+   5   s@   € Ø—‘˜"“�J€Aˆ!Ø
ˆc�A�g�+˜˜S 1�W�¨Ð0€AÜ�;Š;�q˜bÔ!Ð!r!   c                 ó|   € V P                  R4      w  rr#WW ,
          W1,
          .p\        P                  ! VRR7      # r%   r   )r   r'   ÚXÚYr   s   &    r   Úbox_xyxy_to_xywhr/   ;   r)   r!   c                 ó²   € V P                  R4      w  rr4W,           ^,          W$,           ^,          W1,
          WB,
          .p\        P                  ! VRR7      # r%   r   )r   Úx0Úy0Úx1Úy1r   s   &     r   Úbox_xyxy_to_cxcywhr5   A   sB   € Ø—X‘X˜b“\�N€BˆBØ
�'�Q�˜� A�¨­°2µ7Ð<€AÜ�;Š;�q˜bÔ!Ð!r!   c                óT   € V P                  R4      w  rr4W1,
          WB,
          ,          # )zŸ
Batched version of box area. Boxes should be in [x0, y0, x1, y1] format.

Inputs:
- boxes: Tensor of shape (..., 4)

Returns:
- areas: Tensor of shape (...,)
r   )r   )Úboxesr1   r2   r3   r4   s   &    r   Úbox_arear8   G   s%   € ð —\‘\ "Ó%�N€BˆBØ�G˜�Õ Ð r!   )Úbackendsc                   óì   a a€ ] tR t^Ut oRV3R lV 3R lllt]RV3R lR ll4       tRV3R lR lltR tRR lt	R	 t
RR
 ltRR ltR tR tRV3R lR lltRR ltRR ltRR ltRR ltRtVtV ;t# )ÚSam3Processorc                ó4   <€ V ^8„  d   QhRS[ R,          RS[ /# )é   Útarget_sizeNÚpoint_pad_value)Úint)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚSam3Processor.__annotate__X   s%   ø€ ÷ kñ kÙ7:¸TµzðkÙ[^ñkr!   c                ó’   <€ \         SV `  ! W3/ VB  W@n        Ve	   W0n        R# V P                  P                  R,          V n        R# )z×
target_size (`int`, *optional*):
    The target size (target_size, target_size) to which the image will be resized.
point_pad_value (`int`, *optional*, defaults to -10):
    The value used for padding input boxes.
NÚheight)ÚsuperÚ__init__r?   Úimage_processorÚsizer>   )ÚselfrI   Ú	tokenizerr>   r?   ÚkwargsÚ	__class__s   &&&&&,€r   rH   ÚSam3Processor.__init__X   sA   ø€ ô 	‰Ò˜Ñ>°vÒ>Ø.ÔØ*5Ò*A˜;ÖÀt×G[ÑG[×G`ÑG`ÐaiÕGjˆÖr!   c                óø  <€ V ^8„  d   QhRS[ R,          RS[S[,          S[S[,          ,          S[S[,          ,          R,          RS[ R,          RS[S[S[S[,          ,          ,          S[P                  ,          R,          RS[S[S[S[,          ,          ,          S[P                  ,          R,          RS[S[S[,          ,          S[P                  ,          R,          RS[S[	,          R,          R	S[
/# )
r=   ÚimagesNÚtextÚsegmentation_mapsÚinput_boxesÚinput_boxes_labelsÚoriginal_sizesÚreturn_tensorsÚreturn)r   r   r   ÚlistÚfloatr   ÚTensorr@   Ústrr   r   )rA   rB   s   "€r   rC   rD   f   sç   ø€ ÷ jñ já˜TÕ!ðjñ Ñ+Õ+©d±9­oÕ=ÁÑEVÕ@WÕWÐZ^Õ^ðjñ &¨Õ,ð	jñ
 ™$™t¡E�{Õ+Õ,©u¯|©|Õ;¸dÕBðjñ !¡¡d©3¥i¥Õ1±E·L±LÕ@À4ÕGðjñ ™T¡%�[Õ)©E¯L©LÕ8¸4Õ?ðjñ ™jÕ(¨4Õ/ðjñ 
ñjr!   c                óZ  € Rp	Ve   V P                   ! V3RVRV/VB p	MaVeO   \        V\        P                  4      '       d   VP	                  4       P                  4       p\        RV/VR7      p	MVe   \        R4      hV P                  W$4      pVe-   V P                  W'R^ R7      p
V	e   V	P                  V
4       MT
p	VEef   V	R,          pV P                  V^R	R
^R7      pV P                  V^RRR7      pVe   Vf   V P                  V4      pVe   V P                  V4      R,          pVe   V P                  V4      R,          pVe   Ve   XX8w  d   \        R4      hVet   V P                  VX^.,           4      p\        P                  ! V\        P                   R7      pV P#                  VVRRR7       \%        V4      pV	P                  RV/4       VeL   V P                  VX4      p\        P                  ! V\        P&                  R7      pV	P                  RV/4       V	# )aÝ  
images (`ImageInput`, *optional*):
    The image(s) to process.
text (`str`, `list[str]`, `list[list[str]]`, *optional*):
    The text to process.
segmentation_maps (`ImageInput`, *optional*):
    The segmentation maps to process.
input_boxes (`list[list[list[float]]]`, `torch.Tensor`, *optional*):
    The bounding boxes to process.
input_boxes_labels (`list[list[int]]`, `torch.Tensor`, *optional*):
    The labels for the bounding boxes.
original_sizes (`list[list[float]]`, `torch.Tensor`, *optional*):
    The original sizes of the images.

Returns:
    A [`BatchEncoding`] with the following fields:
    - `pixel_values` (`torch.Tensor`): The processed image(s).
    - `original_sizes` (`list[list[float]]`): The original sizes of the images.
    - `labels` (`torch.Tensor`): The processed segmentation maps (if provided).
    - `input_boxes_labels` (`torch.Tensor`): The processed labels for the bounding boxes.
    - `input_boxes` (`torch.Tensor`): The processed bounding boxes.
NrS   rW   rV   )Útensor_typezKEither images or original_sizes must be provided if input_boxes is not NoneÚ
max_length)rW   Úpaddingr_   r7   z)[image level, box level, box coordinates])Úexpected_depthÚ
input_nameÚexpected_formatÚexpected_coord_sizeÚlabelsz[image level, box level])ra   rb   rc   :Nr=   NzaInput boxes and labels have inconsistent dimensions. Please ensure they have the same dimensions.)ÚdtypeT)Úis_bounding_boxÚpreserve_paddingrT   rU   )rI   Ú
isinstancer   r[   ÚcpuÚtolistr   Ú
ValueErrorÚ_resolve_text_promptsrL   ÚupdateÚ_validate_single_inputÚ_generate_default_box_labelsÚ_get_nested_dimensionsÚ_pad_nested_listÚtensorÚfloat32Ú_normalize_tensor_coordinatesr5   Úint64)rK   rQ   rR   rS   rT   rU   rV   rW   rM   ÚencodingÚtext_inputsÚprocessed_boxesÚprocessed_boxes_labelsÚboxes_max_dimsÚboxes_labels_max_dimsÚpadded_boxesÚfinal_boxesÚpadded_boxes_labelsÚfinal_boxes_labelss   &&&&&&&&,          r   Ú__call__ÚSam3Processor.__call__e   sn  € ðD ˆØÒØ×+Ò+Øñà"3ðð  .ðð ñ	‰Hð Ò'Ü˜.¬%¯,©,×7Ò7Ø!/×!3Ñ!3Ó!5×!<Ñ!<Ó!>�Ü$Ð&6¸Ð%GÐUcÔd‰HØÒ$ÜÐjÓkÐkà×)Ñ)¨$Ó<ˆØÒØŸ.™.¨ÐVbÐoq˜.ÓrˆKØÒ#Ø—‘ Õ,à&�ð Ó"Ø%Ð&6Õ7ˆNà"×9Ñ9ØØ Ø"Ø KØ$%ð :ó ˆOð &*×%@Ñ%@Ø"Ø Ø#Ø :ð	 &Aó &Ð"ð Ò*Ð/EÒ/MØ)-×)JÑ)JÈ?Ó)[Ð&ð Ò*Ø!%×!<Ñ!<¸_Ó!MÈbÕ!Q�Ø%Ò1Ø(,×(CÑ(CÐDZÓ([Ð\^Õ(_Ð%ð Ò*Ð/EÒ/QØ!Ð%:Ô:Ü$Ø{óð ð
 Ò*Ø#×4Ñ4°_ÀnÐXYÐWZÕFZÓ[�Ü#Ÿlšl¨<¼u¿}¹}ÔM�Ø×2Ñ2Ø ÀÐX\ð 3ô ô 1°Ó=�Ø—‘ °Ð <Ô=à%Ò1Ø&*×&;Ñ&;Ð<RÐTiÓ&jÐ#Ü%*§\¢\Ð2EÌUÏ[É[Ô%YÐ"Ø—‘Ð!5Ð7IÐ JÔKàˆr!   c                ó"   <€ V ^8„  d   QhRRRR/# )r=   Úcoordsztorch.TensorrX   © )rA   rB   s   "€r   rC   rD   Ò   s   ø€ ÷ ñ ¨^ð Ðftñ r!   c                óö   € Vw  rE\        V4      P                  4       pV'       d   VP                  R^^4      pVR,          V,          VR&   VR,          V,          VR&   V'       d   VP                  R^4      pV# )a³  
Expects a numpy array of length 2 in the final dimension. Requires the original image size in (H, W) format.

Args:
    target_size (`int`):
        The target size of the image.
    coords (`torch.Tensor`):
        The coordinates to be normalized.
    original_size (`tuple`):
        The original size of the image.
    is_bounding_box (`bool`, *optional*, defaults to `False`):
        Whether the coordinates are bounding boxes.
r   ).é    ).r   )r   rZ   Úreshape)rK   r„   Úoriginal_sizerg   Úold_hÚold_ws   &&&&  r   Ú_normalize_coordinatesÚ$Sam3Processor._normalize_coordinatesÒ   so   € ð %‰ˆÜ˜&Ó!×'Ñ'Ó)ˆçØ—^‘^ B¨¨1Ó-ˆFØ �¨%Õ/ˆˆv‰Ø �¨%Õ/ˆˆv‰çØ—^‘^ B¨Ó*ˆFàˆr!   c                ó\   € V Uu. uF  q"f   RM^.\        V4      ,          NK  	  up# u upi )z[Generate default box labels: `point_pad_value` for None (padded) entries, 1 for real boxes.N)Úlen)rK   ry   Úimage_boxess   && r   rp   Ú*Sam3Processor._generate_default_box_labelsí   s0   € á[jÓkÑ[jÈKÒ+‘°!°´s¸;Ó7GÕ1GÒGÑ[jÑkÐkùÒks   …!)c           	     óH  € Vf   R# \        V\        P                  4      '       dn   W2^,
          8X  g   \        VP                  4      ^8:  d   VP                  4       P                  4       # V Uu. uF  q@P                  WBV^,           4      NK  	  up# \        V\        P                  4      '       d`   W2^,
          8X  g   \        VP                  4      ^8:  d   VP                  4       # V Uu. uF  q@P                  WBV^,           4      NK  	  up# \        V\        4      '       d8   W28X  d   V# V Uu. uF"  pVe   V P                  WBV^,           4      MRNK$  	  up# \        V\        \        34      '       d   V# \        R\        V4       24      hu upi u upi u upi )af  
Recursively convert various input formats (tensors, numpy arrays, lists) to nested lists.
Preserves None values within lists.

Args:
    data: Input data in any format (may be None or contain None values)
    expected_depth: Expected nesting depth
    current_depth: Current depth in recursion

Returns:
    Nested list representation of the data (or None)
NzUnsupported data type: )ri   r   r[   r�   ÚshapeÚnumpyrk   Ú_convert_to_nested_listÚnpÚndarrayrY   r@   rZ   rl   Útype)rK   Údatara   Úcurrent_depthÚitems   &&&& r   r•   Ú%Sam3Processor._convert_to_nested_listñ   sq  € ð Š<Ùô �dœEŸL™L×)Ò)Ø°Õ 2Ô2´c¸$¿*¹*³oÈÔ6JØ—z‘z“|×*Ñ*Ó,Ð,ájnÓoÑjnÐbf×4Ñ4°TÈ=Ð[\ÕK\Ö]ÑjnÑoÐoÜ˜œbŸj™j×)Ò)Ø°Õ 2Ô2´c¸$¿*¹*³oÈÔ6JØ—{‘{“}Ð$ájnÓoÑjnÐbf×4Ñ4°TÈ=Ð[\ÕK\Ö]ÑjnÑoÐoÜ˜œd×#Ò#ØÔ.à�ñ
 !%óá $˜ð ^bÒ]m�D×0Ñ0°À}ÐWXÕGXÔYÐswÒwÙ $ñð ô ˜œs¤E˜l×+Ò+ØˆKäÐ6´t¸D³z°lÐCÓDÐDùò' pùò
 pùòs   Á0!FÃ/!FÄ5(Fc                ój  € Vf   V'       d   R# R# \        V\        \        34      '       g   V# \        V4      pV'       d>   \        V4      \        V4      8w  d%   \	        R\        V4       R\        V4       R24      h\        V4       F%  w  r4Ve   K  V'       g   K  W#,          f   K!  RW&   K'  	  V# )zA
Resolve text prompts by setting defaults based on prompt types.
NÚvisualzEThe number of text prompts must match the number of input boxes. Got z text prompts and z input boxes.)ri   rY   Útupler�   rl   Ú	enumerate)rK   rR   rT   ÚiÚ
text_values   &&&  r   rm   Ú#Sam3Processor._resolve_text_prompts  s«   € ð
 Š<ß*�8Ð4°Ð4ä˜$¤¤u ×.Ò.ØˆKô �D‹zˆçœ3˜t›9¬¨KÓ(8Ô8ÜðÜ˜4“y�kÐ!3´C¸Ó4DÐ3EÀ]ðTóð ô ' tž_‰MˆAØÔ!§k¡k°kµnÔ6PØ"�“ñ -ð ˆr!   c                ó&  € Vf   . p\        V\        4      '       g   V# \        V4      ^ 8X  d   VP                  \        V4      4       M\	        V^ ,          \        V4      4      V^ &   \        V4      ^ 8”  d™   V F’  pVf   K	  \        V\        4      '       g   K!  V P                  V4      p\        V4       FQ  w  rVV^,           \        V4      8¼  d   VP                  V4       K/  \	        W%^,           ,          V4      W%^,           &   KS  	  K”  	  V# )aH  
Get the maximum dimensions at each level of nesting, skipping None values.

Args:
    nested_list (`list`):
        Nested list structure (may contain None values).
    max_dims (`list`, *optional*):
        Current maximum dimensions (for recursion).

Returns:
    `list`: A list of maximum dimensions for each nesting level.
)ri   rY   r�   ÚappendÚmaxrq   r    )rK   Únested_listÚmax_dimsr›   Úsub_dimsr¡   r   s   &&&    r   rq   Ú$Sam3Processor._get_nested_dimensions6  sß   € ð ÒØˆHä˜+¤t×,Ò,ØˆOäˆx‹=˜AÔØ�O‰OœC Ó,Õ-ä˜h q�k¬3¨{Ó+;Ó<ˆH�Q‰Käˆ{Ó˜aÔÛ#�à’<ÙÜ˜d¤D×)Ô)Ø#×:Ñ:¸4Ó@�Hä"+¨HÖ"5™˜Ø˜q�5¤C¨£MÔ1Ø$ŸO™O¨CÖ0ä.1°(¸q½5µ/À3Ó.G˜H¨¥U›Oó	 #6ñ $ð ˆr!   c                ó  € Vf   V P                   pV\        V4      8¼  d   V# \        V\        4      '       g   V.p\        V4      pW#,          pV\        V4      ^,
          8X  d!   VP	                  V.We,
          ,          4       MÛV^ 8”  d†   V\        V4      ^,
          8  d   W#^,           R pV P                  Wt4      pMV.W#^,           ,          ,          pTP	                  \        We,
          4       U	u. uF  p	\        V4      NK  	  up	4       MOW#^,           R pV P                  Wt4      pTP	                  \        V4       U	u. uF  p	\        V4      NK  	  up	4       V\        V4      ^,
          8  d†   \        \        V4      4       Fm  p
W,          f!   W#^,           R pV P                  Wt4      W&   K-  \        W,          \        4      '       g   KK  V P                  W,          W#^,           V4      W&   Ko  	  V# u up	i u up	i )aË  
Recursively pad a nested list to match target dimensions. Replaces None values with padded structures.

Args:
    nested_list (`list`):
        Nested list to pad (may contain None values).
    target_dims (`list`):
        Target dimensions for each level.
    current_level (`int`, *optional*, defaults to 0):
        Current nesting level.
    pad_value (`int`, *optional*):
        Value to use for padding.

Returns:
    `list`: The padded nested list.
N)	r?   r�   ri   rY   ÚextendÚ_create_empty_nested_structureÚranger   rr   )rK   r§   Útarget_dimsÚcurrent_levelÚ	pad_valueÚcurrent_sizer>   Útemplate_dimsÚtemplateÚ_r¡   s   &&&&&      r   rr   ÚSam3Processor._pad_nested_list^  sÛ  € ð" ÒØ×,Ñ,ˆIàœC Ó,Ô,ØÐô ˜+¤t×,Ò,Ø&˜-ˆKô ˜;Ó'ˆØ!Õ0ˆð œC Ó,¨qÕ0Ô0à×Ñ 	˜{¨kÕ.HÕIÕJð ˜aÔà ¤3 {Ó#3°aÕ#7Ô7à$/ÀÕ0AÐ0CÐ$D�MØ#×BÑBÀ=Ó\‘Hð !*˜{¨[ÈÕ9JÕ-KÕK�Hà×"Ñ"ÄÀkÕF`Ô@aÓ#bÑ@a¸1¤H¨XÖ$6Ñ@aÑ#bÕcð !,¸AÕ,=Ð,?Ð @�Ø×>Ñ>¸}ÓX�Ø×"Ñ"ÄÀkÔ@RÓ#SÑ@R¸1¤H¨XÖ$6Ñ@RÑ#SÔTð œ3˜{Ó+¨aÕ/Ô/Üœ3˜{Ó+Ö,�Ø•>Ò)à$/ÀÕ0AÐ0CÐ$D�MØ%)×%HÑ%HÈÓ%b�K“NÜ ¥´×5Ô5Ø%)×%:Ñ%:¸;½>È;ÐhiÕXiÐktÓ%u�K“Nñ -ð Ðùò# $cùò
 $Ts   Ã6G?ÅHc                ó¾   € \        V4      ^8X  d   V.V^ ,          ,          # \        V^ ,          4       Uu. uF  q0P                  VR,          V4      NK  	  up# u upi )zÞ
Create an empty nested structure with given dimensions filled with pad_value.

Args:
    dims (`list`):
        The dimensions of the nested structure.
    pad_value (`int`):
        The value to fill the structure with.
:r   NN)r�   r®   r­   )rK   Údimsr±   rµ   s   &&& r   r­   Ú,Sam3Processor._create_empty_nested_structure   sV   € ô ˆt‹9˜Œ>Ø�;  a¥Õ(Ð(äV[Ð\`ÐabÕ\cÔVdÓeÑVdÐQR×7Ñ7¸¸R½À)ÖLÑVdÑeÐeùÒes   ¶!Ac                ó2  € \        V\        4      '       d<   \        V4      ^ 8X  d   ^# V F!  pVf   K	  ^V P                  V4      ,           u # 	  ^# \        V\        P
                  \        P                  34      '       d   \        VP                  4      # ^ # )z�
Get the nesting level of a list structure, skipping None values.

Args:
    input_list (`list`):
        The list to get the nesting level of.
)	ri   rY   r�   Ú_get_nesting_levelr–   r—   r   r[   r“   )rK   Ú
input_listr›   s   && r   r»   Ú Sam3Processor._get_nesting_level¯  sy   € ô �j¤$×'Ò'Ü�:‹ !Ô#Ùã"�ØÔ#Ø˜t×6Ñ6°tÓ<Õ<Ò<ñ #ñ Ü˜
¤R§Z¡Z´·±Ð$>×?Ò?ä�z×'Ñ'Ó(Ð(Ùr!   c                ó”   <€ V ^8„  d   QhRS[ P                  S[P                  ,          S[,          RS[RS[RS[RS[R,          RS[/# )r=   r™   ra   rb   rc   rd   NrX   )r   r[   r–   r—   rY   r@   r\   )rA   rB   s   "€r   rC   rD   Å  se   ø€ ÷ 0Fñ 0Fá�l‰l™RŸZ™ZÕ'©$Õ.ð0Fñ ð0Fñ ð	0Fñ
 ð0Fñ ! 4�Zð0Fñ 
ñ0Fr!   c                ó*  € Vf   R# \        V\        P                  \        P                  34      '       d‡   VP
                  V8w  d#   \        RV RV RV RVP
                   R2	4      hVe?   VP                  R,          V8w  d'   \        RV RV RVP                  R,           R24      hV P                  W4      # \        V\        4      '       dA   V P                  V4      pWb8w  d   \        RV R	V R
V RV R2	4      hV P                  W4      # R# )aW  
        Validate a single input by ensuring proper nesting and raising an error if the input is not valid.

        Args:
            data (`torch.Tensor`, `np.ndarray`, or `list`):
                Input data to process.
            expected_depth (`int`):
                Expected nesting depth.
            input_name (`str`):
                Name of the input for error messages.
            expected_format (`str`):
                The expected format of the input.
            expected_coord_size (`int`, *optional*):
                Expected coordinate size (4 for boxes, None for labels).
.
NzInput z must be a tensor/array with z, dimensions. The expected nesting format is z. Got z dimensions.z as the last dimension, got Ú.z must be a nested list with z( levels. The expected nesting format is z levels.r   )ri   r   r[   r–   r—   Úndimrl   r“   r•   rY   r»   )rK   r™   ra   rb   rc   rd   rš   s   &&&&&& r   ro   Ú$Sam3Processor._validate_single_inputÅ  s   € ð0 Š<Ùô �dœUŸ\™\¬2¯:©:Ð6×7Ò7à�y‰y˜NÔ*Ü Ø˜Z˜LÐ(EÀnÐEUð  VBð  CRð  BSð  SYð  Z^÷  Zcñ  Zcð  Ydð  dpð  qóð ð %Ò0Ø—:‘:˜b•>Ð%8Ô8Ü$Ø   Ð,IÐJ]ÐI^Ð^zÐ{÷  |Fñ  |Fð  GIõ  |Jð  {Kð  KLð  Móð ð ×/Ñ/°ÓEÐEô �dœD×!Ò!Ø ×3Ñ3°DÓ9ˆMØÔ.Ü Ø˜Z˜LÐ(DÀ^ÐDTÐT|ð  ~Mð  }Nð  NTð  Ubð  Tcð  ckð  lóð ð ×/Ñ/°ÓEÐEñ "r!   c                óÌ  € V'       d"   WP                   8g  pVP                  RRR7      p\        \        V4      4       F¢  pWqP                  ^ ,          8  g   K  V\        V4      8  d	   W',          MV^ ,          pV P                  W,          WƒR7      p	V'       dA   XV,          p
\        P                  ! V
P                  W,          4      W‘V,          4      W&   Kž  W‘V&   K¤  	  R# )a¹  
Helper method to normalize coordinates in a tensor across multiple images.

Args:
    tensor (`torch.Tensor`):
        Input tensor with coordinates.
    original_sizes (`list`):
        Original image sizes.
    is_bounding_box (`bool`, *optional*, defaults to `False`):
        Whether coordinates are bounding boxes.
    preserve_padding (`bool`, *optional*, defaults to `False`):
        Whether to preserve padding values (for boxes).
T)r   Úkeepdim)rg   Nr   )	r?   Úallr®   r�   r“   rŒ   r   ÚwhereÚ	expand_as)rK   rs   rV   rg   rh   ÚmaskÚ
coord_maskÚimg_idxr‰   Únormalized_coordsÚimg_masks   &&&&&      r   ru   Ú+Sam3Processor._normalize_tensor_coordinates÷  sÅ   € ÷ à×1Ñ1Ñ1ˆDØŸ™ b°$˜Ó7ˆJäœS Ó0Ö1ˆGØŸ™ a�Ö(Ø;BÄSÈÓEXÔ;X Ö 7Ð^lÐmnÕ^o�Ø$(×$?Ñ$?Ø•O ]ð %@ó %Ð!÷ $à)¨'Õ2�HÜ&+§k¢kØ ×*Ñ*¨6­?Ó;Ð=NÐW^ÕP_ó'�F“Oð '8˜7“Oó 2r!   c                ó@   € V P                   P                  VVVVR7      # )a¶  
Converts the output of [`Sam3Model`] into semantic segmentation maps.

Args:
    outputs ([`Sam3ImageSegmentationOutput`]):
        Raw outputs of the model containing semantic_seg.
    target_sizes (`list[tuple]` of length `batch_size`, *optional*):
        List of tuples corresponding to the requested final size (height, width) of each prediction. If unset,
        predictions will not be resized.
    threshold (`float`, *optional*, defaults to 0.5):
        Threshold for binarizing the semantic segmentation masks.
    return_segmentation_scores (`bool`, *optional*, defaults to `False`):
        Whether to return segmentation scores alongside the segmentation map.

Returns:
    semantic_segmentation: `list[torch.Tensor]` of length `batch_size`, where each item is a semantic
    segmentation map of shape (height, width) corresponding to the target_sizes entry (if `target_sizes` is
    specified). Each entry is a binary mask (0 or 1).
)Útarget_sizesÚ	thresholdÚreturn_segmentation_scores)rI   Ú"post_process_semantic_segmentation)rK   ÚoutputsrÏ   rÐ   rÑ   s   &&&&&r   rÒ   Ú0Sam3Processor.post_process_semantic_segmentation  s/   € ð, ×#Ñ#×FÑFØØ%ØØ'Að	 Gó 
ð 	
r!   c                ó:   € V P                   P                  WV4      # )a  
Converts the raw output of [`Sam3Model`] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format. This is a convenience wrapper around the image processor method.

Args:
    outputs ([`Sam3ImageSegmentationOutput`]):
        Raw outputs of the model containing pred_boxes, pred_logits, and optionally presence_logits.
    threshold (`float`, *optional*, defaults to 0.3):
        Score threshold to keep object detection predictions.
    target_sizes (`list[tuple[int, int]]`, *optional*):
        List of tuples (`tuple[int, int]`) containing the target size `(height, width)` of each image in the
        batch. If unset, predictions will not be resized.

Returns:
    `list[dict]`: A list of dictionaries, each dictionary containing the following keys:
        - **scores** (`torch.Tensor`): The confidence scores for each predicted box on the image.
        - **boxes** (`torch.Tensor`): Image bounding boxes in (top_left_x, top_left_y, bottom_right_x,
          bottom_right_y) format.

Example:

```python
>>> from transformers import AutoModel, AutoProcessor
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO

>>> model = AutoModel.from_pretrained("facebook/sam3-base")
>>> processor = AutoProcessor.from_pretrained("facebook/sam3-base")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))
>>> inputs = processor(images=image, text="cat", return_tensors="pt")
>>> outputs = model(**inputs)

>>> # Post-process to get bounding boxes
>>> results = processor.post_process_object_detection(outputs, threshold=0.3, target_sizes=[image.size[::-1]])
>>> boxes = results[0]["boxes"]
>>> scores = results[0]["scores"]
```
)rI   Úpost_process_object_detection)rK   rÓ   rÐ   rÏ   s   &&&&r   rÖ   Ú+Sam3Processor.post_process_object_detection7  s   € ðV ×#Ñ#×AÑAÀ'ÐVbÓcÐcr!   c                ó:   € V P                   P                  WW44      # )a)  
Converts the raw output of [`Sam3Model`] into instance segmentation predictions with bounding boxes and masks.
This is a convenience wrapper around the image processor method.

Args:
    outputs ([`Sam3ImageSegmentationOutput`]):
        Raw outputs of the model containing pred_boxes, pred_logits, pred_masks, and optionally
        presence_logits.
    threshold (`float`, *optional*, defaults to 0.3):
        Score threshold to keep instance predictions.
    mask_threshold (`float`, *optional*, defaults to 0.5):
        Threshold for binarizing the predicted masks.
    target_sizes (`list[tuple[int, int]]`, *optional*):
        List of tuples (`tuple[int, int]`) containing the target size `(height, width)` of each image in the
        batch. If unset, predictions will not be resized.

Returns:
    `list[dict]`: A list of dictionaries, each dictionary containing the following keys:
        - **scores** (`torch.Tensor`): The confidence scores for each predicted instance on the image.
        - **boxes** (`torch.Tensor`): Image bounding boxes in (top_left_x, top_left_y, bottom_right_x,
          bottom_right_y) format.
        - **masks** (`torch.Tensor`): Binary segmentation masks for each instance, shape (num_instances,
          height, width).

Example:

```python
>>> from transformers import AutoModel, AutoProcessor
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO

>>> model = AutoModel.from_pretrained("facebook/sam3-base")
>>> processor = AutoProcessor.from_pretrained("facebook/sam3-base")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))
>>> inputs = processor(images=image, text="cat", return_tensors="pt")
>>> outputs = model(**inputs)

>>> # Post-process to get instance segmentation
>>> results = processor.post_process_instance_segmentation(
...     outputs, threshold=0.3, target_sizes=[image.size[::-1]]
... )
>>> masks = results[0]["masks"]
>>> boxes = results[0]["boxes"]
>>> scores = results[0]["scores"]
```
)rI   Ú"post_process_instance_segmentation)rK   rÓ   rÐ   Úmask_thresholdrÏ   s   &&&&&r   rÙ   Ú0Sam3Processor.post_process_instance_segmentationd  s#   € ðr ×#Ñ#×FÑFØ ó
ð 	
r!   )r?   r>   )Niöÿÿÿ)NNNNNNN)F)r‡   )N)r‡   N)FF)Nr   F)ç333333Ó?N)rÜ   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__rH   r	   r�   rŒ   rp   r•   rm   rq   rr   r­   r»   ro   ru   rÒ   rÖ   rÙ   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)rN   rB   s   @@r   r;   r;   U   s‹   ù‡ € ÷kõ kð ÷jñ jó ðj÷Xò ò6lô(EòTô6&ôP@òDfò÷,0Fò 0Fôd!8ôF
ô:+d÷Z;
ô ;
r!   r;   )r   )!Ú__doc__Úcopyr   r”   r–   Úimage_utilsr   Úprocessing_utilsr   Útokenization_utils_baser   r   r   Úutilsr   r	   r
   r   Úutils.import_utilsr   Ú
get_loggerrÝ   Úloggerr   r    r#   r(   r+   r/   r5   r8   r;   Ú__all__r…   r!   r   Ú<module>rî      sž   ðñõ ã å %Ý .ß RÑ Rß LÓ LÝ *ð 
×	Ò	˜HÓ	%€á×ÒÛò"ò"ò"ò"ò"ò"ò!ñ 
�:ÔØôH	
�Nó H	
ó ó ðH	
ðV Ð
‚r!   