+
    œ°³j/ç  ã                   óþ  € ^ RI t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIH	t	 ^ RI
H	u Ht ^ RIHt ^RIHt ^RIHt ^RIHt ^RIHtHt ^R	IHtHt ^R
IHt ^RIHt ^RIH t H!t!H"t"H#t# ^RI$H%t%H&t&H't' ^RI(H)t)H*t* ^RI+H,t, ^RI-H.t.H/t/H0t0H1t1 ]#Pd                  ! ]34      t4 ! R R]	Pj                  4      t6]!! RR7      ] ! R R]4      4       4       t7R8R R llt8 ! R R]	Pr                  4      t: ! R R]4      t; ! R R]	Pr                  4      t<]! ! R R ]4      4       t= ! R! R"]	Pr                  4      t> ! R# R$]	Pr                  4      t?]!! R%R7       ! R& R']=4      4       t@]!! R(R7      ] ! R) R*] 4      4       4       tA ! R+ R,]	Pr                  4      tB ! R- R.]	Pr                  4      tC ! R/ R0]	Pr                  4      tD ! R1 R2]	Pr                  4      tE ! R3 R4]	Pr                  4      tF]!! R5R7       ! R6 R7]=4      4       tG. R9OtHR# ):é    N)ÚCallable)Ú	dataclass)ÚTensor)Úinitialization)ÚACT2FN)ÚGradientCheckpointingLayer)ÚBaseModelOutputÚBaseModelOutputWithPooling)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)Ú#compile_compatible_method_lru_cache)ÚModelOutputÚauto_docstringÚcan_return_tupleÚlogging)ÚTransformersKwargsÚis_flash_attention_requestedÚmerge_with_config_defaults)ÚOutputRecorderÚcapture_outputs)Ú	AutoModel)ÚEdgeTamConfigÚEdgeTamMaskDecoderConfigÚEdgeTamPromptEncoderConfigÚEdgeTamVisionConfigc                   óZ   a a€ ] tR t^5t oRtRRRR/V 3R lltV3R lV 3R lltR	tVtV ;t	# )
ÚEdgeTamLayerNorma5  LayerNorm that supports two data formats: channels_last (default) or channels_first.
The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height,
width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width).
Úepsç�íµ ÷Æ°>Údata_formatÚchannels_lastc               ód   <€ \         SV `  ! V3R V/VB  VR9  d   \        RV 24      hW0n        R# )r   zUnsupported data format: N)r"   Úchannels_first)ÚsuperÚ__init__ÚNotImplementedErrorr!   )ÚselfÚnormalized_shaper   r!   ÚkwargsÚ	__class__s   &&$$,€Úm/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/edgetam/modeling_edgetam.pyr&   ÚEdgeTamLayerNorm.__init__;   s=   ø€ Ü‰ÒÐ)Ñ=¨sÐ=°fÒ=ØÐAÔAÜ%Ð(AÀ+ÀÐ&OÓPÐPØ&Öó    c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )é   ÚfeaturesÚreturn©Útorchr   )ÚformatÚ__classdict__s   "€r,   Ú__annotate__ÚEdgeTamLayerNorm.__annotate__A   s#   ø€ ÷ ñ ¡§¡ð ±·±ñ r.   c                óº   <€ V P                   R8X  d:   VP                  ^ ^^^4      p\        SV `  V4      pVP                  ^ ^^^4      pV# \        SV `  V4      pV# )zt
Args:
    features: Tensor of shape (batch_size, channels, height, width) OR (batch_size, height, width, channels)
r$   )r!   Úpermuter%   Úforward)r(   r1   r+   s   &&€r,   r;   ÚEdgeTamLayerNorm.forwardA   sj   ø€ ð
 ×ÑÐ/Ô/Ø×'Ñ'¨¨1¨a°Ó3ˆHÜ‘w‘ xÓ0ˆHØ×'Ñ'¨¨1¨a°Ó3ˆHð ˆô ‘w‘ xÓ0ˆHØˆr.   ©r!   ©
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r&   r;   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r+   r6   s   @@r,   r   r   5   s,   ù‡ € ñð
'°ð 'À/÷ '÷÷ ó r.   r   z,Base class for the vision encoder's outputs.)Úcustom_introc                   ó8   a € ] tR t^Ot o RtRtRtV 3R ltRtV t	R# )ÚEdgeTamVisionEncoderOutputa©  
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, height, width, hidden_size)`):
    Sequence of hidden-states at the output of the last layer of the model.
fpn_hidden_states (`tuple(torch.FloatTensor)`):
    Tuple of `torch.FloatTensor` (one for each feature level, from high to low resolution) of shape
    `(batch_size, hidden_size, height, width)`. Feature maps from the Feature Pyramid Network neck.
fpn_position_encoding (`tuple(torch.FloatTensor)`):
    Tuple of `torch.FloatTensor` (one for each feature level, from high to low resolution) of shape
    `(batch_size, hidden_size, height, width)`. Positional encodings corresponding to the `fpn_hidden_states`.
Nc                óv   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   # )r0   NÚfpn_hidden_statesÚfpn_position_encoding)r4   ÚFloatTensor)r5   r6   s   "€r,   r7   Ú'EdgeTamVisionEncoderOutput.__annotate__O   s5   ø‡ ‚ ñ ×(Ñ(¨4Õ/Ñ6ñ ñ !×,Ñ,¨tÕ3Ñ:ò r.   © )
r?   r@   rA   rB   rC   rL   rM   Ú__annotate_func__rD   rE   ©r6   s   @r,   rJ   rJ   O   s   ø‡ € ñ	ð 37ÐØ6:Ð÷ ƒ r.   rJ   c                óÞ   € V ^8„  d   QhR\         P                  R\        P                  R\        P                  R\        P                  R\        P                  R,          R\        R\        /# )	r0   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskNÚscalingÚdropout)ÚnnÚModuler4   r   Úfloat)r5   s   "r,   r7   r7   a   sg   € ÷ %ñ %Ü�I‰Ið%ä�<‰<ð%ô 
�‰ð%ô �<‰<ð	%ô
 —L‘L 4Õ'ð%ô ð%ô ñ%r.   c                 óÎ  € \         P                  ! WP                  ^^4      4      V,          pVe	   W„,           p\        P                  P                  VR\         P                  R7      P                  VP                  4      p\        P                  P                  W†V P                  R7      p\         P                  ! Wƒ4      p	V	P                  ^^4      P                  4       p	W˜3# )r0   )ÚdimÚdtype)ÚpÚtrainingéÿÿÿÿ)r4   ÚmatmulÚ	transposer[   Ú
functionalÚsoftmaxÚfloat32Útor`   rZ   rb   Ú
contiguous)
rT   rU   rV   rW   rX   rY   rZ   r*   Úattn_weightsÚattn_outputs
   &&&&&&&,  r,   Úeager_attention_forwardrm   a   s°   € ô —<’< §}¡}°Q¸Ó':Ó;¸gÕE€LØÒ!Ø#Õ4ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ó[€LÜ—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KàÐ$Ð$r.   c                   óP   a a€ ] tR t^wt oRtRV 3R lltRV3R lR lltRtVtV ;t	# )ÚEdgeTamAttentionz€
EDGETAM's attention layer that allows for downscaling the size of the embedding after projection to queries, keys, and
values.
c                óÊ  <€ \         SV `  4        Vf   VP                  MTpWn        VP                  V n        VP                  V,          V n        VP                  V n        V P
                  VP                  ,          V n        V P                  R,          V n        RV n	        \        P                  ! V P                  V P
                  4      V n        \        P                  ! V P                  V P
                  4      V n        \        P                  ! V P                  V P
                  4      V n        \        P                  ! V P
                  V P                  4      V n        R # )NFg      à¿)r%   r&   Úattention_downsample_rateÚconfigÚhidden_sizeÚinternal_dimÚnum_attention_headsÚhead_dimrY   Ú	is_causalr[   ÚLinearÚq_projÚk_projÚv_projÚo_proj)r(   rr   Údownsample_rater+   s   &&&€r,   r&   ÚEdgeTamAttention.__init__}   sü   ø€ Ü‰ÑÔØ>MÒ>U˜&×:Ò:Ð[jˆØŒØ!×-Ñ-ˆÔØ"×.Ñ.°/ÕAˆÔØ#)×#=Ñ#=ˆÔ Ø×)Ñ)¨V×-GÑ-GÕGˆŒØ—}‘} dÕ*ˆŒØˆŒä—i’i × 0Ñ 0°$×2CÑ2CÓDˆŒÜ—i’i × 0Ñ 0°$×2CÑ2CÓDˆŒÜ—i’i × 0Ñ 0°$×2CÑ2CÓDˆŒÜ—i’i × 1Ñ 1°4×3CÑ3CÓDˆŽr.   c                óê   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  R,          RS[S[,          RS[S[ P                  S[ P                  3,          /# )r0   rU   rV   rW   Úattention_similarityNr*   r2   )r4   r   r   r   Útuple)r5   r6   s   "€r,   r7   ÚEdgeTamAttention.__annotate__�   st   ø€ ÷ .)ñ .)á�|‰|ð.)ñ �\‰\ð.)ñ �|‰|ð	.)ñ
 $Ÿl™l¨TÕ1ð.)ñ Ñ+Õ,ð.)ñ 
‰u�|‰|™UŸ\™\Ð)Õ	*ñ.)r.   c                óZ  € VP                   R ,          w  rgWg,          RV P                  V P                  3pV P                  V4      P                  ! V!  P                  ^^4      pV P                  V4      P                  ! V!  P                  ^^4      pV P                  V4      P                  ! V!  P                  ^^4      p\        P                  ! V P                  P                  \        4      p	\        V P                  4      '       d'   Ve#   \        R,          p	\        P                  R4       V	! V VVV3RVRRRV P                   RV P"                  /VB w  r«V
P%                  WgRV P                  V P                  ,          4      P'                  4       p
V P)                  V
4      p
W«3# )	ºNr0   NÚsdpaznFalling back to SDPA for target-guided attention because Flash Attention does not support additive bias masks.rX   rZ   ç        rY   rw   rc   )Úshaperu   rv   ry   Úviewre   rz   r{   r   Úget_interfacerr   Ú_attn_implementationrm   r   ÚloggerÚwarning_oncerY   rw   Úreshaperj   r|   )r(   rU   rV   rW   r€   r*   Ú
batch_sizeÚpoint_batch_sizeÚ	new_shapeÚattention_interfacerl   rk   s   &&&&&,      r,   r;   ÚEdgeTamAttention.forward�   s�  € ð (-§{¡{°2¥Ñ$ˆ
ØÕ2°B¸×8PÑ8PÐRV×R_ÑR_Ð`ˆ	à—‘˜EÓ"×'Ò'¨Ñ3×=Ñ=¸aÀÓCˆØ�k‰k˜#Ó×#Ò# YÑ/×9Ñ9¸!¸QÓ?ˆØ—‘˜EÓ"×'Ò'¨Ñ3×=Ñ=¸aÀÓCˆä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðô (¨¯©×4Ò4Ð9MÒ9Yô #:¸&Õ"AÐÜ×ÑðHôñ
 %8ØØØØñ	
%
ð
 0ð
%
ð ð
%
ð —L‘Lð
%
ð —n‘nð
%
ð ñ
%
Ñ!ˆð "×)Ñ)Ø¨"¨d×.FÑ.FÈÏÉÕ.Vó
ç
‰*‹,ð 	ð —k‘k +Ó.ˆàÐ(Ð(r.   )rr   rv   rs   rt   rw   rz   ru   r|   ry   rY   r{   ©Nr>   rG   s   @@r,   ro   ro   w   s   ù‡ € ñ÷
E÷ .)÷ .)ò .)r.   ro   c                   óT   a a€ ] tR t^¾t oRV3R lV 3R llltV3R lR ltRtVtV ;t# )ÚEdgeTamTwoWayAttentionBlockc                ó&   <€ V ^8„  d   QhRS[ RS[/# )r0   rr   Úskip_first_layer_pe)r   Úbool)r5   r6   s   "€r,   r7   Ú(EdgeTamTwoWayAttentionBlock.__annotate__¿   s   ø€ ÷ 7ñ 7Ñ7ð 7Édñ 7r.   c                ó4  <€ \         SV `  4        \        V^R7      V n        \        P
                  ! VP                  4      V n        \        V4      V n        \        P
                  ! VP                  4      V n	        \        VP                  VP                  VP                  VP                  R7      V n        \        P
                  ! VP                  4      V n        \        P
                  ! VP                  4      V n        \        V4      V n        W n        R# )a…  
A transformer block with four layers:
    (1) self-attention of sparse inputs (2) cross attention of sparse inputs -> dense inputs (3) mlp block on
    sparse inputs (4) cross attention of dense inputs -> sparse inputs

Arguments:
    config (`EdgeTamMaskDecoderConfig`):
        The configuration file used to instantiate the block
    attention_downsample_rate (*optional*, int, defaults to 2):
        The downsample ratio of the block used to reduce the inner dim of the attention.
    skip_first_layer_pe (*optional*, bool, defaults to `False`):
        Whether or not to skip the addition of the query_point_embedding on the first layer.
)r}   )Ú
num_layersN)r%   r&   ro   Ú	self_attnr[   Ú	LayerNormrs   Úlayer_norm1Úcross_attn_token_to_imageÚlayer_norm2ÚEdgeTamFeedForwardÚmlp_dimÚnum_hidden_layersÚmlpÚlayer_norm3Úlayer_norm4Úcross_attn_image_to_tokenr—   )r(   rr   r—   r+   s   &&&€r,   r&   Ú$EdgeTamTwoWayAttentionBlock.__init__¿   sÇ   ø€ ô 	‰ÑÔÜ)¨&À!ÔDˆŒÜŸ<š<¨×(:Ñ(:Ó;ˆÔä)9¸&Ó)AˆÔ&ÜŸ<š<¨×(:Ñ(:Ó;ˆÔä%Ø×Ñ §¡°×0BÑ0BÈv×OgÑOgô
ˆŒô Ÿ<š<¨×(:Ñ(:Ó;ˆÔäŸ<š<¨×(:Ñ(:Ó;ˆÔÜ)9¸&Ó)AˆÔ&à#6Ö r.   c                óN   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[ RS[S[,          /# )r0   ÚqueriesÚkeysÚquery_point_embeddingÚkey_point_embeddingr€   r*   )r   r   r   )r5   r6   s   "€r,   r7   r™   Þ   sM   ø€ ÷ *'ñ *'áð*'ñ ð*'ñ  &ð	*'ñ
 $ð*'ñ %ð*'ñ Ñ+Õ,ñ*'r.   c                ó  € V P                   '       d   V P                  WVR 7      w  rM%W,           pV P                  WˆVR 7      w  r—W,           pV P                  V4      pW,           pW$,           p
V P                  WŠW%R7      w  r—W,           pV P	                  V4      pV P                  V4      pW,           pV P                  V4      pW,           pW$,           p
V P                  W¨VR 7      w  r—W),           pV P                  V4      pWV	3# )©rU   rV   rW   )rU   rV   rW   r€   )	r—   rœ   rž   rŸ   r    r¤   r¥   r§   r¦   )r(   rª   r«   r¬   r­   r€   r*   Ú_rU   Úattn_outrV   Úmlp_outs   &&&&&&,     r,   r;   Ú#EdgeTamTwoWayAttentionBlock.forwardÞ   s  € ð ×#×#Ð#ØŸ™¨gÈ'˜ÓR‰JˆG�QàÕ3ˆEØŸ.™.¨uÀw˜.ÓO‰KˆHØÕ(ˆGØ×"Ñ" 7Ó+ˆð Õ/ˆØÕ(ˆà×4Ñ4Ø¨ð 5ó 
‰ˆð Õ$ˆà×"Ñ" 7Ó+ˆð —(‘(˜7Ó#ˆØÕ#ˆØ×"Ñ" 7Ó+ˆð Õ/ˆØÕ(ˆà×4Ñ4¸3ÐQXÐ4ÓY‰ˆØ�ˆà×Ñ Ó%ˆØ˜hÐ&Ð&r.   )	r§   rŸ   rž   r    r¥   r¦   r¤   rœ   r—   )F©	r?   r@   rA   rB   r&   r;   rD   rE   rF   rG   s   @@r,   r•   r•   ¾   s   ù‡ € ÷7õ 7÷>*'÷ *'ð *'r.   r•   c                   óH   a a€ ] tR tRt oRV3R lV 3R llltR tRtVtV ;t# )r¡   i  c                ó>   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[RS[/# )r0   Ú	input_dimÚ
hidden_dimÚ
output_dimr›   Ú
activationÚsigmoid_output)ÚintÚstrr˜   )r5   r6   s   "€r,   r7   ÚEdgeTamFeedForward.__annotate__  sG   ø€ ÷ -ñ -áð-ñ ð-ñ ð	-ñ
 ð-ñ ð-ñ ñ-r.   c           	     ót  <€ \         SV `  4        W@n        \        V,          V n        \
        P                  ! W4      V n        \
        P                  ! W#4      V n        \
        P                  ! \        V^,
          4       Uu. uF  p\
        P                  ! W"4      NK  	  up4      V n        W`n        R# u upi ©r0   N)r%   r&   r›   r   rº   r[   rx   Úproj_inÚproj_outÚ
ModuleListÚrangeÚlayersr»   )	r(   r·   r¸   r¹   r›   rº   r»   r°   r+   s	   &&&&&&& €r,   r&   ÚEdgeTamFeedForward.__init__  s„   ø€ ô 	‰ÑÔØ$ŒÜ  Õ,ˆŒÜ—y’y Ó7ˆŒÜŸ	š	 *Ó9ˆŒÜ—m’mÔPUÐV`ÐcdÕVdÔPeÓ$fÑPeÈ1¤R§Y¢Y¨zÖ%FÑPeÑ$fÓgˆŒØ,Öùò %gs   ÂB5c                ó  € V P                  V4      pV P                  V4      pV P                   F  pV P                  V! V4      4      pK  	  V P                  V4      pV P                  '       d   \
        P                  ! V4      pV# r“   )rÁ   rº   rÅ   rÂ   r»   ÚFÚsigmoid)r(   Úhidden_statesÚlayers   && r,   r;   ÚEdgeTamFeedForward.forward  so   € ØŸ™ ]Ó3ˆØŸ™¨Ó6ˆØ—[”[ˆEØ ŸO™O©E°-Ó,@ÓAŠMñ !ð Ÿ™ mÓ4ˆØ××ÐÜŸIšI mÓ4ˆMØÐr.   )rº   rÅ   r›   rÁ   rÂ   r»   )ÚreluFr´   rG   s   @@r,   r¡   r¡     s   ù‡ € ÷-õ -÷"	ò 	r.   r¡   c                   óz   a a€ ] tR tRt o]tRtRtRtRt	Rt
RtRt]P                  ! 4       V 3R l4       tRtVtV ;t# )	ÚEdgeTamPreTrainedModeli)  ÚedgetamÚpixel_valuesTNc                ó6  <€ \         SV `  V4       \        V\        4      '       d3   VP                  e#   \
        P                  ! VP                  4       R # R # \        VR4      '       d/   \
        P                  ! VP                  VP                  R7       R # R # )NÚpositional_embedding)Ústd)r%   Ú_init_weightsÚ
isinstanceÚEdgeTamModelÚno_memory_embeddingÚinitÚzeros_ÚhasattrÚnormal_rÓ   Úscale)r(   rT   r+   s   &&€r,   rÕ   Ú$EdgeTamPreTrainedModel._init_weights4  sk   ø€ ä‰Ñ˜fÔ%Ü�fœl×+Ò+Ø×)Ñ)Ò5Ü—’˜F×6Ñ6Ö7ñ 6ä�VÐ3×4Ò4Ü�LŠL˜×4Ñ4¸&¿,¹,×Gñ 5r.   rP   )Úimage)r?   r@   rA   rB   r   Úconfig_classÚbase_model_prefixÚmain_input_nameÚinput_modalitiesÚ_supports_sdpaÚ_supports_flash_attnÚ_supports_attention_backendÚ"_keys_to_ignore_on_load_unexpectedr4   Úno_gradrÕ   rD   rE   rF   rG   s   @@r,   rÏ   rÏ   )  sR   ù‡ € à €LØ!ÐØ$€OØ!ÐØ€NØÐØ"&ÐØ)-Ð&à
‡]‚]ƒ_ôHó ÷Hð Hr.   rÏ   c                   ó”   a a€ ] tR tRt oRtRV3R lV 3R lllt]]! ^R7      RV3R lR ll4       4       tRV3R lR	 llt	R
t
VtV ;t# )ÚEdgeTamSinePositionEmbeddingi>  z 
This is a more standard version of the position embedding, very similar to the one used by the Attention is all you
need paper, generalized to work on images.
c          	      ó@   <€ V ^8„  d   QhRS[ RS[ RS[RS[R,          /# )r0   Únum_position_featuresÚtemperatureÚ	normalizerÝ   N)r¼   r˜   r]   )r5   r6   s   "€r,   r7   Ú)EdgeTamSinePositionEmbedding.__annotate__D  s7   ø€ ÷ =ñ =á"ð=ñ ð=ñ ð	=ñ
 �t�|ñ=r.   c                óÄ   <€ \         SV `  4        Ve   VRJ d   \        R4      hWn        W n        W0n        Vf   ^\        P                  ,          V n        R # TV n        R # )NFz+normalize should be True if scale is passed)	r%   r&   Ú
ValueErrorrì   rí   rî   ÚmathÚpirÝ   )r(   rì   rí   rî   rÝ   r+   s   &&&&&€r,   r&   Ú%EdgeTamSinePositionEmbedding.__init__D  sS   ø€ ô 	‰ÑÔØÒ ¨eÓ!3ÜÐJÓKÐKØ%:Ô"Ø&ÔØ"ŒØ$)¢M�QœŸ™•[ˆŽ
°uˆŽ
r.   )Úmaxsizec                óà   <€ V ^8„  d   QhRS[ P                  RS[ P                  S[,          RS[ P                  RS[RS[RS[R,          RS[R	S[ P                  R,          R
S[ P                  /	# )r0   r‡   Údevicer`   rì   rî   rÝ   Nrí   Úmaskr2   )	r4   ÚSizer÷   r½   r`   r¼   r˜   r]   r   )r5   r6   s   "€r,   r7   rï   U  s…   ø€ ÷ (ñ (Ù�z‰zð(á—‘™sÕ"ð(ñ �{‰{ð(ñ  #ð	(ñ
 ð(ñ �t�|ð(ñ ð(ñ �l‰l˜TÕ!ð(ñ 
�‰ñ(r.   c                ó¤  € V w  r‰r«Vfp   \         P                  ! ^V
^,           W!R7      R,          P                  WŠV4      p\         P                  ! ^V^,           W!R7      R,          P                  WŠV4      pM3VP                  V4      pVP	                  ^4      pVP	                  ^4      pV'       dG   RpWÌRR	R 1R3,          V,           ,          V,          pWÝRRR	R 13,          V,           ,          V,          p\         P                  ! V\         P
                  VR7      P                  V4      pV^\         P                  ! V^RR7      ,          V,          ,          pVR
,          V,          pVR
,          V,          p\         P                  ! VR,          P                  4       VR,          P                  4       3^R7      P                  ^4      p\         P                  ! VR,          P                  4       VR,          P                  4       3^R7      P                  ^4      p\         P                  ! VV3^R7      P                  ^ ^^^4      pV# )N©r`   r÷   ºNNNr    Úfloor)Úrounding_mode©r_   )Nrü   N)NNrü   rc   )rü   rü   rü   N)rü   rü   rü   :r   Nr0   )rü   rü   rü   :é   Nr0   )r4   ÚarangeÚexpandri   ÚcumsumÚint64ÚdivÚstackÚsinÚcosÚflattenÚcatr:   )r‡   r÷   r`   rì   rî   rÝ   rí   rø   rŽ   r°   ÚheightÚwidthÚy_embedÚx_embedÚ
embed_maskr   Údim_tÚpos_xÚpos_yÚposs   &&&&&&&&            r,   Úbuild_sine_position_embeddingÚ:EdgeTamSinePositionEmbedding.build_sine_position_embeddingS  së  € ð (-Ñ$ˆ
�vØŠ<ô —l’l 1 f¨q¥j¸ÔMÈmÕ\×cÑcØ EóˆGô —l’l 1 e¨a¥i°uÔLÈ]Õ[×bÑbØ Eó‰Gð Ÿ™ ›ˆJØ ×'Ñ'¨Ó*ˆGØ ×'Ñ'¨Ó*ˆGßØˆCØ¨¨B©C°¨Õ!3°cÕ!9Õ:¸UÕBˆGØ¨¨A¨r©s¨Õ!3°cÕ!9Õ:¸UÕBˆGä—’Ð2¼%¿+¹+ÈfÔU×XÑXÐY^Ó_ˆØ ¤E§I¢I¨e°QÀgÔ$NÕ NÐQfÕ fÕgˆà˜Õ&¨Õ.ˆØ˜Õ&¨Õ.ˆÜ—’˜U =Õ1×5Ñ5Ó7¸¸}Õ9M×9QÑ9QÓ9SÐTÐZ[Ô\×dÑdÐefÓgˆÜ—’˜U =Õ1×5Ñ5Ó7¸¸}Õ9M×9QÑ9QÓ9SÐTÐZ[Ô\×dÑdÐefÓgˆÜ�iŠi˜ ˜¨AÔ.×6Ñ6°q¸!¸QÀÓBˆØˆ
r.   c          
      óº   <€ V ^8„  d   QhRS[ P                  RS[ P                  S[,          RS[ P                  RS[ P
                  R,          RS[ P
                  /# )r0   r‡   r÷   r`   rø   Nr2   )r4   rù   r÷   r½   r`   r   )r5   r6   s   "€r,   r7   rï     s[   ø€ ÷ 	
ñ 	
á�z‰zð	
ñ —‘™sÕ"ð	
ñ �{‰{ð		
ñ
 �l‰l˜TÕ!ð	
ñ 
�‰ñ	
r.   c           
     ó~   € V P                  WW0P                  V P                  V P                  V P                  V4      # r“   )r  rì   rî   rÝ   rí   )r(   r‡   r÷   r`   rø   s   &&&&&r,   r;   Ú$EdgeTamSinePositionEmbedding.forward  s:   € ð ×1Ñ1Ø˜5×"<Ñ"<¸d¿n¹nÈdÏjÉjÐZ^×ZjÑZjÐlpó
ð 	
r.   )rî   rì   rÝ   rí   )é@   é'  FN)FNr  Nr“   )r?   r@   rA   rB   rC   r&   Ústaticmethodr   r  r;   rD   rE   rF   rG   s   @@r,   rê   rê   >  sJ   ù‡ € ñ÷
=õ =ð Ù(°Ô3÷(ñ (ó 4ó ð(÷T	
÷ 	
ò 	
r.   rê   c                   óP   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltRtVtV ;t# )ÚEdgeTamVisionNecki‹  c                ó    <€ V ^8„  d   QhRS[ /# ©r0   rr   ©r   )r5   r6   s   "€r,   r7   ÚEdgeTamVisionNeck.__annotate__Œ  s   ø€ ÷ >ñ >Ñ2ñ >r.   c                óª  <€ \         SV `  4        Wn        \        VP                  ^,          RR7      V n        \        P                  ! 4       V n        VP                   F_  pV P                  P                  \        P                  ! VVP                  VP                  VP                  VP                  R7      4       Ka  	  VP                  V n        R# )r0   T)rì   rî   )Úin_channelsÚout_channelsÚkernel_sizeÚstrideÚpaddingN)r%   r&   rr   rê   Úfpn_hidden_sizeÚposition_encodingr[   rÃ   ÚconvsÚbackbone_channel_listÚappendÚConv2dÚfpn_kernel_sizeÚ
fpn_strideÚfpn_paddingÚfpn_top_down_levels)r(   rr   r#  r+   s   && €r,   r&   ÚEdgeTamVisionNeck.__init__Œ  s¤   ø€ Ü‰ÑÔØŒä!=Ø"(×"8Ñ"8¸AÕ"=Èô"
ˆÔô —]’]“_ˆŒ
Ø!×7Ô7ˆKØ�J‰J×ÑÜ—	’	Ø +Ø!'×!7Ñ!7Ø &× 6Ñ 6Ø!×,Ñ,Ø"×.Ñ.ôöñ 8ð $*×#=Ñ#=ˆÖ r.   c                ó    <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  R3,          S[S[ P                  R3,          3,          /# )r0   rÊ   r2   .)r4   r   r�   )r5   r6   s   "€r,   r7   r!     sK   ø€ ÷ 8ñ 8¡U§\¡\ð 8±e¹EÁ%Ç,Á,ÐPSÐBSÕ<TÑV[Ñ\a×\hÑ\hÐjmÐ\mÕVnÐ<nÕ6oñ 8r.   c           	     óì  € RpRp\        V P                  4      ^,
          p\        VRR4       EF@  pW,          P                  ^ ^^^4      pV P                  WE,
          ,          ! VP	                  V P                  V,          P
                  P                  4      4      pWPP                  9  g   WT8X  d   TpMZ\        P                  ! XP	                  \        P                  R7      RRRRR7      P	                  VP                  4      pWh,           pV P                  VP                  VP                  VP                  4      P	                  VP                  4      p	W'3,          pW93,          pEKC  	  W#3# )	r   )r`   g       @ÚnearestNF)Úscale_factorÚmodeÚalign_cornersÚ	antialiasrP   rc   )Úlenr*  rÄ   r:   ri   Úweightr`   r1  rÈ   Úinterpolater4   rh   r)  r‡   r÷   )
r(   rÊ   rL   rM   ÚnÚiÚlateral_featuresÚprev_featuresÚtop_down_featuresÚprev_position_encodings
   &&        r,   r;   ÚEdgeTamVisionNeck.forward   sK  € ØÐØ "Ðô �—
‘
‹O˜aÕˆÜ�q˜"˜b×!ˆAØ,Õ/×7Ñ7¸¸1¸aÀÓCÐØ#Ÿz™z¨!­%Ö0Ð1A×1DÑ1DÀTÇZÁZÐPQÅ]×EYÑEY×E_ÑE_Ó1`ÓaÐØ×0Ñ0Ô0°A´FØ 0‘ä$%§M¢MØ!×$Ñ$¬5¯=©=Ð$Ó9Ø!$Ø"Ø"&Ø#ô%÷ ‘"Ð%×+Ñ+Ó,ð "ð !1Õ D�à%)×%;Ñ%;Ø×#Ñ# ]×%9Ñ%9¸=×;NÑ;Nó&ç‰b�×$Ñ$Ó%ð #ð Ð!1Õ1ÐØ!Ð%>Õ>Ó!ñ) "ð, !Ð7Ð7r.   )rr   r*  r1  r)  r´   rG   s   @@r,   r  r  ‹  s   ù‡ € ÷>ó >÷(8÷ 8ð 8r.   r  zN
    The vision model from EdgeTAM without any head or projection on top.
    c                   ót   a a€ ] tR tRt o]tRt/ tV3R lV 3R llt]	]
RV3R lR ll4       4       tRtVtV ;t# )	ÚEdgeTamVisionModeli¿  rÑ   c                ó    <€ V ^8„  d   QhRS[ /# r  r   )r5   r6   s   "€r,   r7   ÚEdgeTamVisionModel.__annotate__Ë  s   ø€ ÷ 	ñ 	Ñ2ñ 	r.   c                óÞ   <€ \         SV `  V4       Wn        \        P                  ! VP
                  4      V n        \        V4      V n        VP                  V n	        V P                  4        R # r“   )r%   r&   rr   r   Úfrom_configÚbackbone_configÚbackboner  ÚneckÚnum_feature_levelsÚ	post_init©r(   rr   r+   s   &&€r,   r&   ÚEdgeTamVisionModel.__init__Ë  sQ   ø€ Ü‰Ñ˜Ô ØŒä!×-Ò-¨f×.DÑ.DÓEˆŒä% fÓ-ˆŒ	Ø"(×";Ñ";ˆÔà�‰Ör.   c                ón   <€ V ^8„  d   QhRS[ P                  R,          RS[S[,          RS[S[,          /# )r0   rÑ   Nr*   r2   ©r4   rN   r   r   r�   rJ   )r5   r6   s   "€r,   r7   rG  Ø  s@   ø€ ÷ 
ñ 
á×'Ñ'¨$Õ.ð
ñ Ñ+Õ,ð
ñ 
Ñ+Õ	+ñ	
r.   c           	     óv  € Vf   \        R4      hV P                  ! V3/ VB pVP                  pV Uu. uF  qUP                  ^ ^^^4      NK  	  ppV P	                  V4      w  rgW`P
                  ) R  R R R1,          pWpP
                  ) R  R R R1,          p\        VR,          VVVP                  R7      # u upi )Nz You have to specify pixel_values)Úlast_hidden_staterL   rM   rÊ   rc   )rñ   rK  rT  r:   rL  rM  rJ   rÊ   )r(   rÑ   r*   Úbackbone_outputÚintermediate_hidden_statesÚhidden_staterL   rM   s   &&,     r,   r;   ÚEdgeTamVisionModel.forwardÖ  sÙ   € ð ÒÜÐ?Ó@Ð@ð Ÿ-š-¨Ñ?¸Ñ?ˆØ%4×%FÑ%FÐ"Ù[uÓ%vÑ[uÈ<×&:Ñ&:¸1¸aÀÀAÖ&FÑ[uÐ"Ð%và37·9±9Ð=WÓ3XÑ0Ðà-×/FÑ/FÐ.FÐ.HÐIÉ$ÈBÈ$ÕOÐØ 5×7NÑ7NÐ6NÐ6PÐ QÑRVÐTVÐRVÕ WÐä)Ø8¸Õ<Ø/Ø"7Ø)×7Ñ7ô	
ð 	
ùò &ws   ³B6)rK  rr   rL  rM  r“   )r?   r@   rA   rB   r   rà   râ   Ú_can_record_outputsr&   r   r   r;   rD   rE   rF   rG   s   @@r,   rE  rE  ¿  sI   ù‡ € ð '€LØ$€Oð Ð÷	ó 	ð  Ø÷
ñ 
ó ó  ÷
ð 
r.   rE  z*Base class for the EdgeTam model's output.c                   óL   a € ] tR tRt o RtRtRtRtRtRt	Rt
RtV 3R ltRtV tR# )ÚEdgeTamImageSegmentationOutputiò  ay  
iou_scores (`torch.FloatTensor` of shape `(batch_size, point_batch_size, num_masks)`):
    The Intersection over Union (IoU) scores of the predicted masks.
pred_masks (`torch.FloatTensor` of shape `(batch_size, point_batch_size, num_masks, height, width)`):
    The predicted low-resolution masks. This is an alias for `low_res_masks`. These masks need to be post-processed
    by the processor to be brought to the original image size.
object_score_logits (`torch.FloatTensor` of shape `(batch_size, point_batch_size, 1)`):
    Logits for the object score, indicating if an object is present.
image_embeddings (`tuple(torch.FloatTensor)`):
    The features from the FPN, which are used by the mask decoder. This is a tuple of `torch.FloatTensor` where each
    tensor has shape `(batch_size, channels, height, width)`.
vision_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True`):
    Tuple of `torch.FloatTensor` (one for the output of each stage) of shape `(batch_size, height, width, hidden_size)`.
    Hidden-states of the vision model at the output of each stage.
vision_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True`):
    Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, sequence_length)`.
    Attentions weights of the vision model.
mask_decoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True`):
    Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, sequence_length)`.
    Attentions weights of the mask decoder.
Nc                óž  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  R3,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R	&   # )
r0   NÚ
iou_scoresÚ
pred_masksÚobject_score_logits.Úimage_embeddingsÚvision_hidden_statesÚvision_attentionsÚmask_decoder_attentions)r4   rN   r�   )r5   r6   s   "€r,   r7   Ú+EdgeTamImageSegmentationOutput.__annotate__ò  sÐ   ø‡ ‚ ñ2 ×!Ñ! DÕ(Ñ/ñ3 ñ4 ×!Ñ! DÕ(Ñ/ñ5 ñ6 ×*Ñ*¨TÕ1Ñ8ñ7 ñ8 ™E×-Ñ-¨sÐ2Õ3Ñ:ñ9 ñ:  ¡× 1Ñ 1°3Ð 6Õ7¸$Õ>ÑEñ; ñ< ™U×.Ñ.°Ð3Õ4°tÕ;ÑBñ= ñ> #¡5×#4Ñ#4°cÐ#9Õ:¸TÕAÑHò? r.   rP   )r?   r@   rA   rB   rC   r]  r^  r_  r`  ra  rb  rc  rQ   rD   rE   rR   s   @r,   r[  r[  ò  s;   ø‡ € ñð, ,0€JØ+/€JØ48ÐØ6:ÐØAEÐØ>BÐØDHÐ÷? ƒ r.   r[  c                   óH   a a€ ] tR tRt oV3R lV 3R lltRR ltRtVtV ;t# )ÚEdgeTamPositionalEmbeddingi  c                ó    <€ V ^8„  d   QhRS[ /# r  ©r   )r5   r6   s   "€r,   r7   Ú'EdgeTamPositionalEmbedding.__annotate__  s   ø€ ÷ Dñ DÑ9ñ Dr.   c                óð   <€ \         SV `  4        VP                  V n        V P                  \        P                  ! ^VP
                  ^,          34      ,          p\        P                  ! V4      V n        R# rÀ   )	r%   r&   rÝ   r4   Úrandnrs   r[   ÚBufferrÓ   )r(   rr   rÓ   r+   s   && €r,   r&   Ú#EdgeTamPositionalEmbedding.__init__  sT   ø€ Ü‰ÑÔØ—\‘\ˆŒ
Ø#Ÿz™z¬E¯KªK¸¸F×<NÑ<NÐRSÕ<SÐ8TÓ,UÕUÐÜ$&§I¢IÐ.BÓ$CˆÖ!r.   c                ó  € VP                  4       pVe5   VR,          V^,          ,          VR&   VR,          V^ ,          ,          VR&   VP                  \        P                  4       ^V,          ^,
          pVP                  V P                  P
                  4      pW0P                  ,          p^\        P                  ,          V,          p\        P                  ! \        P                  ! V4      \        P                  ! V4      .RR7      # )z8Positionally encode points that are normalized to [0,1].rÿ   ©rü   rü   rü   r   )rü   rü   rü   r   rc   )Úcloneri   r4   rh   rÓ   r`   Únpró   r
  r  r  )r(   Úinput_coordsÚinput_shapeÚcoordinatess   &&& r,   r;   Ú"EdgeTamPositionalEmbedding.forward  sÈ   € à"×(Ñ(Ó*ˆàÒ"Ø&1°*Õ&=ÀÈAÅÕ&NˆK˜
Ñ#Ø&1°*Õ&=ÀÈAÅÕ&NˆK˜
Ñ#Ø�‰”u—}‘}Ô%ð ˜+•o¨Õ)ˆØ!—n‘n T×%>Ñ%>×%DÑ%DÓEˆØ!×$=Ñ$=Õ=ˆØœ"Ÿ%™%•i +Õ-ˆä�yŠyœ%Ÿ)š) KÓ0´%·)²)¸KÓ2HÐIÈrÔRÐRr.   )rÓ   rÝ   r“   r´   rG   s   @@r,   rf  rf    s   ù‡ € ÷Dó D÷Sô Sr.   rf  c                   óD   a a€ ] tR tRt oV3R lV 3R lltR tRtVtV ;t# )ÚEdgeTamMaskEmbeddingi-  c                ó    <€ V ^8„  d   QhRS[ /# r  rh  )r5   r6   s   "€r,   r7   Ú!EdgeTamMaskEmbedding.__annotate__.  s   ø€ ÷ 
ñ 
Ñ9ñ 
r.   c                óR  <€ \         SV `  4        VP                  ^,          V n        \        VP                  ,          V n        \        P                  ! ^V P                  ^^R7      V n        \        P                  ! V P                  VP                  ^^R7      V n	        \        P                  ! VP                  VP                  ^R7      V n        \        V P                  VP                  RR7      V n        \        V P                  ^,          VP                  RR7      V n        R# )é   ©r%  r&  )r%  r$   )r   r!   N)r%   r&   Úmask_input_channelsr   Ú
hidden_actrº   r[   r-  Úconv1Úconv2rs   Úconv3r   Úlayer_norm_epsrž   r    rO  s   &&€r,   r&   ÚEdgeTamMaskEmbedding.__init__.  sÞ   ø€ Ü‰ÑÔØ#)×#=Ñ#=ÀÕ#BˆÔ Ü  ×!2Ñ!2Õ3ˆŒÜ—Y’Y˜q $×":Ñ":ÈÐRSÔTˆŒ
Ü—Y’Y˜t×7Ñ7¸×9SÑ9SÐabÐklÔmˆŒ
Ü—Y’Y˜v×9Ñ9¸6×;MÑ;MÐ[\Ô]ˆŒ
Ü+Ø×$Ñ$¨&×*?Ñ*?ÐM]ô
ˆÔô ,Ø×$Ñ$ qÕ(¨f×.CÑ.CÐQaô
ˆÖr.   c                óô   € V P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV P	                  V4      pV P                  V4      pV P                  V4      pV# r“   )r  rž   rº   r€  r    r�  )r(   ÚmasksrÊ   Údense_embeddingss   &&  r,   r;   ÚEdgeTamMaskEmbedding.forward<  so   € ØŸ
™
 5Ó)ˆØ×(Ñ(¨Ó7ˆØŸ™¨Ó6ˆàŸ
™
 =Ó1ˆØ×(Ñ(¨Ó7ˆØŸ™¨Ó6ˆØŸ:™: mÓ4ÐØÐr.   )rº   r  r€  r�  rž   r    r}  r´   rG   s   @@r,   rw  rw  -  s   ù‡ € ÷
ó 
÷	 ò 	 r.   rw  c                   ót   a a€ ] tR tRt oV3R lV 3R lltV3R lR ltV3R lR ltV3R lR	 ltR
tVt	V ;t
# )ÚEdgeTamPromptEncoderiH  c                ó    <€ V ^8„  d   QhRS[ /# r  rh  )r5   r6   s   "€r,   r7   Ú!EdgeTamPromptEncoder.__annotate__I  s   ø€ ÷ Eñ EÑ9ñ Er.   c                ó¸  <€ \         SV `  4        \        V4      V n        \	        V4      V n        \        P                  ! ^VP                  4      V n	        VP                  VP                  ,          VP                  VP                  ,          3V n        ^VP                  ,          VP                  ,          ^VP                  ,          VP                  ,          3V n        VP                  V n        \        P                  ! VP                  VP                  4      V n        VP                  V n        \        P                  ! ^VP                  4      V n        R# ©r   N)r%   r&   rf  Úshared_embeddingrw  Ú
mask_embedr[   Ú	Embeddingrs   Úno_mask_embedÚ
image_sizeÚ
patch_sizeÚimage_embedding_sizeÚmask_input_sizeÚinput_image_sizeÚnum_point_embeddingsÚpoint_embedÚnot_a_point_embedrO  s   &&€r,   r&   ÚEdgeTamPromptEncoder.__init__I  sÿ   ø€ Ü‰ÑÔÜ :¸6Ó BˆÔÜ.¨vÓ6ˆŒÜŸ\š\¨!¨V×-?Ñ-?Ó@ˆÔà%+×%6Ñ%6¸&×:KÑ:KÕ%KÈV×M^ÑM^Ðbh×bsÑbsÕMsÐ$tˆÔ!Ø ! F×$5Ñ$5Õ 5¸×9JÑ9JÕ JÈAÐPV×PaÑPaÕLaÐek×evÑevÕLvÐwˆÔØ &× 1Ñ 1ˆÔäŸ<š<¨×(CÑ(CÀV×EWÑEWÓXˆÔØ!×-Ñ-ˆÔÜ!#§¢¨a°×1CÑ1CÓ!DˆÖr.   c                ón   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RS[ P                  /# )r0   ÚpointsÚlabelsÚpadr2   )r4   r   r˜   )r5   r6   s   "€r,   r7   r‹  W  s8   ø€ ÷ ñ ¡E§L¡Lð ¹%¿,¹,ð ÉTð ÑV[×VbÑVbñ r.   c                ó†  € VR,           pV'       d[   \         P                  P                  P                  VRR^ R7      p\         P                  P                  P                  VRRRR7      pV P                  V P                  3pV P                  W4      p\         P                  ! VR,          R8H  V P                  P                  V4      p\         P                  ! VR,          R	8g  V\         P                  ! V4      4      pWPP                  VP                  ^ R7      4      V^ 8¬  P                  R4      ,          ,           pV# )
zEmbeds point prompts.ç      à?Úconstant©r7  rW   )Úmin©r   r   r   r   )r   r   rc   ).Niöÿÿÿ)r4   r[   rf   rž  r–  rŽ  Úwherer™  r;  Ú
zeros_liker˜  ÚclampÚ	unsqueeze)r(   rœ  r�  rž  rs  Úpoint_embeddings   &&&&  r,   Ú_embed_pointsÚ"EdgeTamPromptEncoder._embed_pointsW  s  € à˜#•ˆßÜ—X‘X×(Ñ(×,Ñ,¨V°\È
ÐZ[Ð,Ó\ˆFÜ—X‘X×(Ñ(×,Ñ,¨V°VÀ*ÐTVÐ,ÓWˆFØ×,Ñ,¨d×.CÑ.CÐDˆØ×/Ñ/°ÓDˆô  Ÿ+š+ f¨YÕ&7¸2Ñ&=¸t×?UÑ?U×?\Ñ?\Ð^mÓnˆô  Ÿ+š+Ø�9Õ Ñ$ØÜ×Ò˜_Ó-ó
ˆð *×,<Ñ,<¸V¿\¹\Èa¸\Ó=PÓ,QÐU[Ð_`ÑU`×TkÑTkÐlnÓToÕ,oÕoˆàÐr.   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r0   Úboxesr2   r3   )r5   r6   s   "€r,   r7   r‹  p  s#   ø€ ÷ 
 ñ 
 ¡%§,¡,ð 
 ±5·<±<ñ 
 r.   c                ó.  € VR,           pVP                   ! . VP                  R,          O^N^N5!  p\        P                  P                  P                  VRR^ R7      pV P                  W P                  V P                  34      pVR;;,          V P                  P                  ^,          ,          uu&   VR;;,          V P                  P                  ^,          ,          uu&   V P                  P                  P                  VR,          4      VR&   V# )	zEmbeds box prompts.r   r„   r¡  r¢  r¤  ©rü   rü   r   rü   ©rü   rü   r   rü   )rü   rü   r0   rü   )rˆ   r‡   r4   r[   rf   rž  rŽ  r–  r˜  r;  r™  Ú	expand_as)r(   r­  ÚcoordsÚcorner_embeddings   &&  r,   Ú_embed_boxesÚ!EdgeTamPromptEncoder._embed_boxesp  sæ   € à˜•ˆØ—’Ð3˜UŸ[™[¨�_Ð3¨aÐ3°Ó3ˆä—‘×$Ñ$×(Ñ(¨°ÀJÐVWÐ(ÓXˆØ×0Ñ0°×:OÑ:OÐQU×QfÑQfÐ9gÓhÐØ˜×$¨×(8Ñ(8×(?Ñ(?ÀÕ(BÕBÓ$Ø˜×$¨×(8Ñ(8×(?Ñ(?ÀÕ(BÕBÓ$Ø'+×'=Ñ'=×'DÑ'D×'NÑ'NÐO_Ð`jÕOkÓ'lÐ˜Ñ$ØÐr.   c                ó(  <€ V ^8„  d   QhRS[ S[P                  S[P                  3,          R,          RS[P                  R,          RS[P                  R,          RS[P                  R,          RS[ S[P                  S[P                  3,          /# )r0   Úinput_pointsNÚinput_labelsÚinput_boxesÚinput_masksr2   )r�   r4   r   )r5   r6   s   "€r,   r7   r‹  |  s�   ø€ ÷ (3ñ (3á™EŸL™L©%¯,©,Ð6Õ7¸$Õ>ð(3ñ —l‘l TÕ)ð(3ñ —\‘\ DÕ(ð	(3ñ
 —\‘\ DÕ(ð(3ñ 
‰u�|‰|™UŸ\™\Ð)Õ	*ñ(3r.   c                ó  € Rp^pVe:   VP                   ^ ,          pVf   \        R4      hV P                  WVRJ R7      pTpVeE   VP                   ^ ,          pV P                  V4      pVf   TpM\        P
                  ! WX.^R7      pVe   V P                  V4      p	WY3# V P                  P                  P                  ^R^^4      P                  VRV P                  ^ ,          V P                  ^,          4      p	WY3# )a-  
Embeds different types of prompts, returning both sparse and dense embeddings.

Args:
    points (`torch.Tensor`, *optional*):
        point coordinates and labels to embed.
    boxes (`torch.Tensor`, *optional*):
        boxes to embed
    masks (`torch.Tensor`, *optional*):
        masks to embed
Nz5If points are provided, labels must also be provided.)rž  rÿ   rc   )r‡   rñ   rª  r´  r4   r
  r�  r‘  r;  r�   r  r”  )
r(   r·  r¸  r¹  rº  Úsparse_embeddingsrŽ   Úpoint_embeddingsÚbox_embeddingsr†  s
   &&&&&     r,   r;   ÚEdgeTamPromptEncoder.forward|  s  € ð$ !ÐØˆ
ØÒ#Ø%×+Ñ+¨AÕ.ˆJØÒ#Ü Ð!XÓYÐYØ#×1Ñ1°,ÐS^ÐbfÐSfÐ1ÓhÐØ 0ÐØÒ"Ø$×*Ñ*¨1Õ-ˆJØ!×.Ñ.¨{Ó;ˆNØ Ò(Ø$2Ñ!ä$)§I¢IÐ/@Ð.QÐWXÔ$YÐ!ØÒ"Ø#Ÿ™¨{Ó;Ðð !Ð2Ð2ð	  $×1Ñ1×8Ñ8×@Ñ@ÀÀBÈÈ1ÓM×TÑTØ˜B × 9Ñ 9¸!Õ <¸d×>WÑ>WÐXYÕ>Zó Ðð !Ð2Ð2r.   )	rs   r”  r–  r�  r•  r‘  r™  r˜  rŽ  )r?   r@   rA   rB   r&   rª  r´  r;   rD   rE   rF   rG   s   @@r,   r‰  r‰  H  s4   ù‡ € ÷Eó E÷ð ÷2
 ð 
 ÷(3÷ (3ð (3r.   r‰  c                   óT   a a€ ] tR tRt oV3R lV 3R lltRV3R lR lltRtVtV ;t# )ÚEdgeTamTwoWayTransformeri§  c                ó    <€ V ^8„  d   QhRS[ /# r  ©r   )r5   r6   s   "€r,   r7   Ú%EdgeTamTwoWayTransformer.__annotate__¨  s   ø€ ÷ Fñ FÑ7ñ Fr.   c                óx  <€ \         SV `  4        Wn        VP                  V n        \        P
                  ! 4       V n        \        V P                  4       F+  pV P                  P                  \        W^ 8H  R7      4       K-  	  \        V4      V n        \        P                  ! VP                  4      V n        R# )r   )r—   N)r%   r&   rr   r£   r[   rÃ   rÅ   rÄ   r,  r•   ro   Úfinal_attn_token_to_imager�   rs   Úlayer_norm_final_attn)r(   rr   r>  r+   s   && €r,   r&   Ú!EdgeTamTwoWayTransformer.__init__¨  s‡   ø€ Ü‰ÑÔØŒà!'×!9Ñ!9ˆÔÜ—m’m“oˆŒä�t×-Ñ-Ö.ˆAØ�K‰K×ÑÔ:¸6Ð]^ÑX^Ô`Öañ /ô *:¸&Ó)AˆÔ&Ü%'§\¢\°&×2DÑ2DÓ%EˆÖ"r.   c                ó^   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[S[,          RS[S[,          /# )r0   r½  r`  Úimage_positional_embeddingsr€   r*   r2   )r   r   r   r�   r	   )r5   r6   s   "€r,   r7   rÄ  µ  sR   ø€ ÷ (ñ (á ð(ñ !ð(ñ &,ð	(ñ
 %ð(ñ Ñ+Õ,ð(ñ 
‘Õ	 ñ(r.   c                óÒ  € Vf   \        R4      hVP                  ^4      P                  ^^4      P                  ^4      pVP                  ^4      P                  ^^4      P                  ^4      pTpTpV P                   F$  p	Ve	   Wu,          pV	! RRVRVRVRVRV/VB w  rxp
K&  	  Wq,           pWƒ,           pV P                  W¼VR7      w  rÚW},           pV P                  V4      pWx3# )	Nz&You have to specify an image_embeddingrª   r«   r¬   r­   r€   r¯   rP   )rñ   r	  re   r¨  rÅ   rÆ  rÇ  )r(   r½  r`  rÊ  r€   Útarget_embeddingr*   rª   r«   rË   r°   rU   rV   r±   s   &&&&&&,       r,   r;   Ú EdgeTamTwoWayTransformer.forwardµ  s(  € ð Ò#ÜÐEÓFÐFà+×3Ñ3°AÓ6×@Ñ@ÀÀAÓF×PÑPÐQRÓSÐØ&A×&IÑ&IÈ!Ó&L×&VÑ&VÐWXÐZ[Ó&\×&fÑ&fÐghÓ&iÐ#ð #ˆØˆð —[”[ˆEØÒ+ØÕ+�á$ñ  Øð àð ð '7ð ð %@ð	 ð
 &:ð ð ñ ÑˆGš1ñ	 !ð Õ*ˆØÕ0ˆà×4Ñ4¸5ÐQUÐ4ÓV‰ˆàÕ$ˆØ×,Ñ,¨WÓ5ˆØˆ}Ðr.   )rr   rÆ  rÇ  rÅ   r£   r“   r´   rG   s   @@r,   rÁ  rÁ  §  s    ù‡ € ÷Fó F÷(÷ (ò (r.   rÁ  c                   ó`   a a€ ] tR tRt oV3R lV 3R lltR	V3R lR lltR tR tRtVt	V ;t
# )
ÚEdgeTamMaskDecoderià  c                ó    <€ V ^8„  d   QhRS[ /# r  rÃ  )r5   r6   s   "€r,   r7   ÚEdgeTamMaskDecoder.__annotate__á  s   ø€ ÷ '\ñ '\Ñ7ñ '\r.   c                ó*  <€ \         SV `  4        Wn        VP                  V n        VP                  V n        VP                  ^,           V n        \        P                  ! ^V P                  4      V n        \        P                  ! V P
                  V P                  4      V n	        \        V4      V n        \        P                  ! V P                  V P                  ^,          ^^R7      V n        \        P                  ! V P                  ^,          V P                  ^,          ^^R7      V n        \        V P                  ^,          RR7      V n        \        P"                  ! 4       V n        . p\'        V P
                  4       F>  pV\)        V P                  V P                  V P                  ^,          ^4      .,          pK@  	  \        P*                  ! V4      V n        \)        V P                  VP.                  V P
                  VP0                  RR7      V n        \        P4                  ! VP                  VP                  ^,          ^^R7      V n        \        P4                  ! VP                  VP                  ^,          ^^R7      V n        \        P                  ! ^V P                  4      V n        \)        V P                  V P                  ^^4      V n        VP>                  V n        VP@                  V n         VPB                  V n!        R# )r   r|  r$   r=   T)r»   N)"r%   r&   rr   rs   Únum_multimask_outputsÚnum_mask_tokensr[   r�  Ú	iou_tokenÚmask_tokensrÁ  ÚtransformerÚConvTranspose2dÚupscale_conv1Úupscale_conv2r   Úupscale_layer_normÚGELUrº   rÄ   r¡   rÃ   Úoutput_hypernetworks_mlpsÚiou_head_hidden_dimÚiou_head_depthÚiou_prediction_headr-  Úconv_s0Úconv_s1Úobj_score_tokenÚpred_obj_score_headÚdynamic_multimask_via_stabilityÚ!dynamic_multimask_stability_deltaÚ"dynamic_multimask_stability_thresh)r(   rr   Ú	mlps_listr°   r+   s   &&  €r,   r&   ÚEdgeTamMaskDecoder.__init__á  sY  ø€ Ü‰ÑÔØŒØ!×-Ñ-ˆÔà%+×%AÑ%AˆÔ"Ø%×;Ñ;¸aÕ?ˆÔäŸš a¨×)9Ñ)9Ó:ˆŒÜŸ<š<¨×(<Ñ(<¸d×>NÑ>NÓOˆÔä3°FÓ;ˆÔô  ×/Ò/°×0@Ñ0@À$×BRÑBRÐVWÕBWÐefÐopÔqˆÔÜ×/Ò/°×0@Ñ0@ÀAÕ0EÀt×GWÑGWÐ[\ÕG\ÐjkÐtuÔvˆÔÜ"2°4×3CÑ3CÀqÕ3HÐVfÔ"gˆÔÜŸ'š'›)ˆŒàˆ	Ü�t×+Ñ+Ö,ˆAØÔ,¨T×-=Ñ-=¸t×?OÑ?OÐQU×QaÑQaÐefÕQfÐhiÓjÐkÕkŠIñ -ä)+¯ª°yÓ)AˆÔ&Ü#5Ø×ÑØ×&Ñ&Ø× Ñ Ø×!Ñ!Øô$
ˆÔ ô —y’y ×!3Ñ!3°V×5GÑ5GÈ1Õ5LÐZ[ÐdeÔfˆŒÜ—y’y ×!3Ñ!3°V×5GÑ5GÈ1Õ5LÐZ[ÐdeÔfˆŒä!Ÿ|š|¨A¨t×/?Ñ/?Ó@ˆÔÜ#5°d×6FÑ6FÈ×HXÑHXÐZ[Ð]^Ó#_ˆÔ à/5×/UÑ/UˆÔ,Ø17×1YÑ1YˆÔ.Ø28×2[Ñ2[ˆÖ/r.   c                óŒ  <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  RS[RS[S[ P                  ,          RS[ P                  R,          R	S[ P                  R,          R
S[S[,          RS[S[ P                  S[ P                  S[ P                  S[ P                  3,          /
# )r0   r`  rÊ  Úsparse_prompt_embeddingsÚdense_prompt_embeddingsÚmultimask_outputÚhigh_resolution_featuresr€   NrÌ  r*   r2   )r4   r   r˜   Úlistr   r   r�   )r5   r6   s   "€r,   r7   rÑ  
  sÖ   ø€ ÷ mDñ mDáŸ,™,ðmDñ &+§\¡\ðmDñ #(§,¡,ð	mDñ
 "'§¡ðmDñ ðmDñ #'¡u§|¡|Õ"4ðmDñ $Ÿl™l¨TÕ1ðmDñ  Ÿ,™,¨Õ-ðmDñ Ñ+Õ,ðmDñ 
‰u�|‰|™UŸ\™\©5¯<©<¹¿¹ÐEÕ	FñmDr.   c	                ó*  € VP                   w  r«rÍVP                   ^,          p\        P                  ! V P                  P                  V P
                  P                  V P                  P                  .^ R7      pVP                  W®^^4      pVP                   ^ ,          ^ 8w  d   \        P                  ! Wó3^R7      pMTpVP                  V P
                  P                  P                  4      pW,           pVP                  V^ R7      pVP                  V^ 4      pV P                  ! R	RVRVRVRVRV/V	B w  ppVR
,          pVRR^^V P                  ,           1R3,          pVP                  ^^4      P                  W®,          W¼V4      pVw  ppVP                  V^ R7      pVP                  V^ R7      pV P                  V4      V,           pV P!                  V P#                  V4      4      pV P!                  V P%                  V4      V,           4      p. p\'        V P                  4       F1  pV P(                  V,          pVV! VRRVR3,          4      .,          pK3  	  \        P*                  ! V^R7      pVP                   w  pr¼pVP                  W®W¼V,          4      pVV,          P                  W®RWÍ4      pV P-                  V4      pV P/                  VR,          4      pV'       d(   \1        ^R4      pVRRVRR3,          pVRRV3,          pMlV P2                  '       d5   V P4                  '       g#   \1        ^ ^4      pV P7                  VV4      w  ppM&\1        ^ ^4      pVRRVRR3,          pVRRV3,          pVRRV3,          p VVV V3# )aC  
Predict masks given image and prompt embeddings.

Args:
    image_embeddings (`torch.Tensor`):
        The embeddings from the image encoder.
    image_positional_embeddings (`torch.Tensor`):
        Positional encoding with the shape of image_embeddings.
    sparse_prompt_embeddings (`torch.Tensor`):
        The embeddings of the points and boxes.
    dense_prompt_embeddings (`torch.Tensor`):
        The embeddings of the mask inputs.
    multimask_output (`bool`):
        Whether to return multiple masks or a single mask.
    high_resolution_features (`list[torch.Tensor]`, *optional*):
        The high-resolution features from the vision encoder.
    attention_similarity (`torch.Tensor`, *optional*):
        The attention similarity tensor.
    target_embedding (`torch.Tensor`, *optional*):
        The target embedding.
rÿ   r½  r`  rÊ  r€   rÌ  rü   NrP   r°  rc   r¯  )r‡   r4   r
  rã  r;  rÕ  rÖ  Úrepeatri   r`   Úrepeat_interleaver×  rÔ  re   rˆ   rÙ  rº   rÛ  rÚ  rÄ   rÝ  r  rà  rä  Úslicerå  rb   Ú _dynamic_multimask_via_stability)!r(   r`  rÊ  rë  rì  rí  rî  r€   rÌ  r*   rŽ   Únum_channelsr  r  r�   Úoutput_tokensÚtokensr½  Úiou_token_outÚmask_tokens_outÚfeat_s0Úfeat_s1Úupscaled_embeddingÚhyper_in_listr>  Úcurrent_mlpÚhyper_inr°   r…  Úiou_predr_  Ú
mask_sliceÚsam_tokens_outs!   &&&&&&&&&,                       r,   r;   ÚEdgeTamMaskDecoder.forward
  sÀ  € ðB 3C×2HÑ2HÑ/ˆ
 &Ø3×9Ñ9¸!Õ<ÐäŸ	š	à×$Ñ$×+Ñ+Ø—‘×%Ñ%Ø× Ñ ×'Ñ'ðð
 ô
ˆð &×,Ñ,¨ZÈ1ÈaÓPˆà#×)Ñ)¨!Õ,°Ô1Ü—Y’Y ÐHÈaÔP‰Fà"ˆFØ!Ÿ9™9 T§^¡^×%:Ñ%:×%@Ñ%@ÓAÐð ,ÕEÐØ+×=Ñ=Ð>NÐTUÐ=ÓVÐØ&A×&SÑ&SÐTdÐfgÓ&hÐ#à-1×-=Ò-=ñ .
Ø-ð.
à-ð.
ð )Dð.
ð "6ð	.
ð
 .ð.
ð ñ.
Ñ*ÐÐ*ð )¨Õ4ˆØ*¨1¨a°°a¸$×:NÑ:NÕ6NÐ1OÐQRÐ+RÕSˆð ,×5Ñ5°a¸Ó;×@Ñ@ØÕ)¨<Àó
Ðð 4Ñˆ�Ø×+Ñ+Ð,<À!Ð+ÓDˆØ×+Ñ+Ð,<À!Ð+ÓDˆØ!×/Ñ/Ð0@ÓAÀGÕKÐØ!Ÿ_™_¨T×-DÑ-DÐEWÓ-XÓYÐØ!Ÿ_™_¨T×-?Ñ-?Ð@RÓ-SÐV]Õ-]Ó^Ðà,.ˆÜ�t×+Ñ+Ö,ˆAØ×8Ñ8¸Õ;ˆKØ™k¨/¸!¸QÀÀ1¸*Õ*EÓFÐGÕGŠMñ -ô —;’;˜}°!Ô4ˆà);×)AÑ)AÑ&ˆˆ< Ø/×4Ñ4°ZÐS_ÐjoÕaoÓpÐØÐ.Õ.×4Ñ4°ZÐSUÐW]Óeˆð ×+Ñ+¨MÓ:ˆØ"×6Ñ6Ð7GÈ
Õ7SÓTÐ÷ Ü˜q $›ˆJØ˜!˜Q 
¨A¨qÐ0Õ1ˆEØ  1 jÐ 0Õ1‰HØ×1×1Ð1¸$¿-¿-¸-Ü˜q !›ˆJØ"×CÑCÀEÈ8ÓT‰OˆE‘8ä˜q !›ˆJØ˜!˜Q 
¨A¨qÐ0Õ1ˆEØ  1 jÐ 0Õ1ˆHà(¨¨A¨zÐ)9Õ:ˆà�h Ð0CÐCÐCr.   c                ó$  € VP                  R4      pV P                  p\        P                  ! W8„  RR7      P	                  4       p\        P                  ! W) 8„  RR7      P	                  4       p\        P
                  ! V^ 8„  W4,          R4      pV# )zb
Compute stability scores of the mask logits based on the IoU between upper and
lower thresholds.
rÿ   g      ð?éþÿÿÿrc   )r	  ræ  r4   Úsumr]   r¥  )r(   Úmask_logitsÚstability_deltaÚarea_iÚarea_uÚstability_scoress   &&    r,   Ú_get_stability_scoresÚ(EdgeTamMaskDecoder._get_stability_scoresy  sy   € ð
 "×)Ñ)¨"Ó-ˆØ×@Ñ@ˆÜ—’˜;Ñ8¸bÔA×GÑGÓIˆÜ—’˜;Ð)9Ñ9¸rÔB×HÑHÓJˆÜ Ÿ;š; v°¡z°6µ?ÀCÓHÐØÐr.   c           	     óª  € VR,          pVR,          p\         P                  ! VRR7      pVP                  R4      P                  R4      P                  R4      pVP                  RR^VP	                  R4      VP	                  R4      4      p\         P
                  ! V^V4      p\         P
                  ! V^VP                  R4      4      pVR,          p	VR,          p
V P                  V	4      pW°P                  8¬  p\         P                  ! VR,          P                  V	4      V	V4      p\         P                  ! VP                  V
4      V
V4      pWÞ3# )	aK  
When outputting a single mask, if the stability score from the current single-mask
output (based on output token 0) falls below a threshold, we instead select from
multi-mask outputs (based on output token 1~3) the mask with the highest predicted
IoU score. This is intended to ensure a valid mask for both clicking and tracking.
rÿ   )rü   rü   ºr   NNrü   rü   )rü   rü   r  rc   r  )rü   rü   ºr   r   Nrü   rü   )rü   rü   r  ).NN)
r4   Úargmaxr¨  r  ÚsizeÚgatherr  rç  r¥  r±  )r(   Úall_mask_logitsÚall_iou_scoresÚmultimask_logitsÚmultimask_iou_scoresÚbest_scores_indsÚbest_scores_inds_expandedÚbest_multimask_logitsÚbest_multimask_iou_scoresÚsinglemask_logitsÚsinglemask_iou_scoresr  Ú	is_stableÚmask_logits_outÚiou_scores_outs   &&&            r,   rô  Ú3EdgeTamMaskDecoder._dynamic_multimask_via_stability…  sR  € ð +¨>Õ:ÐØ-¨hÕ7ÐÜ Ÿ<š<Ð(<À"ÔEÐØ$4×$>Ñ$>¸rÓ$B×$LÑ$LÈRÓ$P×$ZÑ$ZÐ[]Ó$^Ð!Ø$=×$DÑ$DØ��AÐ'×,Ñ,¨RÓ0Ð2B×2GÑ2GÈÓ2Kó%
Ð!ô !&§¢Ð-=¸qÐB[Ó \ÐÜ$)§L¢LÐ1EÀqÐJZ×JdÑJdÐegÓJhÓ$iÐ!ð ,¨OÕ<ÐØ .¨yÕ 9ÐØ×5Ñ5Ð6GÓHÐØ$×(OÑ(OÑOˆ	ô  Ÿ+š+Ø�oÕ&×0Ñ0Ð1BÓCØØ!ó
ˆô
 ŸšØ×ÑÐ 5Ó6Ø!Ø%ó
ˆð
 Ð.Ð.r.   )rº   rr   rá  râ  ræ  rç  rå  rs   rà  rÕ  rÖ  rÔ  rÓ  rã  rÝ  rä  r×  rÙ  rÚ  rÛ  )NN)r?   r@   rA   rB   r&   r;   r  rô  rD   rE   rF   rG   s   @@r,   rÏ  rÏ  à  s0   ù‡ € ÷'\ó '\÷RmDò mDò^
 ÷#/ò #/r.   rÏ  z”
    Segment Anything Model 2 (SAM 2) for generating segmentation masks, given an input image and
    input points and labels, boxes, or masks.
    c                   óJ  a a€ ] tR tRt oRtR]! ]^R7      /t/ t. ROt	V3R lV 3R llt
V3R lR lt]P                  ! 4       V3R lR	 l4       t]P                  ! 4       RV3R
 lR ll4       t]]]RV3R lR ll4       4       4       t]]V3R lR l4       4       tRtVtV ;t# )r×   i«  rc  )Úindexc                ó    <€ V ^8„  d   QhRS[ /# r  )r   )r5   r6   s   "€r,   r7   ÚEdgeTamModel.__annotate__À  s   ø€ ÷ ñ ™}ñ r.   c                óŒ  <€ \         SV `  V4       \        VP                  4      V n        \
        P                  ! VP                  4      V n        \        VP                  4      V n
        VP                  VP                  n        \        VP                  4      V n        VP                  P                  V n        VP                  P                   V n        VP                  P"                  V n        \&        P(                  P+                  \&        P,                  ! ^^V P$                  4      4      V n        V P1                  4        R# r�  )r%   r&   rf  Úprompt_encoder_configÚshared_image_embeddingr   rI  Úvision_configÚvision_encoderr‰  Úprompt_encoderrŠ   Úmask_decoder_configrÏ  Úmask_decoderrM  Úbackbone_feature_sizesr(  r¸   r4   r[   Ú	ParameterÚzerosrØ   rN  rO  s   &&€r,   r&   ÚEdgeTamModel.__init__À  sã   ø€ Ü‰Ñ˜Ô Ü&@À×A]ÑA]Ó&^ˆÔ#Ü'×3Ò3°F×4HÑ4HÓIˆÔÜ2°6×3OÑ3OÓPˆÔà:@×:UÑ:Uˆ×"Ñ"Ô7Ü.¨v×/IÑ/IÓJˆÔà"(×"6Ñ"6×"IÑ"IˆÔØ&,×&:Ñ&:×&QÑ&QˆÔ#à ×.Ñ.×>Ñ>ˆŒÜ#(§8¡8×#5Ñ#5´e·k²kÀ!ÀQÈÏÉÓ6XÓ#YˆÔ à�‰Ör.   c                ó4   <€ V ^8„  d   QhRS[ P                  /# )r0   r2   r3   )r5   r6   s   "€r,   r7   r%  Ñ  s   ø€ ÷ Bñ B±e·l±lñ Br.   c                ó  € V P                   P                  pV P                  P                  P                  pV P                  P                  P
                  p\        P                  ! WVR 7      pVP                  ^ R7      R,
          pVP                  ^R7      R,
          pWQ^ ,          ,          pWa^,          ,          pV P                  \        P                  ! We.RR7      4      pVP                  ^^ ^4      P                  ^ 4      # ))r÷   r`   rÿ   r   rc   )r+  r”  r(  rÓ   r÷   r`   r4   Úonesr  r  r:   r¨  )r(   r  Útarget_deviceÚtarget_dtypeÚgridr  r  rÓ   s   &       r,   Ú$get_image_wide_positional_embeddingsÚ1EdgeTamModel.get_image_wide_positional_embeddingsÑ  sÓ   € Ø×"Ñ"×7Ñ7ˆØ×3Ñ3×HÑH×OÑOˆØ×2Ñ2×GÑG×MÑMˆÜ�zŠz˜$¸LÔIˆØ—+‘+ !�+Ó$ sÕ*ˆØ—+‘+ !�+Ó$ sÕ*ˆØ �GÕ#ˆØ �GÕ#ˆà#×:Ñ:¼5¿;º;ÈÐGYÐ_aÔ;bÓcÐØ#×+Ñ+¨A¨q°!Ó4×>Ñ>¸qÓAÐAr.   c                ót   <€ V ^8„  d   QhRS[ P                  RS[S[,          RS[S[ P
                  ,          /# ©r0   rÑ   r*   r2   )r4   rN   r   r   rï  r   )r5   r6   s   "€r,   r7   r%  ß  s>   ø€ ÷  ñ  á×'Ñ'ð ñ Ñ+Õ,ð ñ 
‰e�l‰lÕ	ñ	 r.   c           	     óL  € VP                   ^ ,          pV P                  ! V3RR/VB pVP                  pVR,          V P                  ,           VR&   \	        WPP
                  4       UUu. uF+  w  rgVP                  ^^^ 4      P                  ! VR.VO5!  NK-  	  pppV# u uppi )zÕ
Returns the image embeddings by passing the pixel values through the vision encoder.

Args:
    pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
        Input pixel values
Úreturn_dictTrc   )r‡   Úget_image_featuresrL   rØ   Úzipr.  r:   rˆ   )	r(   rÑ   r*   rŽ   Úimage_outputsÚfeature_mapsÚfeatÚ	feat_sizer`  s	   &&,      r,   Úget_image_embeddingsÚ!EdgeTamModel.get_image_embeddingsÞ  s±   € ð "×'Ñ'¨Õ*ˆ
Ø×/Ò/°ÑYÈ$ÐYÐRXÑYˆØ$×6Ñ6ˆð (¨Õ+¨d×.FÑ.FÕFˆ�RÑô
 $' |×5PÑ5PÔ#Qô
á#Q‘�ð �L‰L˜˜A˜qÓ!×&Ò& z°2ÐB¸	ÖBÙ#Qð 	ñ 
ð
  Ðùó
s   Á*1B c          	      óº   <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          /# )r0   r·  Nr¸  r¹  rº  )r4   rN   Ú
LongTensor)r5   r6   s   "€r,   r7   r%  û  s_   ø€ ÷ ñ á×'Ñ'¨$Õ.ðñ ×&Ñ&¨Õ-ðñ ×&Ñ&¨Õ-ð	ñ
 ×%Ñ%¨Õ,ñr.   c                ó0   € V P                  VVVVR7      pV# )a˜  
Returns the prompt embeddings by passing the input points, labels, boxes and masks through the prompt encoder.

Args:
    input_points (`torch.FloatTensor` of shape `(batch_size, point_batch_size, num_points_per_image, 2)`):
        Optional input points for the prompt encoder. The padding of the point is automatically done by the
        processor. `point_batch_size` refers to the number of masks that we want the model to predict per
        point. The model will output `point_batch_size` times 3 masks in total.
    input_labels (`torch.LongTensor` of shape `(batch_size, point_batch_size, num_points_per_image)`):
        Optional input labels for the prompt encoder. The padding of the labels is automatically done by the
        processor, or can be fed by the user.
    input_boxes (`torch.FloatTensor` of shape `(batch_size, num_boxes_per_image, 4)`):
        Optional input boxes for the prompt encoder. The padding of the boxes is automatically done by the
        processor. users can also pass manually the input boxes.
    input_masks (`torch.LongTensor` of shape `(batch_size, image_size, image_size)`):
        Optional input masks for the prompt encoder.
©r·  r¸  r¹  rº  )r+  )r(   r·  r¸  r¹  rº  Úprompt_outputs   &&&&& r,   Úget_prompt_embeddingsÚ"EdgeTamModel.get_prompt_embeddingsú  s-   € ð2 ×+Ñ+Ø%Ø%Ø#Ø#ð	 ,ó 
ˆð Ðr.   c                ó|  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R	S[ P                  R,          R
S[ P                  R,          RS[S[,          RS[/# )r0   rÑ   Nr·  r¸  r¹  rº  r`  rí  r€   rÌ  r*   r2   )r4   rN   rG  r˜   r   r   r[  )r5   r6   s   "€r,   r7   r%    sä   ø€ ÷ m
ñ m
á×'Ñ'¨$Õ.ðm
ñ ×'Ñ'¨$Õ.ðm
ñ ×&Ñ&¨Õ-ð	m
ñ
 ×&Ñ&¨Õ-ðm
ñ ×%Ñ%¨Õ,ðm
ñ  ×+Ñ+¨dÕ2ðm
ñ ðm
ñ $×/Ñ/°$Õ6ðm
ñ  ×+Ñ+¨dÕ2ðm
ñ Ñ+Õ,ðm
ñ 
(ñm
r.   c
                óP  € VRJ VRJ ,          '       g   \        R4      hVeb   Ve^   VP                  ^,          VP                  ^,          8w  d5   \        RVP                  ^,           RVP                  ^,           R24      hV P                  4       pVe   VP                  ^ ,          MVR,          P                  ^ ,          pVP                  V^^^4      pRpRpVe¥   V P                  ! V3RR/V
B pVP
                  pVP                  pVP                  pVR,          V P                  ,           VR&   \        VV P                  4       UUu. uF,  w  ppVP                  ^^^ 4      P                  ! VR.VO5!  NK.  	  pppVe=   Vf9   \        P                  ! VR,          \        P                  VP                   R7      pVf~   Vfz   \        P"                  ! V^^^VR,          P$                  VR,          P                   R7      p\        P&                  ! V^^\        P(                  VR,          P                   R7      ) pVe   VP                  RR V P*                  P,                  8w  dW   \.        P0                  ! VP3                  4       V P*                  P,                  R	R
RR7      P5                  VP$                  4      pV P+                  VVVVR7      w  ppV P6                  ! RRVR,          RVRVRVRVRVRR RVRV	/V
B w  pppp\9        VVVVVVR7      # u uppi )aÂ  
input_points (`torch.FloatTensor` of shape `(batch_size, num_points, 2)`):
    Input 2D spatial points, this is used by the prompt encoder to encode the prompt. Generally yields to much
    better results. The points can be obtained by passing a list of list of list to the processor that will
    create corresponding `torch` tensors of dimension 4. The first dimension is the image batch size, the
    second dimension is the point batch size (i.e. how many segmentation masks do we want the model to predict
    per input point), the third dimension is the number of points per segmentation mask (it is possible to pass
    multiple points for a single mask), and the last dimension is the x (vertical) and y (horizontal)
    coordinates of the point. If a different number of points is passed either for each image, or for each
    mask, the processor will create "PAD" points that will correspond to the (0, 0) coordinate, and the
    computation of the embedding will be skipped for these points using the labels.
input_labels (`torch.LongTensor` of shape `(batch_size, point_batch_size, num_points)`):
    Input labels for the points, this is used by the prompt encoder to encode the prompt. According to the
    official implementation, there are 3 types of labels

    - `1`: the point is a point that contains the object of interest
    - `0`: the point is a point that does not contain the object of interest
    - `-1`: the point corresponds to the background

    We added the label:

    - `-10`: the point is a padding point, thus should be ignored by the prompt encoder

    The padding labels should be automatically done by the processor.
input_boxes (`torch.FloatTensor` of shape `(batch_size, num_boxes, 4)`):
    Input boxes for the points, this is used by the prompt encoder to encode the prompt. Generally yields to
    much better generated masks. The boxes can be obtained by passing a list of list of list to the processor,
    that will generate a `torch` tensor, with each dimension corresponding respectively to the image batch
    size, the number of boxes per image and the coordinates of the top left and bottom right point of the box.
    In the order (`x1`, `y1`, `x2`, `y2`):

    - `x1`: the x coordinate of the top left point of the input box
    - `y1`: the y coordinate of the top left point of the input box
    - `x2`: the x coordinate of the bottom right point of the input box
    - `y2`: the y coordinate of the bottom right point of the input box
input_masks (`torch.FloatTensor` of shape `(batch_size, image_size, image_size)`):
    SAM model also accepts segmentation masks as input. The mask will be embedded by the prompt encoder to
    generate a corresponding embedding, that will be fed later on to the mask decoder. These masks needs to be
    manually fed by the user, and they need to be of shape (`batch_size`, `image_size`, `image_size`).
image_embeddings (`torch.FloatTensor` of shape `(batch_size, output_channels, window_size, window_size)`):
    Image embeddings, this is used by the mask decoder to generate masks and iou scores. For more memory
    efficient computation, users can first retrieve the image embeddings using the `get_image_embeddings`
    method, and then feed them to the `forward` method instead of feeding the `pixel_values`.
multimask_output (`bool`, *optional*):
    In the original implementation and paper, the model always outputs 3 masks per image (or per point / per
    bounding box if relevant). However, it is possible to just output a single mask, that corresponds to the
    "best" mask, by specifying `multimask_output=False`.
attention_similarity (`torch.FloatTensor`, *optional*):
    Attention similarity tensor, to be provided to the mask decoder for target-guided attention in case the
    model is used for personalization as introduced in [PerSAM](https://huggingface.co/papers/2305.03048).
target_embedding (`torch.FloatTensor`, *optional*):
    Embedding of the target concept, to be provided to the mask decoder for target-semantic prompting in case
    the model is used for personalization as introduced in [PerSAM](https://huggingface.co/papers/2305.03048).

Example:

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

>>> model = AutoModel.from_pretrained("danelcsb/edgetam.1_hiera_tiny")
>>> processor = AutoProcessor.from_pretrained("danelcsb/edgetam.1_hiera_tiny")

>>> url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/sam-car.png"
>>> with httpx.stream("GET", url) as response:
...     raw_image = Image.open(BytesIO(response.read())).convert("RGB")
>>> input_points = [[[400, 650]]]  # 2D location of a window on the car
>>> inputs = processor(images=raw_image, input_points=input_points, return_tensors="pt")

>>> # Get segmentation mask
>>> outputs = model(**inputs)

>>> # Postprocess masks
>>> masks = processor.post_process_masks(
...     outputs.pred_masks, inputs["original_sizes"]
... )
```
NzAExactly one of pixel_values or image_embeddings must be provided.zGYou should provide as many bounding boxes as input points per box. Got z and Ú.r=  Trû   FÚbilinear)r  r8  r7  r9  rI  r`  rÊ  rë  rì  rí  rî  r€   rÌ  )r]  r^  r_  r`  ra  rb  rc   ro  r  rP   )rñ   r‡   r8  rñ  r>  rL   rÊ   Ú
attentionsrØ   r?  r.  r:   rˆ   r4   Ú	ones_liker¼   r÷   r0  r`   r4  Úint32r+  r•  rÈ   r<  r]   ri   r-  r[  )r(   rÑ   r·  r¸  r¹  rº  r`  rí  r€   rÌ  r*   rÊ  rŽ   rb  ra  r@  rA  rB  rC  r¼  r†  Úlow_res_multimasksr]  r°   r_  s   &&&&&&&&&&,              r,   r;   ÚEdgeTamModel.forward  s°  € ð@  Ð%Ð*:¸dÐ*B×CÔCÜÐ`ÓaÐaØÒ#¨Ò(?Ø×!Ñ! !Õ$¨×(9Ñ(9¸!Õ(<Ô<Ü Ø]Ð^j×^pÑ^pÐqrÕ^sÐ]tÐtyð  {F÷  {Lñ  {Lð  MNõ  {Oð  zPð  PQð  Róð ð '+×&OÑ&OÓ&QÐ#à.:Ò.F�\×'Ñ'¨Ö*ÐL\Ð]_ÕL`×LfÑLfÐghÕLiˆ
Ø&A×&HÑ&HÈÐUVÐXYÐ[\Ó&]Ð#à ÐØ#ÐàÒ#Ø8<×8OÒ8OØñ9Ø*.ð9Ø28ñ9ˆMð )×:Ñ:ˆLØ#0×#>Ñ#>Ð Ø -× 8Ñ 8Ðð  ,¨BÕ/°$×2JÑ2JÕJˆL˜Ñô
 (+¨<¸×9TÑ9TÔ'Uô á'U‘O�D˜)ð —‘˜Q  1Ó%×*Ò*¨:°rÐF¸IÖFÙ'Uð ñ  ð
 Ò#¨Ò(<Ü Ÿ?š?¨<¸
Õ+CÌ5Ï9É9Ð]i×]pÑ]pÔqˆLàÒ KÒ$7ä Ÿ;š;Ø˜A˜q !Ð+;¸BÕ+?×+EÑ+EÐN^Ð_aÕNb×NiÑNiôˆLô "ŸJšJ z°1°a¼u¿{¹{ÐScÐdfÕSg×SnÑSnÔoÐoˆLàÒ"ð × Ñ   Ð%¨×)<Ñ)<×)LÑ)LÔLÜŸmšmØ×%Ñ%Ó'Ø×,Ñ,×<Ñ<Ø"'Ø#Ø"ô÷ ‘"�[×&Ñ&Ó'ð ð /3×.AÑ.AØ%Ø%Ø#Ø#ð	 /Bó /
Ñ+ÐÐ+ð BF×ARÒARñ 
B
Ø-¨bÕ1ð
B
à(Cð
B
ð &7ð
B
ð %5ð	
B
ð
 .ð
B
ð &6°c°rÐ%:ð
B
ð "6ð
B
ð .ð
B
ð ñ
B
Ñ>Ð˜J¨Ð+>ô .Ø!Ø)Ø 3Ø-Ø!5Ø/ô
ð 	
ùó[ s   Å2L"c                ó`   <€ V ^8„  d   QhRS[ P                  RS[S[,          RS[S[,          /# r;  rR  )r5   r6   s   "€r,   r7   r%  Ï  s;   ø€ ÷ ñ á×'Ñ'ðñ Ñ+Õ,ðñ 
Ñ+Õ	+ñ	r.   c                óú  € V P                   ! V3RR/VB pVP                  pVP                  p\        V4      pV P                  P                  V^ ,          4      V^ &   V P                  P                  V^,          4      V^&   V Uu. uF$  qfP                  ^4      P                  ^^ ^4      NK&  	  ppV Uu. uF%  pVP                  ^4      P                  ^^ ^4      NK'  	  uppWCn        WSn        V# u upi u upi )zr
pixel_values (`torch.FloatTensor`):
    Input pixel values of shape `(batch_size, num_channels, height, width)`.
r=  T)	r*  rL   rM   rï  r-  rá  râ  r	  r:   )r(   rÑ   r*   Úvision_outputsrA  Ú feature_maps_position_embeddingsÚfeature_maps   &&,    r,   r>  ÚEdgeTamModel.get_image_featuresÍ  s  € ð 6:×5HÒ5HÈÑ5rÐcgÐ5rÐkqÑ5rˆà%×7Ñ7ˆØ+9×+OÑ+OÐ(ô ˜LÓ)ˆØ×+Ñ+×3Ñ3°LÀµOÓDˆ�Q‰Ø×+Ñ+×3Ñ3°LÀµOÓDˆ�Q‰ñ T`Ó`ÑS_ÀK×+Ñ+¨AÓ.×6Ñ6°q¸!¸QÖ?ÑS_ˆÐ`ñ 5Uó,
á4TÐ0ð -×4Ñ4°QÓ7×?Ñ?ÀÀ1ÀaÖHÙ4Tñ,
Ð(ð ,8Ô(Ø/OÔ,àÐùò aùò,
s   Â*C3Â7+C8)r.  r¸   r-  rØ   rM  r+  r(  r*  )rß   Útext)z
^memory_.*z^mask_downsample.*zspatial_perceiver.*z^object_pointer_proj.*z0^temporal_positional_encoding_projection_layer.*Úno_memory_positional_encodingÚno_object_pointerÚ%occlusion_spatial_embedding_parameter)NNNN)	NNNNNNTNN)r?   r@   rA   rB   rã   r   r•   rY  Ú_tied_weights_keysrç   r&   r8  r4   rè   rD  rK  r   r   r   r;   r   r>  rD   rE   rF   rG   s   @@r,   r×   r×   «  sÍ   ù‡ € ð )ÐØ4±nÐE`ÐhiÔ6jÐkÐØÐò	*Ð&÷ó ÷"Bð Bð ‡]‚]ƒ_÷ ó ð ð6 ‡]‚]ƒ_÷ñ ó ðð@  ØØ÷m
ñ m
ó ó ó  ðm
ð^ Ø÷ó ó ÷ð r.   r×   )r†   )r×   rE  rÏ   )Irò   Úcollections.abcr   Údataclassesr   Únumpyrq  r4   Útorch.nnr[   Útorch.nn.functionalrf   rÈ   r   Ú r   rÙ   Úactivationsr   Úmodeling_layersr   Úmodeling_outputsr	   r
   Úmodeling_utilsr   r   Úprocessing_utilsr   Úpytorch_utilsr   Úutilsr   r   r   r   Úutils.genericr   r   r   Úutils.output_capturingr   r   Úautor   Úconfiguration_edgetamr   r   r   r   Ú
get_loggerr?   r‹   r�   r   rJ   rm   r\   ro   r•   r¡   rÏ   rê   r  rE  r[  rf  rw  r‰  rÁ  rÏ  r×   Ú__all__rP   r.   r,   Ú<module>rt     sú  ðó* Ý $Ý !ã Û Ý ß Ð Ý å &Ý !Ý 9ß Kß FÝ &Ý @ß KÓ Kß iÑ iß EÝ ÷ó ð 
×	Ò	˜HÓ	%€ô�r—|‘|ô ñ4 ÐKÔLØ
ô;Ð!;ó ;ó ó Mð;÷ %ô,D)�r—y‘yô D)ôNJ'Ð"<ô J'ôZ˜Ÿ™ô ð< ôH˜_ó Hó ðHô(J
 2§9¡9ô J
ôZ18˜Ÿ	™	ô 18ñh ðôô
+
Ð/ó +
óð
+
ñ\ ÐIÔJØ
ôI [ó Ió ó KðIô@S §¡ô Sô2 ˜2Ÿ9™9ô  ô6\3˜2Ÿ9™9ô \3ô~6˜rŸy™yô 6ôrH/˜Ÿ™ô H/ñV ðôô{Ð)ó {óð{ò|	 K‚r.   