+
    åûjDD  ã                  óª  a € 0 t $ ^ RIHt ^ RIt^ RIHtHt ^ RIt^ RIHt ^ RI	H
t
Ht ^RIHt ^RIHtHt ^RIHt ^R	IHt ^R
IHt / tR]R&   ]
! RR4      R.]R&   ]
! RR4      R.]R&   ]
! RR4      R.]R&   RRRR>R^RRRR^€R. R?O/R!R"R R#R R$^R%. R@OR(R)R*R+/R,R-R.R/^R0R1R2R3R4^R5R6R7RR8R9R:^È/	R;R"^€R#^€R$^R%R&R'.R(R)//t ! R< R=]P4                  4      tR# )Aé    )ÚannotationsN)ÚAnyÚOptional)Únn)Úhf_urlÚload_state_dict_from_url)Úbuild_backbone)ÚFinePreprocessÚLocalFeatureTransformer)ÚCoarseMatching)ÚFineMatching)ÚPositionEncodingSinezdict[str, str | list[str]]ÚurlsÚloftrzloftr_outdoor.ckptz<https://cmp.felk.cvut.cz/~mishkdmy/models/loftr_outdoor.ckptÚoutdoorzloftr_indoor_ds_new.ckptzBhttps://cmp.felk.cvut.cz/~mishkdmy/models/loftr_indoor_ds_new.ckptÚ
indoor_newzloftr_indoor.ckptz;https://cmp.felk.cvut.cz/~mishkdmy/models/loftr_indoor.ckptÚindoorÚbackbone_typeÚ	ResNetFPNÚ
resolutionÚfine_window_sizeÚfine_concat_coarse_featTÚ	resnetfpnÚinitial_dimÚ
block_dimsé   ÚcoarseÚd_modelÚd_ffnÚnheadÚlayer_namesÚselfÚcrossÚ	attentionÚlinearÚtemp_bug_fixFÚmatch_coarseÚthrgš™™™™™É?Ú	border_rmÚ
match_typeÚdual_softmaxÚdsmax_temperaturegš™™™™™¹?Ú	skh_itersÚskh_init_bin_scoreg      ð?Úskh_prefilterÚtrain_coarse_percentgš™™™™™Ù?Útrain_pad_num_gt_minÚfinec                  óp   a € ] tR t^PtRtR]3R V 3R llltR R ltR R ltR	 R
 lt	R V 3R llt
RtV ;t# )ÚLoFTRa  Match two grayscale images without a detector, by transformer-matched dense features (LoFTR).

``loftr = LoFTR("outdoor")`` loads pretrained weights and ``out = loftr({"image0": img0, "image1": img1})`` takes
two batches of ``N`` grayscale images ``(N, 1, H, W)`` in :math:`[0, 1]`, the two possibly of different sizes, and
returns a dict of the matches of all pairs: the pixel positions ``keypoints0`` and ``keypoints1`` ``(NC, 2)``, as
``(x, y)`` in the frame of the reference implementation, half a pixel off kornia's (see the Convention block),
their ``confidence`` ``(NC,)`` and the pair of each match, ``batch_indexes`` ``(NC,)``. It needs no keypoints or
descriptors: the matches of image0 lie on a grid of 8-pixel cells, not at detected keypoints. To match one image
against many, compute its backbone features, which do not depend on the other image, once with
:meth:`extract_features` and pass them as ``features0`` or ``features1``. For matching detected keypoints and
their descriptors, use :class:`LightGlueMatcher` or :class:`LocalFeatureMatcher` instead.

This is based on the original code of "LoFTR: Detector-Free Local Feature Matching with Transformers", see
:cite:`LoFTR2021` for more details.

Convention:
    - ``image0`` and ``image1`` are grayscale ``(N, 1, H, W)`` images in :math:`[0, 1]`, the input of the
      pretrained models. With the default ``config``, whose ``resolution`` (8, 2) every pretrained model uses,
      the two images can differ in size, and their heights and widths do not need to be multiples of 8 (the
      reference implementation expects multiples of 8).
    - With that ``resolution``, ``keypoints0`` lie on the grid of the 1/8-resolution coarse feature map, at
      ``8 * (column, row)`` of a coarse cell, and ``keypoints1`` at ``8 * (column, row)`` of the matching cell of
      image1 plus the offset found by the fine stage, at most 4 pixels along each axis. Both are :math:`(x, y)` in
      the frame of the reference implementation, in which the pretrained models put the centre of pixel
      :math:`(x, y)` at :math:`(x + 0.5, y + 0.5)`: subtract 0.5 to get kornia's frame
      (:ref:`Local features <local-features-conventions>`), in which pixel centres have integer coordinates.
      The keypoints are float32 for a float16 or bfloat16 model and float64 for a float64 one;
      ``confidence`` keeps the model dtype.
    - ``confidence`` is the coarse matching score of the match, a dual-softmax score with the default
      ``match_type``; only matches above ``max(thr, 0)`` are returned, with the ``thr`` of
      ``config["match_coarse"]``, 0.2 by default.
    - Coarse matches within ``border_rm`` cells of an edge are dropped (2 cells, 16 pixels by default).
      With ``mask0`` or ``mask1``, each sample's border is measured from its valid region, assumed to be a
      top-left-aligned rectangle with padding on the right and bottom. Either mask may be supplied alone;
      the other image is then treated as fully valid. Masks are sampled at the coarse cell centres.

Args:
    pretrained: Download and set pretrained weights to the model. Options: 'outdoor', 'indoor', 'indoor_new'.
                'outdoor' is trained on the MegaDepth dataset and 'indoor' and 'indoor_new'
                on the ScanNet. 'indoor_new' also switches the positional encoding of the copy
                to ``temp_bug_fix=True``, which is what its checkpoint was trained with. The weighted model
                comes back in evaluation mode. ``None`` builds random weights in training mode, where
                ``CoarseMatching`` runs its supervised training branch and needs ground-truth data; call
                ``.eval()`` for inference, also after loading your own weights.
    config: Dict with initialization parameters. Do not pass it, unless you know what you are doing.
            The model works on its own deep copy, so the dict you pass is never modified.

Returns:
    Dictionary with image correspondences and confidence scores.

See Also:
    - :class:`LightGlueMatcher`: a transformer matcher for the keypoints and descriptors of a detector.
    - :class:`LocalFeatureMatcher`: detects, describes and matches two images with a descriptor matcher.
    - :class:`~kornia.geometry.ransac.RANSAC`: the next step, which keeps the matches one geometric model
      explains, such as a :func:`~kornia.geometry.epipolar.find_fundamental` matrix.

Example:
    >>> img1 = torch.rand(1, 1, 320, 200)
    >>> img2 = torch.rand(1, 1, 128, 128)
    >>> input = {"image0": img1, "image1": img2}
    >>> loftr = LoFTR('outdoor')
    >>> out = loftr(input)

r   c               ó$   € V ^8„  d   QhRRRRRR/# )é   Ú
pretrainedzOptional[str]Úconfigúdict[str, Any]ÚreturnÚNone© )Úformats   "ÚVC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\loftr\loftr.pyÚ__annotate__ÚLoFTR.__annotate__’   s"   € ÷ ñ  =ð Ànð Ðgkñ ó    c                	óÜ  <€ \         SV `  4        \        P                  ! V4      pVR 8X  d   RVR,          R&   W n        \        V4      V n        \        VR,          R,          VR,          R,          R7      V n        \        VR,          4      V n
        \        VR,          4      V n        \        V4      V n        \        VR,          4      V n        \!        4       V n        Wn        Ve‚   V\&        9  d!   \)        R	\&        P+                  4        24      h\-        \&        V,          \.        P0                  ! R
4      R7      pV P3                  VR,          4       V P5                  4        R# R# )r   Tr   r&   r   )r&   r'   r2   Nz$pretrained should be None or one of Úcpu)Úmap_locationÚ
state_dict)ÚsuperÚ__init__ÚcopyÚdeepcopyr8   r	   Úbackboner   Úpos_encodingr   Úloftr_coarser   Úcoarse_matchingr
   Úfine_preprocessÚ
loftr_finer   Úfine_matchingr7   r   Ú
ValueErrorÚkeysr   ÚtorchÚdeviceÚload_state_dictÚeval)r"   r7   r8   Úpretrained_dictÚ	__class__s   &&& €r>   rG   ÚLoFTR.__init__’   s$  ø€ Ü‰ÑÔô —’˜vÓ&ˆØ˜Ô%Ø/3ˆF�8Õ˜^Ñ,ØŒä& vÓ.ˆŒÜ0Ø�8Õ˜YÕ'°f¸XÕ6FÀ~Õ6Vô
ˆÔô 4°F¸8Õ4DÓEˆÔÜ-¨f°^Õ.DÓEˆÔÜ-¨fÓ5ˆÔÜ1°&¸µ.ÓAˆŒÜ)›^ˆÔØ$ŒØÒ!Ø¤Ô%Ü Ð#GÌÏ	É	ËÀ}Ð!UÓVÐVä6´t¸JÕ7GÔV[×VbÒVbÐchÓViÔjˆOØ× Ñ  °Õ!>Ô?Ø�I‰IŽKñ "rA   c               ó    € V ^8„  d   QhRRRR/# )r6   Úimageztorch.Tensorr:   údict[str, torch.Tensor]r<   )r=   s   "r>   r?   r@   ­   s   € ÷ Eñ E lð EÐ7Nñ ErA   c                óR   € V P                  V4      w  r#RV P                  V4      RV/# )aH  Compute the features of images that do not depend on the image they are matched with.

These are the backbone's coarse and fine feature maps, the coarse one with its positional encoding. Pass the
returned dict to :meth:`forward` as ``features0`` or ``features1`` instead of ``image0`` or ``image1`` to
match an image against many others without running the backbone again for every pair.

Args:
    image: grayscale images with shape ``(N, 1, H, W)``.

Returns:
    - ``coarse``, position-encoded 1/8-resolution features ``(N, C_c, ceil(H / 8), ceil(W / 8))``.
    - ``fine``, 1/2-resolution features ``(N, C_f, ceil(H / 2), ceil(W / 2))``. With the default config this
      is 128 channels, about 96 MB in float32 for a 1024 x 736 image.

Example:
    >>> loftr = LoFTR(None).eval()
    >>> images = [torch.rand(1, 1, 64, 80), torch.rand(1, 1, 72, 64), torch.rand(1, 1, 64, 64)]
    >>> features = [loftr.extract_features(image) for image in images]
    >>> out = loftr({"features0": features[0], "features1": features[1]})
    >>> out = loftr({"features0": features[0], "image1": images[2]})

r   r2   )rJ   rK   )r"   r[   Úfeat_cÚfeat_fs   &&  r>   Úextract_featuresÚLoFTR.extract_features­   s.   € ð. Ÿ™ uÓ-‰ˆØ˜$×+Ñ+¨FÓ3°V¸VÐDÐDrA   c               ó    € V ^8„  d   QhRRRR/# )r6   Údatar9   r:   z7tuple[dict[str, torch.Tensor], dict[str, torch.Tensor]]r<   )r=   s   "r>   r?   r@   Ç   s   € ÷ (ñ ( >ð (Ð6mñ (rA   c           	     ó  € R F(  pRV 2V9   RV 2V9   8X  g   K  \        RV RV R24      h	  RV9   dÝ   RV9   dÖ   VR,          P                  R,          VR,          P                  R,          8X  dŸ   VR,          P                  ^ 4      pV P                  \        P
                  ! VR,          VR,          .^ R	7      4      pVP                  4        UUu/ uF
  w  rVWVR
V bK  	  uppVP                  4        UUu/ uF
  w  rVWVVR
 bK  	  upp.pMO. pR FG  pVP                  RV 24      pTP                  Ve   TMV P                  VRV 2,          4      4       KI  	  V^ ,          R,          P                  ^ 4      V^,          R,          P                  ^ 4      8w  dM   \        RV^ ,          R,          P                  ^ 4       RV^,          R,          P                  ^ 4       R24      hV^ ,          V^,          3# u uppi u uppi )zHFeatures of both sides of the pair: given, or extracted from the images.r[   ÚfeatureszPass exactly one of `imagez` and `featuresz`.Úimage0Úimage1ºr6   NN)ÚdimNr   z)Both sides need the same batch size. Got z and Ú.)r   é   )	rQ   ÚshapeÚsizer`   rS   ÚcatÚitemsÚgetÚappend)	r"   rc   ÚsideÚnÚbothÚkÚvre   Úgivens	   &&       r>   Ú_pair_featuresÚLoFTR._pair_featuresÇ   sý  € ãˆDØ˜�v� $Ñ&¨h°t°fÐ,=ÀÑ,EÖFÜ Ð#=¸d¸VÀ?ÐSWÐRXÐXZÐ![Ó\Ð\ñ ð �tÔ ¨DÔ 0°T¸(µ^×5IÑ5IÈ"Õ5MÐQUÐV^ÕQ_×QeÑQeÐfhÕQiÔ5ià�X•×#Ñ# AÓ&ˆAØ×(Ñ(¬¯ª°D¸µNÀDÈÅNÐ3SÐYZÔ)[Ó\ˆDØ.2¯j©j¬lÔ;©l¡d a˜˜b˜q˜Eš©lÒ;ÐSW×S]ÑS]ÔS_Ô=`ÑS_É4È1¸aÀ1À2ÀºhÑS_Ò=`Ða‰HàˆHÛ�ØŸ™ 8¨D¨6Ð!2Ó3�Ø—‘¨Ò):¡À×@UÑ@UÐVZÐ]bÐcgÐbhÐ[iÕVjÓ@kÖlñ ð �A�;�xÕ ×%Ñ% aÓ(¨H°Q­K¸Õ,A×,FÑ,FÀqÓ,IÔIÜØ;¸HÀQ½KÈÕ<Q×<VÑ<VÐWXÓ<YÐ;ZÐZ_Ø˜A•;˜xÕ(×-Ñ-¨aÓ0Ð1°ð4óð ð ˜�{˜H Q�KÐ'Ð'ùó <ùÓ=`s   ÃH Ã<Hc               ó    € V ^8„  d   QhRRRR/# )r6   rc   r9   r:   r\   r<   )r=   s   "r>   r?   r@   Ý   s   € ÷ gñ g˜Nð gÐ/Fñ grA   c                óJ  € V P                   R,          w  r#V P                  V4      w  rEVR,          VR,          rvVR,          VR,          r˜RVP                  ^ 4      RVRV/p
V
P                  RVP                  R,          R	VP                  R,          R
VP                  R,          RV	P                  R,          /4       VP                  ^ ^^^4      pVP                  ^^R7      P                  4       pVP                  ^ ^^^4      pVP                  ^^R7      P                  4       pR;r¼RV9   d)   VR,          RRRV1RRV13,          P                  R4      pRV9   d)   VR,          RRRV1RRV13,          P                  R4      pVf   Ve¨   ^ W´3^WÅ33 F›  w  rÞpVR,          pVP                  ^ 4      VP                  ^4      VP                  ^4      3pVf2   \        P                  ! VVP                  \        P                  R7      MVP                  V4      P                  4       V
RV 2&   K�  	  V P                  WhW¼4      w  rhV P                  WhW«VR7       V P                  WyWhV
4      w  ppVP                  ^ 4      ^ 8w  d   V P!                  VV4      w  ppV P#                  VVV
4       RRRRRRRR/p/ pVP%                  4        FN  w  ppV
V,          p\'        V\        P(                  4      '       d   VVV&   K6  \+        RV R\-        V4       24      h	  V# )aW  Run forward.

Args:
    data: dictionary containing the input data in the following format:

Keyword Args:
    image0: left image with shape ``(N, 1, H1, W1)``.
    image1: right image with shape ``(N, 1, H2, W2)``.
    features0 (optional): instead of ``image0``, its :meth:`extract_features` output.
    features1 (optional): instead of ``image1``, its :meth:`extract_features` output.
    mask0 (optional): left image mask. '0' indicates a padded position ``(N, H1, W1)``.
    mask1 (optional): right image mask. '0' indicates a padded position ``(N, H2, W2)``.

Returns:
    - ``keypoints0``, matching keypoints from image0 ``(NC, 2)``.
    - ``keypoints1``, matching keypoints from image1 ``(NC, 2)``.
    - ``confidence``, the coarse matching score, see the Convention block ``(NC,)``.
    - ``batch_indexes``, batch index of each match ``(NC,)``.

r   r   r2   ÚbsÚstride_cÚstride_fÚhw0_crh   Úhw1_cÚhw0_fÚhw1_f)Ú	start_dimÚend_dimNÚmask0.Úmask1)rT   ÚdtypeÚmask)Úmask_c0Úmask_c1Úmkpts0_fÚ
keypoints0Úmkpts1_fÚ
keypoints1ÚmconfÚ
confidenceÚb_idsÚbatch_indexesz Expected torch.Tensor for item `z`. Got éþÿÿÿ)r8   rx   rm   Úupdaterl   ÚpermuteÚflattenÚ
contiguousrS   ÚonesrT   ÚboolÚreshaperL   rM   rN   rO   rP   ro   Ú
isinstanceÚTensorÚ	TypeErrorÚtype)r"   rc   r}   r~   Ú	features0Ú	features1Úfeat_c0Úfeat_f0Úfeat_c1Úfeat_f1Ú_datar‰   rŠ   rr   rˆ   re   r   rl   Úfeat_f0_unfoldÚfeat_f1_unfoldÚrename_keysÚoutru   rv   Ú_ds   &&                       r>   ÚforwardÚLoFTR.forwardÝ   s%  € ð2 "Ÿ[™[¨Õ6Ñˆð  $×2Ñ2°4Ó8Ñˆ	Ø$ XÕ.°	¸&Õ0A�Ø$ XÕ.°	¸&Õ0A�à�'—,‘,˜q“/Ø˜Ø˜ð=
ˆð 	�‰à˜Ÿ™ rÕ*Ø˜Ÿ™ rÕ*Ø˜Ÿ™ rÕ*Ø˜Ÿ™ rÕ*ð	ô	
ð  —/‘/ ! Q¨¨1Ó-ˆØ—/‘/¨A°q�/Ó9×DÑDÓFˆà—/‘/ ! Q¨¨1Ó-ˆØ—/‘/¨A°q�/Ó9×DÑDÓFˆà Ð ˆà�dŒ?Ø˜7•m C©¨8¨±Z°x°ZÐ$?Õ@×HÑHÈÓLˆGØ�dŒ?Ø˜7•m C©¨8¨±Z°x°ZÐ$?Õ@×HÑHÈÓLˆGØÒ 'Ò"5ð +,¨WÐ)@À1ÀgÐBYÓ(ZÑ$�˜HØ! (Õ+�ØŸ™ Q›¨¯©°Q«¸¿¹ÀQ»ÐH�ð ’|ô —J’J˜u¨V¯]©]Ä%Ç*Á*ÕMàŸ™ eÓ,×1Ñ1Ó3ð ˜˜T˜F�mÓ$ñ )[ð  ×,Ñ,¨W¸wÓPÑˆð 	×Ñ˜W¨uÈwÐÔWð *.×)=Ñ)=¸gÐPWÐbgÓ)hÑ&ˆ˜Ø×Ñ˜qÓ! QÔ&Ø-1¯_©_¸^È^Ó-\Ñ*ˆN˜Nð 	×Ñ˜>¨>¸5ÔAð ˜Ø˜Ø�\Ø�_ð	'
ˆð (*ˆØ×%Ñ%Ö'‰DˆAˆqØ�q•ˆBÜ˜"œeŸl™l×+Ò+Ø��A“äÐ"BÀ1À#ÀWÌTÐRTËXÈJÐ WÓXÐXñ (ð ˆ
rA   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   rE   r9   Úargsr   Úkwargsr:   r<   )r=   s   "r>   r?   r@   F  s0   € ÷ Dñ D¨.ð DÀð DÐPSð DÐX[ñ DrA   c                óæ   <€ \        VP                  4       4       F@  pVP                  R4      '       g   K  VP                  V4      WP	                  RR^4      &   KB  	  \
        SV `  ! V.VO5/ VB # )a­  Load a checkpoint state dictionary into the module.

Args:
    state_dict: Checkpoint state dictionary whose keys are adapted to this module layout.
    *args: Additional positional arguments forwarded to the parent `load_state_dict` implementation.
    **kwargs: Additional keyword arguments forwarded to the parent `load_state_dict` implementation.

Returns:
    Result returned by the parent `load_state_dict` implementation.
zmatcher.Ú )ÚlistrR   Ú
startswithÚpopÚreplacerF   rU   )r"   rE   r®   r¯   ru   rX   s   &&*, €r>   rU   ÚLoFTR.load_state_dictF  sd   ø€ ô �j—o‘oÓ'Ö(ˆAØ�|‰|˜J×'Ô'Ø;E¿>¹>È!Ó;L�
Ÿ9™9 Z°°QÓ7Ó8ñ )ô ‰wÒ& zÐC°DÒC¸FÑCÐCrA   )	rJ   rM   r8   rP   rN   rL   rO   rK   r7   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Údefault_cfgrG   r`   rx   r«   rU   Ú__static_attributes__Ú__classcell__)rX   s   @r>   r4   r4   P   s9   ø† ñ?ðB 4=ÐWb÷ ò õ6Eõ4(õ,g÷RDö DrA   r4   )é   r6   )é€   éÄ   r   )r"   r#   r"   r#   r"   r#   r"   r#   )Ú__conditional_annotations__Ú
__future__r   rH   Útypingr   r   rS   r   Úkornia.core.downloadr   r   rJ   r	   Úloftr_moduler
   r   Úutils.coarse_matchingr   Úutils.fine_matchingr   Úutils.position_encodingr   r   Ú__annotations__r¼   ÚModuler4   )rÂ   s   @r>   Ú<module>rÌ      sG  øð÷$ #Ð "ã ß  ã Ý ç Aå $ß AÝ 1Ý -Ý 9à#%€Ð Ó %á
ˆ7Ð(Ó)ØBð€€Y�ñ
 ˆ7Ð.Ó/ØHð€€\Ñ ñ
 ˆ7Ð'Ó(ØAð€€X�ð �[Ø�&Ø˜Ø˜tØ�-  l²OÐDØØ�3Ø�Ø�ØÒ[Ø�XØ˜ðð ØˆsØ�QØ�nØ˜SØ�QØ˜cØ˜Ø Ø ð
ð ˆY˜˜W c¨7°A°}ÀvÈwÐFWÐYdÐfnÐoð3€ô:DDˆB�I‰Iö DDrA   