+
    œ°³jL  ã                   óà  € R t ^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^RIHtHtHt ]P                  ! ]4      tR R	 ltR
 R ltR R lt]! RR7      ] ! R R]4      4       4       t ! R R]P,                  4      t ! R R]P,                  4      t ! R R]P,                  4      t ! R R]P,                  4      t] ! R R]4      4       t]! RR7       ! R R]4      4       tRR.tR# )zPyTorch SuperPoint model.)Ú	dataclassN)Únn)ÚPreTrainedModel)ÚBaseModelOutputWithNoAttention©ÚSuperPointConfig)ÚModelOutputÚauto_docstringÚloggingc                óÒ   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        R\        R\        \         P                  \         P                  3,          /# )é   Ú	keypointsÚscoresÚborderÚheightÚwidthÚreturn©ÚtorchÚTensorÚintÚtuple)Úformats   "Ús/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/superpoint/modeling_superpoint.pyÚ__annotate__r   %   sV   € ÷ )ñ )Ü�|‰|ð)Ü%*§\¡\ð)Ü;>ð)ÜHKð)ÜTWð)ä
Œ5�<‰<œŸ™Ð%Õ&ñ)ó    c                ó¾   € V R,          V8¬  V R,          W2,
          8  ,          pV R,          V8¬  V R,          WB,
          8  ,          pWV,          pW,          W,          3# )zPRemoves keypoints (and their associated scores) that are too close to the border)ºNNNé    )r   é   © )r   r   r   r   r   Úmask_hÚmask_wÚmasks   &&&&&   r   Úremove_keypoints_from_bordersr$   %   sV   € ð ˜�o Ñ'¨I°d­O¸v½Ñ,OÕP€FØ˜�o Ñ'¨I°d­O¸u½~Ñ,NÕO€FØ�?€DØ�?˜F�LÐ(Ð(r   c          
      óº   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        \         P                  \         P                  3,          /# )r   r   r   Úkr   r   )r   s   "r   r   r   /   sH   € ÷ &ñ &œuŸ|™|ð &´U·\±\ð &Äcð &ÌeÔTY×T`ÑT`Ôbg×bnÑbnÐTnÕNoñ &r   c                óp   € V\        V 4      8¼  d   W3# \        P                  ! W^ R7      w  rW,          V3# )z(Keeps the k keypoints with highest score)Údim)Úlenr   Útopk)r   r   r&   Úindicess   &&& r   Útop_k_keypointsr,   /   s7   € àŒC�	‹NÔØÐ Ð Ü—j’j °Ô2�O€FØÕ˜vÐ%Ð%r   c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r   r   Ú
nms_radiusr   )r   r   r   )r   s   "r   r   r   7   s)   € ÷ 0ñ 0”u—|‘|ð 0´ð 0¼¿¹ñ 0r   c                óZ  a€ S^ 8  d   \        R4      hV3R lp\        P                  ! V 4      pW! V 4      8H  p\        ^4       FM  pV! VP	                  4       4      ^ 8„  p\        P
                  ! WcV 4      pWr! V4      8H  pWHV( ,          ,          pKO  	  \        P
                  ! W@V4      # )z)Applies non-maximum suppression on scoresz'Expected positive values for nms_radiusc                 óf   <€ \         P                  P                  V S^,          ^,           ^SR7      # )r   ©Úkernel_sizeÚstrideÚpadding)r   Ú
functionalÚ
max_pool2d)Úxr.   s   &€r   Úmax_poolÚsimple_nms.<locals>.max_pool<   s,   ø€ Ü�}‰}×'Ñ'¨°zÀAµ~ÈÕ7IÐRSÐ]gÐ'ÓhÐhr   )Ú
ValueErrorr   Ú
zeros_likeÚrangeÚfloatÚwhere)	r   r.   r8   ÚzerosÚmax_maskÚ_Ú	supp_maskÚsupp_scoresÚnew_max_masks	   &f       r   Ú
simple_nmsrE   7   s¢   ø€ à�A„~ÜÐBÓCÐCõiô ×Ò˜VÓ$€EØ˜ &Ó)Ñ)€HÜ�1ŽXˆÙ˜XŸ^™^Ó-Ó.°Ñ2ˆ	Ü—k’k )°FÓ;ˆØ" h¨{Ó&;Ñ;ˆØ°	¨zÕ:Õ;Šñ	 ô
 �;Š;�x¨Ó/Ð/r   aù  
    Base class for outputs of image point description models. Due to the nature of keypoint detection, the number of
    keypoints is not fixed and can vary from image to image, which makes batching non-trivial. In the batch of images,
    the maximum number of keypoints is set as the dimension of the keypoints, scores and descriptors tensors. The mask
    tensor is used to indicate which values in the keypoints, scores and descriptors tensors are keypoint information
    and which are padding.
    )Úcustom_introc                   óH   a € ] tR t^It o RtRtRtRtRtRt	Rt
V 3R ltRtV tR# )Ú#SuperPointKeypointDescriptionOutputa8  
loss (`torch.FloatTensor` of shape `(1,)`, *optional*):
    Loss computed during training.
keypoints (`torch.FloatTensor` of shape `(batch_size, num_keypoints, 2)`):
    Relative (x, y) coordinates of predicted keypoints in a given image.
scores (`torch.FloatTensor` of shape `(batch_size, num_keypoints)`):
    Scores of predicted keypoints.
descriptors (`torch.FloatTensor` of shape `(batch_size, num_keypoints, descriptor_size)`):
    Descriptors of predicted keypoints.
mask (`torch.BoolTensor` of shape `(batch_size, num_keypoints)`):
    Mask indicating which values in keypoints, scores and descriptors are keypoint information.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or
when `config.output_hidden_states=True`):
    Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
    one for the output of each stage) of shape `(batch_size, sequence_length, hidden_size)`. Hidden-states
    (also called feature maps) of the model at the output of each stage.
Nc                ó>  <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[S[ P                  ,          R,          ;R&   # )r   NÚlossr   r   Údescriptorsr#   Úhidden_states)r   ÚFloatTensorÚ	IntTensorÚ
BoolTensorr   )r   Ú__classdict__s   "€r   r   Ú0SuperPointKeypointDescriptionOutput.__annotate__I   sž   ø‡ ‚ ñ: ×
Ñ
˜dÕ
"Ñ)ñ; ñ< �‰ Õ%Ñ,ñ= ñ> ×Ñ Õ$Ñ+ñ? ñ@ ×"Ñ" TÕ)Ñ0ñA ñB ×
Ñ
˜TÕ
!Ñ(ñC ñD ™×*Ñ*Õ+¨dÕ2Ñ9òE r   r    )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rJ   r   r   rK   r#   rL   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©rP   s   @r   rH   rH   I   s2   ø‡ € ñð$ &*€DØ(,€IØ'+€FØ,0€KØ$(€DØ59€M÷E ƒ r   rH   c                   óT   a a€ ] tR t^nt 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# )ÚSuperPointConvBlockc          
      ó6   <€ V ^8„  d   QhRS[ RS[RS[RS[RR/# )r   ÚconfigÚin_channelsÚout_channelsÚadd_poolingr   N)r   r   Úbool)r   rP   s   "€r   r   Ú SuperPointConvBlock.__annotate__o   s<   ø€ ÷ Sñ SÙ&ðSÙ58ðSÙHKðSÙZ^ðSà	ñSr   c                ó8  <€ \         SV `  4        \        P                  ! VV^^^R7      V n        \        P                  ! VV^^^R7      V n        \        P                  ! RR7      V n        V'       d    \        P                  ! ^^R7      V n	        R# RV n	        R# )é   r1   T©Úinplace©r2   r3   N)
ÚsuperÚ__init__r   ÚConv2dÚconv_aÚconv_bÚReLUÚreluÚ	MaxPool2dÚpool)Úselfr^   r_   r`   ra   Ú	__class__s   &&&&&€r   rj   ÚSuperPointConvBlock.__init__o   s|   ø€ ô 	‰ÑÔÜ—i’iØØØØØô
ˆŒô —i’iØØØØØô
ˆŒô —G’G DÔ)ˆŒ	ß=H”B—L’L¨Q°qÔ9ˆŽ	ÈdˆŽ	r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   rL   r   ©r   r   )r   rP   s   "€r   r   rc   „   s#   ø€ ÷ ñ ¡U§\¡\ð ±e·l±lñ r   c                óÄ   € V P                  V P                  V4      4      pV P                  V P                  V4      4      pV P                  e   V P                  V4      pV# ©N)ro   rl   rm   rq   )rr   rL   s   &&r   ÚforwardÚSuperPointConvBlock.forward„   sN   € ØŸ	™	 $§+¡+¨mÓ"<Ó=ˆØŸ	™	 $§+¡+¨mÓ"<Ó=ˆØ�9‰9Ò Ø ŸI™I mÓ4ˆMØÐr   )rl   rm   rq   ro   )F)	rR   rS   rT   rU   rj   ry   rX   rY   Ú__classcell__©rs   rP   s   @@r   r\   r\   n   s    ù‡ € ÷Sõ S÷*÷ ð r   r\   c                   óX   a a€ ] tR t^Œt oRt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	# )ÚSuperPointEncoderz’
SuperPoint encoder module. It is made of 4 convolutional layers with ReLU activation and max pooling, reducing the
 dimensionality of the image.
c                ó$   <€ V ^8„  d   QhRS[ RR/# ©r   r^   r   Nr   )r   rP   s   "€r   r   ÚSuperPointEncoder.__annotate__’   s   ø€ ÷ 6ñ 6Ñ/ð 6°Dñ 6r   c           
     ó@  <€ \         SV `  4        ^V n        . pVP                  \	        WP                  VP
                  ^ ,          RR7      4       \        ^\        VP
                  4      ^,
          4       FI  pVP                  \	        WP
                  V^,
          ,          VP
                  V,          RR7      4       KK  	  VP                  \	        WP
                  R,          VP
                  R,          RR7      4       \        P                  ! V4      V n
        R# )r   T)ra   FNéþÿÿÿéÿÿÿÿ)ri   rj   Ú	input_dimÚappendr\   Úencoder_hidden_sizesr<   r)   r   Ú
ModuleListÚconv_blocks)rr   r^   r‰   Úirs   s   &&  €r   rj   ÚSuperPointEncoder.__init__’   sì   ø€ Ü‰ÑÔàˆŒàˆØ×ÑÜ ¯©¸×8SÑ8SÐTUÕ8VÐdhÔiô	
ô �qœ#˜f×9Ñ9Ó:¸QÕ>Ö?ˆAØ×ÑÜ#Ø×7Ñ7¸¸A½Õ>À×@[Ñ@[Ð\]Õ@^Ðlpôöñ @ð 	×ÑÜØ×3Ñ3°BÕ7¸×9TÑ9TÐUWÕ9XÐfkôô	
ô
 Ÿ=š=¨Ó5ˆÖr   c                óX   <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[S[,          /# )r   Úoutput_hidden_statesNÚreturn_dictr   )rb   r   r   )r   rP   s   "€r   r   r�   ¨   s9   ø€ ÷ 
ñ 
ñ # T�kð
ñ ˜D•[ð	
ñ
 
Ñ/Õ	/ñ
r   c                ó   € V'       d   RMR pV P                    F  pV! V4      pV'       g   K  WA3,           pK   	  TpV'       g/   \        ;QJ d    . R Wd3 4       F  NK  	  5# ! R Wd3 4       4      # \        VVR7      # )Nc              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5irx   r    ©Ú.0Úvs   & r   Ú	<genexpr>Ú,SuperPointEncoder.forward.<locals>.<genexpr>¶   s   é € ÐQÑ$?˜qŸšÓ$?ùó   ‚Œ
)Úlast_hidden_staterL   r    )r‰   r   r   )rr   Úinputr�   rŽ   Úall_hidden_statesÚ
conv_blockÚoutputs   &&&&   r   ry   ÚSuperPointEncoder.forward¨   s~   € ÷ #7™B¸DÐà×*Ô*ˆJÙ˜uÓ%ˆEß#Ñ#Ø$5¸Õ$@Ò!ñ +ð ˆßß”5ÑQ VÑ$?ÓQ—5ÐQ�5ÑQ VÑ$?ÓQÓQÐQä-Ø$Ø+ô
ð 	
r   )r‰   r…   )FT)
rR   rS   rT   rU   rV   rj   ry   rX   rY   r{   r|   s   @@r   r~   r~   Œ   s#   ù‡ € ñ÷
6ó 6÷,
÷ 
ò 
r   r~   c                   óx   a a€ ] tR t^¾t oRt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# )ÚSuperPointInterestPointDecoderaú  
The SuperPointInterestPointDecoder uses the output of the SuperPointEncoder to compute the keypoint with scores.
The scores are first computed by a convolutional layer, then a softmax is applied to get a probability distribution
over the 65 possible keypoint classes. The keypoints are then extracted from the scores by thresholding and
non-maximum suppression. Post-processing is then applied to remove keypoints too close to the image borders as well
as to keep only the k keypoints with highest score.
c                ó$   <€ V ^8„  d   QhRS[ RR/# r€   r   )r   rP   s   "€r   r   Ú+SuperPointInterestPointDecoder.__annotate__Ç   ó   ø€ ÷ 
ñ 
Ñ/ð 
°Dñ 
r   c                óü  <€ \         SV `  4        VP                  V n        VP                  V n        VP                  V n        VP
                  V n        \        P                  ! R R7      V n        \        P                  ! ^^R7      V n
        \        P                  ! VP                  R,          VP                  ^^^R7      V n        \        P                  ! VP                  VP                  ^^^ R7      V n        R# ©Trf   rh   r1   Nr„   )ri   rj   Úkeypoint_thresholdÚmax_keypointsr.   Úborder_removal_distancer   rn   ro   rp   rq   rk   r‡   Údecoder_hidden_sizeÚconv_score_aÚkeypoint_decoder_dimÚconv_score_b©rr   r^   rs   s   &&€r   rj   Ú'SuperPointInterestPointDecoder.__init__Ç   sÅ   ø€ Ü‰ÑÔØ"(×";Ñ";ˆÔØ#×1Ñ1ˆÔØ ×+Ñ+ˆŒØ'-×'EÑ'EˆÔ$ä—G’G DÔ)ˆŒ	Ü—L’L¨Q°qÔ9ˆŒ	ÜŸIšIØ×'Ñ'¨Õ+Ø×&Ñ&ØØØô
ˆÔô ŸIšIØ×&Ñ&¨×(CÑ(CÐQRÐ[\Ðfgô
ˆÖr   c                óx   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  S[ P                  3,          /# ©r   Úencodedr   ©r   r   r   )r   rP   s   "€r   r   r    Û   s1   ø€ ÷ !ñ !™uŸ|™|ð !±±e·l±lÁEÇLÁLÐ6PÕ0Qñ !r   c                óP   € V P                  V4      pV P                  V4      w  r2W23# rx   )Ú_get_pixel_scoresÚ_extract_keypoints)rr   r¯   r   r   s   &&  r   ry   Ú&SuperPointInterestPointDecoder.forwardÛ   s.   € Ø×'Ñ'¨Ó0ˆØ ×3Ñ3°FÓ;Ñˆ	àÐ Ð r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r®   rv   )r   rP   s   "€r   r   r    á   s#   ø€ ÷ 	ñ 	©¯©ð 	¹%¿,¹,ñ 	r   c                ó¸  € V P                  V P                  V4      4      pV P                  V4      p\        P                  P                  V^4      RRR13,          pVP                  w  r4rVVP                  ^ ^^^4      P                  W5V^^4      pVP                  ^ ^^^^4      P                  W5^,          V^,          4      p\        W P                  4      pV# )zKBased on the encoder output, compute the scores for each pixel of the imager   Nr„   )ro   r¨   rª   r   r5   ÚsoftmaxÚshapeÚpermuteÚreshaperE   r.   )rr   r¯   r   Ú
batch_sizerA   r   r   s   &&     r   r²   Ú0SuperPointInterestPointDecoder._get_pixel_scoresá   sÁ   € à—‘˜4×,Ñ,¨WÓ5Ó6ˆØ×"Ñ" 6Ó*ˆÜ—‘×&Ñ& v¨qÓ1°!°S°b°S°&Õ9ˆØ'-§|¡|Ñ$ˆ
�vØ—‘  1 a¨Ó+×3Ñ3°JÈÈqÐRSÓTˆØ—‘  1 a¨¨AÓ.×6Ñ6°zÈAÅ:ÈuÐWXÍyÓYˆÜ˜F§O¡OÓ4ˆØˆr   c                óx   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  S[ P                  3,          /# )r   r   r   r°   )r   rP   s   "€r   r   r    ì   s1   ø€ ÷ !ñ !©¯©ð !¹%ÁÇÁÉeÏlÉlÐ@ZÕ:[ñ !r   c                óÌ  € VP                   w  r#p\        P                  ! V^ ,          V P                  8„  4      pV^ ,          \	        VP                  4       4      ,          p\        WQV P                  V^,          V^,          4      w  rQV P                  ^ 8¼  d   \        WQV P                  4      w  rQ\        P                  ! V^.4      P                  VP                  4      pWQ3# )zµ
Based on their scores, extract the pixels that represent the keypoints that will be used for descriptors computation.
The keypoints are in the form of relative (x, y) coordinates.
)r¸   r   Únonzeror¤   r   Útr$   r¦   r¥   r,   ÚflipÚtoÚdtype)rr   r   rA   r   r   r   s   &&    r   r³   Ú1SuperPointInterestPointDecoder._extract_keypointsì   sÂ   € ð
 "Ÿ<™<Ñˆ�5ô —M’M &¨¥)¨d×.EÑ.EÑ"EÓFˆ	Ø˜•œ5 §¡£Ó/Õ0ˆô :Ø˜t×;Ñ;¸VÀa½ZÈÐQRÍó
Ñˆ	ð
 ×Ñ Ô"Ü /°	À4×CUÑCUÓ VÑˆIô —J’J˜y¨1¨#Ó.×1Ñ1°&·,±,Ó?ˆ	àÐ Ð r   )r¦   r¨   rª   r¤   r¥   r.   rq   ro   )rR   rS   rT   rU   rV   rj   ry   r²   r³   rX   rY   r{   r|   s   @@r   rž   rž   ¾   s7   ù‡ € ñ÷
ó 
÷(!ð !÷	ð 	÷!÷ !ð !r   rž   c                   ót   a a€ ] tR tRt oRtV3R lV 3R lltV3R lR lt]R
V3R lR ll4       tR	t	Vt
V ;t# )ÚSuperPointDescriptorDecoderi  aS  
The SuperPointDescriptorDecoder uses the outputs of both the SuperPointEncoder and the
SuperPointInterestPointDecoder to compute the descriptors at the keypoints locations.

The descriptors are first computed by a convolutional layer, then normalized to have a norm of 1. The descriptors
are then interpolated at the keypoints locations.
c                ó$   <€ V ^8„  d   QhRS[ RR/# r€   r   )r   rP   s   "€r   r   Ú(SuperPointDescriptorDecoder.__annotate__  r¡   r   c                ót  <€ \         SV `  4        \        P                  ! R R7      V n        \        P
                  ! ^^R7      V n        \        P                  ! VP                  R,          VP                  ^^^R7      V n
        \        P                  ! VP                  VP                  ^^^ R7      V n        R# r£   )ri   rj   r   rn   ro   rp   rq   rk   r‡   r§   Úconv_descriptor_aÚdescriptor_decoder_dimÚconv_descriptor_br«   s   &&€r   rj   Ú$SuperPointDescriptorDecoder.__init__  s�   ø€ Ü‰ÑÔä—G’G DÔ)ˆŒ	Ü—L’L¨Q°qÔ9ˆŒ	Ü!#§¢Ø×'Ñ'¨Õ+Ø×&Ñ&ØØØô"
ˆÔô "$§¢Ø×&Ñ&Ø×)Ñ)ØØØô"
ˆÖr   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r   r¯   r   r   rv   )r   rP   s   "€r   r   rÈ   #  s.   ø€ ÷ 
ñ 
™uŸ|™|ð 
¹¿¹ð 
ÉÏÉñ 
r   c                ó6  € V P                  V P                  V P                  V4      4      4      p\        P                  P                  V^^R7      pV P                  VR,          V^ ,          R,          ^4      ^ ,          p\        P                  ! V^ ^4      pV# )zXBased on the encoder output and the keypoints, compute the descriptors for each keypoint©Úpr(   N)	rÌ   ro   rÊ   r   r5   Ú	normalizeÚ_sample_descriptorsr   Ú	transpose)rr   r¯   r   rK   s   &&& r   ry   Ú#SuperPointDescriptorDecoder.forward#  sƒ   € à×,Ñ,¨T¯Y©Y°t×7MÑ7MÈgÓ7VÓ-WÓXˆÜ—m‘m×-Ñ-¨k¸QÀAÐ-ÓFˆà×.Ñ.¨y¸­ÀÈAÅÈtÕ@TÐVWÓXÐYZÕ[ˆô —o’o k°1°aÓ8ˆàÐr   c                ó:   <€ V ^8„  d   QhRS[ RS[P                  /# )r   Úscaler   )r   r   r   )r   rP   s   "€r   r   rÈ   0  s   ø€ ÷ ñ ¹3ð ÁuÇ|Á|ñ r   c                ó  € VP                   w  r4rVW^,          ,
          R,           p \        P                  ! Wb,          V^,          ,
          R,
          WR,          V^,          ,
          R,
          ..4      pVP                  V 4      pW,          p V ^,          ^,
          p RR/pV P	                  V^R^4      p \
        P                  P                  ! W3RR/VB pVP                  W4R4      p\
        P                  P                  V^^R7      pV# )z-Interpolate descriptors at keypoint locationsg      à?Úalign_cornersTÚmodeÚbilinearrÐ   r„   )
r¸   r   ÚtensorrÂ   Úviewr   r5   Úgrid_samplerº   rÒ   )	r   rK   r×   r»   Únum_channelsr   r   ÚdivisorÚkwargss	   &&&      r   rÓ   Ú/SuperPointDescriptorDecoder._sample_descriptors/  só   € ð 3>×2CÑ2CÑ/ˆ
 &Ø¨¥	Õ)¨CÕ/ˆ	Ü—,’, %¥-°%¸!µ)Õ";¸cÕ"AÀVÅ^ÐV[Ð^_ÕV_ÕE_ÐbeÕEeÐ gÐhÓiˆØ—*‘*˜YÓ'ˆØÕˆ	Ø •M AÕ%ˆ	Ø! 4Ð(ˆà—N‘N :¨q°"°aÓ8ˆ	Ü—m‘m×/Ò/°ÑbÈZÐbÐ[aÑbˆà!×)Ñ)¨*ÀBÓGˆÜ—m‘m×-Ñ-¨k¸QÀAÐ-ÓFˆØÐr   )rÊ   rÌ   rq   ro   )é   )rR   rS   rT   rU   rV   rj   ry   ÚstaticmethodrÓ   rX   rY   r{   r|   s   @@r   rÆ   rÆ     s<   ù‡ € ñ÷
ó 
÷(
ð 
ð ÷ñ ó ÷ð r   rÆ   c                   óN   a € ] tR tRt o RtRtR
tRtV 3R lR ltV 3R lt	Rt
V tR	# )ÚSuperPointPreTrainedModeliB  Ú
superpointÚpixel_valuesFc                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   rè   r   )r   rM   )r   rP   s   "€r   r   Ú&SuperPointPreTrainedModel.__annotate__J  s(   ø€ ÷ 7ñ 7¹U×=NÑ=Nð 7ÑSX×SdÑSdñ 7r   c                ó"   € VR,          R,          # )aÿ  
Assuming pixel_values has shape (batch_size, 3, height, width), and that all channels values are the same,
extract the first channel value to get a tensor of shape (batch_size, 1, height, width) for SuperPoint. This is
a workaround for the issue discussed in :
https://github.com/huggingface/transformers/pull/25786#issuecomment-1730176446

Args:
    pixel_values: torch.FloatTensor of shape (batch_size, 3, height, width)

Returns:
    pixel_values: torch.FloatTensor of shape (batch_size, 1, height, width)

)r   r   r   r   )r   Nr   r   r    )rr   rè   s   &&r   Ú extract_one_channel_pixel_valuesÚ:SuperPointPreTrainedModel.extract_one_channel_pixel_valuesJ  s   € ð ˜JÕ'¨Õ6Ð6r   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   r^   r   )r   rP   s   "€r   r   rê   B  s   ø‡ ‚ áÑò r   r    N)Úimage)rR   rS   rT   rU   Úbase_model_prefixÚmain_input_nameÚinput_modalitiesÚsupports_gradient_checkpointingrì   rW   rX   rY   rZ   s   @r   ræ   ræ   B  s/   ø‡ € ð %ÐØ$€OØ!ÐØ&+Ð#÷7ð 7÷ ƒ r   ræ   z@
    SuperPoint model outputting keypoints and descriptors.
    c                   ób   a a€ ] tR tRt oRtV3R lV 3R llt]RV3R lR ll4       tRtVt	V ;t
# )	ÚSuperPointForKeypointDetectioni[  až  
SuperPoint model. It consists of a SuperPointEncoder, a SuperPointInterestPointDecoder and a
SuperPointDescriptorDecoder. SuperPoint was proposed in `SuperPoint: Self-Supervised Interest Point Detection and
Description <https://huggingface.co/papers/1712.07629>`__ by Daniel DeTone, Tomasz Malisiewicz, and Andrew Rabinovich. It
is a fully convolutional neural network that extracts keypoints and descriptors from an image. It is trained in a
self-supervised manner, using a combination of a photometric loss and a loss based on the homographic adaptation of
keypoints. It is made of a convolutional encoder and two decoders: one for keypoints and one for descriptors.
c                ó$   <€ V ^8„  d   QhRS[ RR/# r€   r   )r   rP   s   "€r   r   Ú+SuperPointForKeypointDetection.__annotate__j  s   ø€ ÷ 	ñ 	Ñ/ð 	°Dñ 	r   c                ó²   <€ \         SV `  V4       Wn        \        V4      V n        \        V4      V n        \        V4      V n        V P                  4        R # rx   )
ri   rj   r^   r~   Úencoderrž   Úkeypoint_decoderrÆ   Údescriptor_decoderÚ	post_initr«   s   &&€r   rj   Ú'SuperPointForKeypointDetection.__init__j  sE   ø€ Ü‰Ñ˜Ô àŒä(¨Ó0ˆŒÜ >¸vÓ FˆÔÜ"=¸fÓ"EˆÔà�‰Ör   c                óš   <€ V ^8„  d   QhRS[ P                  RS[ P                  R,          RS[R,          RS[R,          RS[S[,          /# )r   rè   ÚlabelsNr�   rŽ   r   )r   rM   Ú
LongTensorrb   r   rH   )r   rP   s   "€r   r   r÷   v  sc   ø€ ÷ [
ñ [
á×'Ñ'ð[
ñ × Ñ  4Õ'ð[
ñ # T�kð	[
ñ
 ˜D•[ð[
ñ 
Ñ4Õ	4ñ[
r   c           	     ó  € RpVe   \        R4      hVe   TMV P                  P                  pVe   TMV P                  P                  pV P	                  V4      pVP
                  w  rxršV P                  VVVR7      pV^ ,          pV Uu. uF  qÀP                  VR	,          4      NK  	  ppV Uu. uF  qî^ ,          NK  	  ppV Uu. uF  qî^,          NK  	  pp\        XV4       UUu. uF&  w  ppV P                  VR	,          VR	,          4      NK(  	  ppp\        R V 4       4      p\        P                  ! VV^3VP                  R7      p\        P                  ! VV3VP                  R7      p\        P                  ! VVV P                  P                  3VP                  R7      p\        P                  ! VV3VP                  \        P                  R7      p\!        \        VVV4      4       Fr  w  pw  pppVVVRVP
                  ^ ,          13&   VVVRVP
                  ^ ,          13&   VVVRVP
                  ^ ,          13&   ^VVRVP
                  ^ ,          13&   Kt  	  V\        P"                  ! W©.VP                  R7      ,          pV'       d
   V^,          MRpV'       g9   \$        ;QJ d    . R VVVVVV3 4       F  NK  	  5# ! R VVVVVV3 4       4      # \'        VVVVVVR7      # u upi u upi u upi u uppi )
ao  
Examples:

```python
>>> from transformers import AutoImageProcessor, SuperPointForKeypointDetection
>>> import torch
>>> from PIL import Image
>>> import httpx
>>> from io import BytesIO

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))

>>> processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint")
>>> model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint")

>>> inputs = processor(image, return_tensors="pt")
>>> outputs = model(**inputs)
```Nz-SuperPoint does not support training for now.)r�   rŽ   c              3   óF   "  € T F  qP                   ^ ,          x € K  	  R# 5i)r   N)r¸   )r’   r   s   & r   r”   Ú9SuperPointForKeypointDetection.forward.<locals>.<genexpr>³  s   é € Ð#WÉ¸9§O¡O°A×$6Ò$6Ëùs   ‚!)Údevice)r  rÃ   c              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5irx   r    r‘   s   & r   r”   r  È  s   é € ÐqÑ$_˜qŸšÓ$_ùr–   )rJ   r   r   rK   r#   rL   )N.)r:   r^   r�   rŽ   rì   r¸   rù   rú   Úziprû   Úmaxr   r?   r  rË   r   Ú	enumeraterÜ   r   rH   )rr   rè   rÿ   r�   rŽ   rá   rJ   r»   rA   r   r   Úencoder_outputsr—   Úlist_keypoints_scoresÚkeypoints_scoresÚlist_keypointsÚlist_scoresr   Úlist_descriptorsÚmaximum_num_keypointsr   rK   r#   rŠ   Ú
_keypointsÚ_scoresÚ_descriptorsrL   s   &&&&&,                      r   ry   Ú&SuperPointForKeypointDetection.forwardu  s3  € ð: ˆØÒÜÐLÓMÐMð %9Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆà×<Ñ<¸\ÓJˆà'3×'9Ñ'9Ñ$ˆ
�vàŸ,™,ØØ!5Ø#ð 'ó 
ˆð ,¨AÕ.Ðñ Zkó!
ÙYjÐDU×!Ñ!Ð"3°IÕ">Ö?ÑYjð 	ð !
ñ G\Ó\ÑF[Ð2B¨1×-Ð-ÑF[ˆÐ\ÙCXÓYÑCXÐ/?¨×*Ð*ÑCXˆÐYô 14Ð4EÀ~Ô0Vô
á0VÑ,Ð! 9ð ×#Ñ#Ð$5°iÕ$@À)ÈIÕBVÖWÙ0Vð 	ñ 
ô
 !$Ñ#WÉÓ#WÓ WÐä—K’K Ð-BÀAÐ FÈ|×ObÑObÔcˆ	Ü—’˜jÐ*?Ð@È×I\ÑI\Ô]ˆÜ—k’kØÐ.°·±×0RÑ0RÐSØ×&Ñ&ô
ˆô �{Š{˜JÐ(=Ð>À|×GZÑGZÔbg×bkÑbkÔlˆä6?ÄÀNÐT_ÐaqÓ@rÖ6sÑ2ˆAÑ2�
˜G \Ø2<ˆI�aÐ.˜:×+Ñ+¨AÕ.Ð.Ð.Ñ/Ø,3ˆF�1Ð(˜Ÿ™ aÕ(Ð(Ð(Ñ)Ø6BˆK˜Ð2˜\×/Ñ/°Õ2Ð2Ð2Ñ3Ø*+ˆD�Ð&�g—m‘m AÕ&Ð&Ð&Ó'ñ	 7tð ¤§¢¨e¨_ÀY×EUÑEUÔ VÕVˆ	ç.B˜¨Ö*Èˆßß”5Ñq T¨9°f¸kÈ4ÐQ^Ñ$_Óq—5Ðq�5Ñq T¨9°f¸kÈ4ÐQ^Ñ$_ÓqÓqÐqä2ØØØØ#ØØ'ô
ð 	
ùòG!
ùò ]ùÚYùó
s   Â K:Â1K?ÃLÃ*,L	)r^   rû   rù   rú   )NNN)rR   rS   rT   rU   rV   rj   r	   ry   rX   rY   r{   r|   s   @@r   rõ   rõ   [  s6   ù‡ € ñ÷	ó 	ð ÷[
ñ [
ó ÷[
ð [
r   rõ   )rV   Údataclassesr   r   r   Útransformersr   Útransformers.modeling_outputsr   Ú7transformers.models.superpoint.configuration_superpointr   Úutilsr   r	   r
   Ú
get_loggerrR   Úloggerr$   r,   rE   rH   ÚModuler\   r~   rž   rÆ   ræ   rõ   Ú__all__r    r   r   Ú<module>r     s  ðñ  å !ã Ý å (õõ U÷ñ ð 
×	Ò	˜HÓ	%€õ)õ&õ0ñ$ ðôð ô:¨+ó :ó óð:ô6˜"Ÿ)™)ô ô</
˜Ÿ	™	ô /
ôdE! R§Y¡Yô E!ôP9 "§)¡)ô 9ðx ô7 ó 7ó ð7ñ0 ðôô
q
Ð%>ó q
óð
q
ðh ,Ð-HÐ
I‚r   