+
    åûj‰L  ã                   óº  a € R, t0 t ^ RIHtHtHtHt ^ RIt^ RIHu H	t
 ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^RIHtHtHtHt ^RIHtHt R	R
]! RR4      R.R]! RR4      R.R]! RR4      R.R]! RR4      R./RR]! RR4      R.R]! RR4      R.R]! RR4      R .R!]! RR"4      R#.R$]! RR%4      R&.R']! RR(4      R).//t] ^ k  ! R* R+]P6                  4      tR# )-é    )ÚDictÚLiteralÚOptionalÚTupleN)Únn)ÚKORNIA_CHECK_SHAPE)Úhf_urlÚload_state_dict_from_url)Ú	Normalize)ÚDeDoDeDescriptorÚDeDoDeDetectorÚget_descriptorÚget_detector)Ú$dedode_denormalize_pixel_coordinatesÚsample_keypointsÚdetectorz	L-uprightÚdedodezdedode_detector_L.pthzchttps://github.com/Parskatt/DeDoDe/releases/download/dedode_pretrained_models/dedode_detector_L.pthzL-C4zdedode_detector_C4.pthz`https://github.com/georg-bn/rotation-steerers/releases/download/release-2/dedode_detector_C4.pthzL-SO2zdedode_detector_SO2.pthzahttps://github.com/georg-bn/rotation-steerers/releases/download/release-2/dedode_detector_SO2.pthúL-C4-v2zdedode_detector_L_v2.pthzPhttps://github.com/Parskatt/DeDoDe/releases/download/v2/dedode_detector_L_v2.pthÚ
descriptorz	B-uprightzdedode_descriptor_B.pthzehttps://github.com/Parskatt/DeDoDe/releases/download/dedode_pretrained_models/dedode_descriptor_B.pthzB-C4z"B_C4_Perm_descriptor_setting_C.pthzlhttps://github.com/georg-bn/rotation-steerers/releases/download/release-2/B_C4_Perm_descriptor_setting_C.pthzB-SO2z%B_SO2_Spread_descriptor_setting_C.pthzohttps://github.com/georg-bn/rotation-steerers/releases/download/release-2/B_SO2_Spread_descriptor_setting_C.pthú	G-uprightzdedode_descriptor_G.pthzehttps://github.com/Parskatt/DeDoDe/releases/download/dedode_pretrained_models/dedode_descriptor_G.pthzG-C4z"G_C4_Perm_descriptor_setting_C.pthzlhttps://github.com/georg-bn/rotation-steerers/releases/download/release-2/G_C4_Perm_descriptor_setting_C.pthzG-SO2z%G_SO2_Spread_descriptor_setting_C.pthzohttps://github.com/georg-bn/rotation-steerers/releases/download/release-2/G_SO2_Spread_descriptor_setting_C.pthc                   ó>  a a€ ] tR t^Ot oRtRR]P                  3V3R lV 3R llltV3R lR ltRV3R lR	 llt	]P                  ! 4       RV3R
 lR ll4       t]P                  ! 4       RV3R lR ll4       t]RR]P                  3V3R lR ll4       tRtVtV ;t# )ÚDeDoDea¸  Detect the n best keypoints of each RGB image and describe them with two networks (DeDoDe).

``dedode = DeDoDe.from_pretrained(detector_weights="L-C4-v2", descriptor_weights="B-upright")`` loads trained
weights in evaluation mode. ``keypoints, scores, descriptions = dedode(images, n=10_000)`` takes RGB images
``(B, 3, H, W)`` in :math:`[0, 1]` and returns the best ``N = min(n, H W)`` keypoints per image.
Outputs are ``(x, y)`` pixel coordinates ``(B, N, 2)`` with pixel centres at ``i + 0.5``, scores ``(B, N)``
and unnormalised descriptors ``(B, N, 256)``. Use :class:`ALIKED` or :class:`DISK` when the keypoint count
should depend on image content.

See :cite:`edstedt2024dedode` for details.

Convention:
    - :meth:`detect` and :meth:`describe` run the detector and descriptor separately. The default descriptor,
      ``G``, combines VGG19 with a frozen DINOv2 ViT-L/14 backbone and loads the backbone's weights in the
      constructor. Descriptor ``B`` uses VGG19 alone.
    - For :class:`LightGlueMatcher`, construct LAFs centred on the keypoints minus 0.5 and pass them with the
      descriptors in ``"dedodeb"`` or ``"dedodeg"`` mode, matching the descriptor variant.
    - :meth:`forward`, :meth:`detect` and :meth:`describe` take RGB images in the range :math:`[0, 1]` and apply
      the ImageNet normalization themselves; pass ``apply_imagenet_normalization=False`` for images that are
      already normalized. ``pad_if_not_divisible`` zero-pads the normalized image at the bottom and right to
      multiples of 14, so the padding is the ImageNet mean colour, and removes it from the maps again.
    - :meth:`forward` returns pixel ``i`` as ``i + 0.5``: subtract 0.5 for the pixel convention of
      :func:`~kornia.feature.laf_from_center_scale_ori` (see :ref:`Local features <local-features-conventions>`).
      :meth:`detect` returns it normalized, as ``(2 i + 1) / (W, H) - 1`` in :math:`[-1, 1]`
      (``align_corners=False``), the form :meth:`describe` takes; ``(k + 1) * (W, H) / 2 - 0.5`` converts such a
      ``k`` to kornia's frame. A description is read at the centre of pixel ``i``.
    - The keypoints of an image come in descending order of score, with no threshold and no padding. Keypoints,
      and the descriptions of :meth:`forward` and of ``describe(images, keypoints)``, are float32. The scoremap
      softmax and the keypoint sampling run in at least float32, so the scores are float32 for a half-precision
      model and float64 for a float64 one. The dense map of ``describe(images)`` follows the network dtype:
      ``amp_dtype`` on CUDA, the dtype of the model on CPU and MPS.
    - kornia detects and describes at the size of the input. The authors resize every image to 784 x 784, without
      keeping its aspect ratio, in ``detect_from_path`` and ``describe_keypoints_from_path``, and train the
      detector and the ``B`` descriptor at 512 x 512 (``G`` at 560 x 560). The 51-pixel coverage window of the
      keypoint sampling and the 14-pixel patches of ``G`` do not scale with the image. After resizing to
      784 x 784, the normalized keypoints of :meth:`detect` hold for the original image unchanged; multiply those
      of :meth:`forward` by ``(W / 784, H / 784)``.
    - ``amp_dtype`` is CUDA mixed precision in every component: on CUDA tensors the networks run under
      ``torch.autocast`` in ``amp_dtype`` (and the DINOv2 backbone of the ``G`` descriptor is cast to it). On CPU
      and MPS it has no effect, so the default argument runs there with float32 weights and images.

Args:
    detector_model: The detector model kind. Available options are: ``"L"``.
    descriptor_model: The descriptor model kind. Available options are: ``"G"`` or ``"B"``.
    amp_dtype: The dtype of the automatic mixed precision used on CUDA; it has no effect on other devices.

See Also:
    - :class:`ALIKED`: learned sub-pixel keypoints whose count follows each image's score map, for RGB images of
      any size.
    - :class:`DISK`: learned integer-pixel keypoints with 128-D descriptors from one U-Net, for RGB images whose
      sides are multiples of 16.
    - :class:`XFeat`: learned keypoints with 64-D descriptors, and its own mutual-nearest-neighbour and refined
      matching of image pairs.
    - :class:`LightGlueMatcher`: matches the descriptions and keypoints with the ``"dedodeb"`` weights for the
      ``B`` descriptor and the ``"dedodeg"`` weights for ``G``.

Example:
    >>> dedode = DeDoDe.from_pretrained(detector_weights="L-C4-v2", descriptor_weights="B-upright")
    >>> images = torch.rand(1, 3, 256, 256)
    >>> keypoints, scores = dedode.detect(images)
    >>> descriptions = dedode.describe(images, keypoints = keypoints)
    >>> keypoints, scores, features = dedode(images) # alternatively do both

ÚLÚGc                ó`   <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[P                  RR/# )é   Údetector_modelr   Údescriptor_modelÚ	amp_dtypeÚreturnN)r   ÚB)r   ÚtorchÚdtype)ÚformatÚ__classdict__s   "€ÚXC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\dedode\dedode.pyÚ__annotate__ÚDeDoDe.__annotate__’   sF   ø€ ÷ 	rñ 	rá �ð	rñ " (Õ+ð	rñ —;‘;ð		rð
 
ñ	ró    c                óà   <€ \         SV `  4        \        W4      V n        \	        W#4      V n        \        \        P                  ! . RO4      \        P                  ! . RO4      R7      V n	        R# )ç
×£p=
ß?)ÚstdN)r+   gÉv¾Ÿ/Ý?g–C‹lçûÙ?)gZd;ßOÍ?gyé&1¬Ì?gÍÌÌÌÌÌÌ?)
ÚsuperÚ__init__r   r   r   r   r   r"   ÚtensorÚ
normalizer)Úselfr   r   r   Ú	__class__s   &&&&€r&   r.   ÚDeDoDe.__init__’   sK   ø€ ô 	‰ÑÔÜ(4°^Ó(OˆŒÜ,:Ð;KÓ,WˆŒÜ#¤E§L¢LÒ1FÓ$GÌUÏ\Ê\ÒZoÓMpÔqˆŽr)   c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   ÚimagesÚapply_imagenet_normalizationÚpad_if_not_divisibler    )r"   ÚTensorÚbool)r$   r%   s   "€r&   r'   r(   �   s5   ø€ ÷ ñ Ù—l‘lðÙBFðÙ^bðá	�‰ñr)   c                ó$  € V'       d   V P                  V4      pV'       do   VP                  RR w  rEV^,          ^ 8”  d   ^V^,          ,
          M^ pV^,          ^ 8”  d   ^V^,          ,
          M^ p\        P                  ! V^ V^ V3RR7      pV# )z¼Normalise, then zero-pad to a multiple of 14.

The pad is applied after the normalisation so that it is the ImageNet mean colour, the neutral value the
networks see, in every entry point.
Ng        )Úvalueéþÿÿÿ)r0   ÚshapeÚFÚpad)r1   r5   r6   r7   ÚHÚWÚpd_hÚpd_ws   &&&&    r&   Ú_preprocessÚDeDoDe._preprocess�   s|   € ÷ (Ø—_‘_ VÓ,ˆFßØ—<‘<  Ð$‰DˆAØ"# b¥&¨1¤*�2˜˜B�–;°!ˆDØ"# b¥&¨1¤*�2˜˜B�–;°!ˆDÜ—U’U˜6 A t¨Q°Ð#5¸SÔAˆFØˆr)   c                ó²   <€ V ^8„  d   QhRS[ P                  RS[S[,          RS[RS[RS[S[ P                  S[ P                  S[ P                  3,          /# )r   r5   Únr6   r7   r    ©r"   r8   r   Úintr9   r   )r$   r%   s   "€r&   r'   r(   ®   sd   ø€ ÷ &[ñ &[á—‘ð&[ñ ‘C�=ð&[ñ '+ð	&[ñ
 #ð&[ñ 
‰u�|‰|™UŸ\™\©5¯<©<Ð7Õ	8ñ&[r)   c           	     ó¸   € VP                   w  rVrxV P                  WV4      pV P                  WRRWxR7      w  ršV P                  WRRWxR7      p\	        W—V4      W«3# )aq  Detect and describe keypoints in the input images.

Args:
    images: A torch.Tensor of shape ``(B, 3, H, W)`` containing the RGB input images in the range
        :math:`[0, 1]`.
    n: The number of keypoints to detect in each image, at most ``H W``; ``None`` keeps every pixel.
    apply_imagenet_normalization: Whether to apply ImageNet normalization to the input images. Pass
        ``False`` if they are already ImageNet-normalized.
    pad_if_not_divisible: Zero-pad the (normalised) image on the bottom and right so that H and W are
        multiples of 14; the pad is the ImageNet mean colour. The padding is removed from the scoremap, so
        keypoints are never reported in it.

Returns:
    keypoints: A torch.Tensor of shape ``(B, N, 2)`` containing the detected keypoints in pixels, with pixel
        ``i`` at ``i + 0.5``, unlike :meth:`detect`, which normalises them.

    scores: A torch.Tensor of shape ``(B, N)`` containing the scores of the detected keypoints.

    descriptions: A torch.Tensor of shape ``(B, N, DIM)`` containing the descriptions
        of the detected keypoints. DIM is 256 for both B and G.

F)rG   r6   r7   Úcrop_hÚcrop_w)r6   r7   rK   rL   )r=   rD   ÚdetectÚdescriber   )r1   r5   rG   r6   r7   Ú_BÚ_Cr@   rA   Ú	keypointsÚscoresÚdescriptionss   &&&&&       r&   ÚforwardÚDeDoDe.forward®   sy   € ð: —|‘|‰ˆ�Ø×!Ñ! &ÐH\Ó]ˆà ŸK™KØ°eÐRWÐ`að (ó 
Ñˆ	ð —}‘}Ø¸EÐX]Ðfgð %ó 
ˆô 4°IÀ!ÓDÀfÐZÐZr)   c                óÆ   <€ V ^8„  d   QhRS[ P                  RS[S[,          RS[RS[RS[S[,          RS[S[,          RS[S[ P                  S[ P                  3,          /# )r   r5   rG   r6   r7   rK   rL   r    rH   )r$   r%   s   "€r&   r'   r(   ×   ss   ø€ ÷ 1%ñ 1%á—‘ð1%ñ ‘C�=ð1%ñ '+ð	1%ñ
 #ð1%ñ ™•ð1%ñ ™•ð1%ñ 
‰u�|‰|™UŸ\™\Ð)Õ	*ñ1%r)   c                ó  € \        V. RO4       V P                  R4       VP                  w  rxršV P                  WV4      pV P                  P                  V4      pVRRV	1RV
13,          pVe   Ve   VRRV1RV13,          pYVr©VP                  \        P                  ! VP                  \        P                  4      4      pVP                  WyV
,          4      P                  RR7      P                  WyV
4      p\        WÂR7      w  rÞWÞ3# )aI  Detect keypoints in the input images.

.. note::
    This method unconditionally sets the model to eval mode via ``self.train(False)``
    so that BatchNorm and Dropout behave deterministically. This is intentional: the
    detector is only used at inference time and its statistics must be frozen.

Args:
    images: A torch.Tensor of shape ``(B, 3, H, W)`` containing the RGB input images in the range
        :math:`[0, 1]`.
    n: The number of keypoints to detect.
    apply_imagenet_normalization: Whether to apply ImageNet normalization to the input images. Pass
        ``False`` if they are already ImageNet-normalized.
    pad_if_not_divisible: Zero-pad the (normalised) image on the bottom and right so that H and W are
        multiples of 14; the pad is the ImageNet mean colour, as in :meth:`forward` and :meth:`describe`. The
        padding is removed from the scoremap, so keypoints are never reported in it.
    crop_h: The height of the crop to be used for detection. If None, the full image is used.
    crop_w: The width of the crop to be used for detection. If None, the full image is used.

Returns:
    keypoints: A torch.Tensor of shape ``(B, N, 2)`` containing the detected keypoints,
    normalized to the range :math:`[-1, 1]`.
    scores: A torch.Tensor of shape ``(B, N)`` containing the scores of the detected keypoints.

F.N)Údim)Únum_samples©r!   Ú3r@   rA   éÿÿÿÿ)r   Útrainr=   rD   r   rT   Útor"   Úpromote_typesr#   Úfloat32ÚreshapeÚsoftmaxr   )r1   r5   rG   r6   r7   rK   rL   r!   rP   r@   rA   ÚlogitsÚscoremaprQ   Ú
confidences   &&&&&&&        r&   rM   ÚDeDoDe.detectÖ   sù   € ôF 	˜6Ò#7Ô8Ø�
‰
�5ÔØ—l‘l‰ˆˆqØ×!Ñ! &ÐH\Ó]ˆØ—‘×&Ñ& vÓ.ˆà˜˜R˜a˜R  ! ˜Õ$ˆØÒ &Ò"4Ø˜C  & ¨'¨6¨'Ð1Õ2ˆFØˆqð —‘œ5×.Ò.¨v¯|©|¼U¿]¹]ÓKÓLˆØ—>‘> !¨¥UÓ+×3Ñ3¸Ð3Ó;×CÑCÀAÈ!ÓLˆÜ 0°Ô IÑˆ	ØÐ$Ð$r)   c                ó°   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[RS[RS[S[,          RS[S[,          RS[ P                  /# )r   r5   rQ   r6   r7   rK   rL   r    )r"   r8   r   r9   rI   )r$   r%   s   "€r&   r'   r(     sj   ø€ ÷ 3ñ 3á—‘ð3ñ ™EŸL™LÕ)ð3ñ '+ð	3ñ
 #ð3ñ ™•ð3ñ ™•ð3ñ 
�‰ñ3r)   c                óœ  € \        V. RO4       VP                  w  rxršVe   \        V. RO4       V P                  WV4      pV P                  R4       V P                  P                  V4      pVe   Ve   YVr©VRRV	1RV
13,          pVeA   \        P                  ! VP                  4       VR,          RRR7      R	,          P                  # V# )
a  Describe keypoints in the input images. If keypoints are not provided, returns the dense descriptors.

.. note::
    This method unconditionally sets the model to eval mode via ``self.train(False)``
    so that BatchNorm and Dropout behave deterministically. This is intentional: the
    descriptor is only used at inference time and its statistics must be frozen.

Args:
    images: A torch.Tensor of shape ``(B, 3, H, W)`` containing the RGB input images in the range
        :math:`[0, 1]`.
    keypoints: An optional torch.Tensor of shape ``(B, N, 2)`` containing the detected keypoints.
    apply_imagenet_normalization: Whether to apply ImageNet normalization to the input images. Pass
        ``False`` if they are already ImageNet-normalized.
    pad_if_not_divisible: Zero-pad the (normalised) image on the bottom and right so that H and W are
        multiples of 14; the pad is the ImageNet mean colour, as in :meth:`forward` and :meth:`detect`.
        Required when using the ``G`` descriptor backed by DINOv2 (patch size 14). The padding is removed from
        the descriptor map, so the map has the size of the input image.
    crop_h: The height of the crop to be used for description. If None, the full image is used.
    crop_w: The width of the crop to be used for description. If None, the full image is used.

Returns:
    descriptions: A torch.Tensor of shape ``(B, N, DIM)`` containing the descriptions
        of the detected keypoints.
        If the dense descriptors are requested, the shape is ``(B, DIM, H, W)``.

NF.Úbilinear)ÚmodeÚalign_cornersrZ   )r!   ÚNÚ2)ºNNNN)rn   rn   r   )
r   r=   rD   r]   r   rT   r>   Úgrid_sampleÚfloatÚmT)r1   r5   rQ   r6   r7   rK   rL   rO   rP   r@   rA   rS   s   &&&&&&&     r&   rN   ÚDeDoDe.describe
  sÊ   € ôH 	˜6Ò#7Ô8Ø—|‘|‰ˆ�ØÒ Ü˜yª/Ô:Ø×!Ñ! &ÐH\Ó]ˆØ�
‰
�5ÔØ—‘×.Ñ.¨vÓ6ˆØÒ &Ò"4Øˆqà# C¨¨!¨¨R¨a¨R KÕ0ˆàÒ Ü—=’= ×!3Ñ!3Ó!5°yÀÕ7IÐPZÐjoÔpØõç‰bðð Ðr)   r   r   c                óZ   <€ V ^8„  d   QhRS[ RS[ RS[P                  RS[P                  /# )r   Údetector_weightsÚdescriptor_weightsr   r    )Ústrr"   r#   r   ÚModule)r$   r%   s   "€r&   r'   r(   A  s;   ø€ ÷ *ñ *áð*ñ  ð*ñ —;‘;ð	*ñ
 
�‰ñ*r)   c                óˆ  € V ! V^ ,          V^ ,          VR7      pVP                   P                  \        \        R,          V,          \        P
                  ! R4      R7      4       VP                  P                  \        \        R,          V,          \        P
                  ! R4      R7      4       VP                  4        V# )aí  Load a pretrained model.

Args:
    detector_weights: The weights to load for the detector.
        One of 'L-upright' (original paper, https://arxiv.org/abs/2308.08479),
        'L-C4', 'L-SO2' (from steerers, better for rotations, https://arxiv.org/abs/2312.02152),
        'L-C4-v2' (from dedode v2, better at rotations, less clustering, https://arxiv.org/abs/2404.08928).
        Default is 'L-C4-v2'.
    descriptor_weights: The weights to load for the descriptor.
        One of 'B-upright','G-upright' (original paper, https://arxiv.org/abs/2308.08479),
        'B-C4', 'B-SO2', 'G-C4', 'G-SO2' (from steerers, better for rotations, https://arxiv.org/abs/2312.02152).
        Default is 'G-upright'.
    amp_dtype: the dtype of the automatic mixed precision used on CUDA, one of torch.float16 or
        torch.float32. It has no effect on CPU or MPS, where every component runs in the dtype of the
        input and the model.
        Default is torch.float16.

Returns:
    The pretrained model.

)r   r   r   r   Úcpu)Úmap_locationr   )r   Úload_state_dictr
   Úurlsr"   Údevicer   Úeval)Úclsrt   ru   r   Úmodels   &&&& r&   Úfrom_pretrainedÚDeDoDe.from_pretrained@  sŸ   € ñ> Ø+¨AÕ.Ø/°Õ2Øô
ˆð
 	�‰×&Ñ&Ü$¤T¨*Õ%5Ð6FÕ%GÔV[×VbÒVbÐchÓViÔjô	
ð 	×Ñ×(Ñ(Ü$¤T¨,Õ%7Ð8JÕ%KÔZ_×ZfÒZfÐglÓZmÔnô	
ð 	�
‰
ŒØˆr)   )r   r   r0   )é'  TT)rƒ   TTNN)NTTNN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   Úfloat16r.   rD   rT   Úno_gradrM   rN   Úclassmethodr�   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r2   r%   s   @@r&   r   r   O   sª   ù‡ € ñ?ðH (+Ø.1Ø!&§¡÷		rõ 	r÷ð ÷"&[ò &[ðP ‡]‚]ƒ_÷1%ñ 1%ó ð1%ðf ‡]‚]ƒ_÷3ñ 3ó ð3ðj ð !*Ø"-Ø!&§¡÷	*ñ *ó ÷*ð *r)   r   c                ó„   € V ^8„  d   Qh/ ^ \         9   d,   \        \        \        \        \        3,          3,          ;R&   # )r   r|   )Ú__conditional_annotations__r   rv   )r$   s   "r&   r'   r'      s0   € × 1Ñ 1÷-ò -„dŒ3””Sœ#�X•ÐÕñ -ò 2r)   )r�   Útypingr   r   r   r   r"   Útorch.nn.functionalr   Ú
functionalr>   Úkornia.core.checkr   Úkornia.core.downloadr	   r
   Úkornia.enhance.normalizer   Údedode_modelsr   r   r   r   Úutilsr   r   r|   rw   r   r'   )r�   s   @r&   Ú<module>r™      sN  øð÷$ 2× 1Ð 1ã ß Ð Ý å 0ß AÝ .ç YÓ Yß Ið ØÙ�8Ð4Ó5Øqð
ð 	Ù�8Ð5Ó6Ønð
ð 	Ù�8Ð6Ó7Øoð
ð 	Ù�8Ð7Ó8Ø^ð
ðð$ ØÙ�8Ð6Ó7Øsð
ð 	Ù�8ÐAÓBØzð
ð 	Ù�8ÐDÓEØ}ð
ð 	Ù�8Ð6Ó7Øsð
ð 	Ù�8ÐAÓBØzð
ð 	Ù�8ÐDÓEØ}ð
ð+ð'-#€ó -ô`\ˆR�Y‰Yö \r)   