+
    åûjÎ1  ã            	       ó¨  a € R t 0 t ^ RIHtHtHt ^ RIt^ RIHu Ht	 ^ RIHt ^ RI
HtHt ^ RIHt ^ RIHt ^RIHtHtHt  ! R R	]4      tR
^R^R^R]! 4       /t] ^ k ]! RR4      R.t ! R R]P0                  4      t ! R R]P0                  4      t ! R R]P6                  4      tRR R llt ! R R]P0                  4      t ! R R]4      tR# )é    )ÚListÚOptionalÚ	TypedDictN)Únn)Úhf_urlÚload_state_dict_from_url)ÚSpatialGradient)Úpyrdown)ÚDetector_configÚMultiResolutionDetectorÚget_default_detector_configc                   ó0   a € ] tR t^t o RtV 3R ltRtV tR# )ÚKeyNet_confaœ  Define the configuration schema for the KeyNet feature detector.

Attributes:
    num_filters: The number of filters in the convolutional layers.
    num_levels: The number of levels in the image pyramid.
    kernel_size: The kernel size of the last convolution, which merges the levels' features.
    Detector_conf: The configuration of the :class:`MultiResolutionDetector` that :class:`KeyNetDetector` builds.
c                óJ   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   S[;R&   # )é   Únum_filtersÚ
num_levelsÚkernel_sizeÚDetector_conf)Úintr   )ÚformatÚ__classdict__s   "€ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\keynet.pyÚ__annotate__ÚKeyNet_conf.__annotate__   s8   ø‡ ‚ ñ Ññ ñ �Oñ ñ Ññ ñ #Ñ"ò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r      s   ø‡ € ñ÷ ƒ r   r   r   r   r   r   Úkeynetzkeynet_pytorch.pthzXhttps://github.com/axelBarroso/Key.Net-Pytorch/raw/main/model/weights/keynet_pytorch.pthc                   óX   a a€ ] tR t^>t oRt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	# )Ú_FeatureExtractorzNHelper class for KeyNet.

It loads both, the handcrafted and learnable blocks
c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   r   ÚreturnN©r   )r   r   s   "€r   r   Ú_FeatureExtractor.__annotate__D   s   ø€ ÷ Añ A¡Cð A°ñ Ar   c                ód   <€ \         SV `  4        \        4       V n        \	        VR 7      V n        R# ))r   N)ÚsuperÚ__init__Ú_HandcraftedBlockÚhc_blockÚ_LearnableBlockÚlb_block)Úselfr   Ú	__class__s   &&€r   r/   Ú_FeatureExtractor.__init__D   s$   ø€ Ü‰ÑÔä)Ó+ˆŒÜ'°KÔ@ˆŽr   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úxr*   ©ÚtorchÚTensor)r   r   s   "€r   r   r,   J   s#   ø€ ÷ #ñ #™Ÿ™ð #©%¯,©,ñ #r   c                óF   € V P                  V4      pV P                  V4      # ©N©r1   r3   )r4   r9   Úx_hcs   && r   ÚforwardÚ_FeatureExtractor.forwardJ   s   € Ø�}‰}˜QÓˆØ�}‰}˜TÓ"Ð"r   r?   )é   ©
r   r   r    r!   r"   r/   rA   r$   r%   Ú__classcell__©r5   r   s   @@r   r(   r(   >   s%   ù‡ € ñ÷
Aõ A÷#÷ #ð #r   r(   c                   óT   a a€ ] tR t^Ot oRtV3R lV 3R lltV3R lR ltRtVtV ;t	# )r0   zaHelper class for KeyNet, it defines the handcrafted filters within the Key.Net handcrafted block.c                ó   <€ V ^8„  d   QhRR/# )r   r*   Nr   )r   r   s   "€r   r   Ú_HandcraftedBlock.__annotate__R   s   ø€ ÷ <ñ <˜$ñ <r   c                óF   <€ \         SV `  4        \        R ^4      V n        R# )ÚsobelN)r.   r/   r	   Úspatial_gradient)r4   r5   s   &€r   r/   Ú_HandcraftedBlock.__init__R   s   ø€ Ü‰ÑÔÜ /°¸Ó ;ˆÖr   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r8   r:   )r   r   s   "€r   r   rI   V   s'   ø€ ÷ 
qñ 
q™Ÿ™ð 
q©%¯,©,ñ 
qr   c                ób  € V P                  V4      pVR,          VR,          rCV P                  V4      pVR,          VR,          rvV P                  V4      R,          p\        P                  ! W4VP                  4       VP                  4       W4,          WwP                  4       WhWh,          .
^4      # )ºNNN)rP   rP   r   rP   rP   )rP   rP   é   rP   rP   )rL   r;   ÚcatÚsquare)	r4   r9   rK   ÚdxÚdyÚsobel_dxÚdxxÚdxyÚdyys	   &&       r   rA   Ú_HandcraftedBlock.forwardV   s•   € Ø×%Ñ% aÓ(ˆØ�}Õ% u¨]Õ';ˆBà×(Ñ(¨Ó,ˆØ˜MÕ*¨H°]Õ,CˆSð ×#Ñ# BÓ'¨Õ6ˆä�yŠy˜" "§)¡)£+¨r¯y©y«{¸B½GÀSÏ*É*Ë,ÐX[ÐbeÕbkÐlÐnoÓpÐpr   )rL   rD   rF   s   @@r   r0   r0   O   s$   ù‡ € Ùk÷<ó <÷
q÷ 
qð 
qr   r0   c                   óX   a a€ ] tR t^ct oRt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	# )r2   zMHelper class for KeyNet.

It defines the learnable blocks within the Key.Net
c                ó*   <€ V ^8„  d   QhRS[ RS[ RR/# )r   Úin_channelsr   r*   Nr+   )r   r   s   "€r   r   Ú_LearnableBlock.__annotate__i   s'   ø€ ÷ @ñ @¡Cð @¹3ð @Àtñ @r   c                ó„   <€ \         SV `  4        \        W4      V n        \        W"4      V n        \        W"4      V n        R # r>   )r.   r/   Ú_KeyNetConvBlockÚconv0Úconv1Úconv2)r4   r]   r   r5   s   &&&€r   r/   Ú_LearnableBlock.__init__i   s2   ø€ Ü‰ÑÔä% kÓ?ˆŒ
Ü% kÓ?ˆŒ
Ü% kÓ?ˆŽ
r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r8   r:   )r   r   s   "€r   r   r^   p   s#   ø€ ÷ 5ñ 5™Ÿ™ð 5©%¯,©,ñ 5r   c                ó  € VP                   \        P                  8X  d<   VP                  P                  R9   d!   VP                  \        P                  R7      pV P                  V P                  V P                  V4      4      4      # )Úcpu)Úmemory_format)rg   Úcuda)
Údtyper;   Úfloat32ÚdeviceÚtypeÚtoÚchannels_lastrc   rb   ra   )r4   r9   s   &&r   rA   Ú_LearnableBlock.forwardp   sY   € ð �7‰7”e—m‘mÔ#¨¯©¯©¸Ô(HØ—‘¤5×#6Ñ#6�Ó7ˆAØ�z‰z˜$Ÿ*™* T§Z¡Z°£]Ó3Ó4Ð4r   )ra   rb   rc   )é
   rC   rD   rF   s   @@r   r2   r2   c   s%   ù‡ € ñ÷
@õ @÷5÷ 5ð 5r   r2   c                ó€   € V ^8„  d   QhR\         R\         R\         R\         R\         R\         R\        P                  /# )r   r]   Úout_channelsr   ÚstrideÚpaddingÚdilationr*   )r   r   Ú
Sequential)r   s   "r   r   r   y   sR   € ÷ ñ Üðäðô ðô ð	ô
 ðô ðô ‡]�]ñr   c           
     ó°   € \         P                  ! \         P                  ! WW#WE4      \         P                  ! V4      \         P                  ! RR7      4      # )zMCreate KeyNet Conv Block.

Default learnable convolutional block for KeyNet.
T©Úinplace)r   rw   ÚConv2dÚBatchNorm2dÚReLU)r]   rs   r   rt   ru   rv   s   &&&&&&r   r`   r`   y   s=   € ô �=Š=Ü
�	Š	�+¨[À'ÓTÜ
�Š�|Ó$Ü
�Š˜Ôóð r   c                   óX   a a€ ] tR t^Œt oRt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	# )ÚKeyNeta=	  Compute the learned Key.Net keypoint response map of a grayscale image, at the input's size.

``response = KeyNet()(img)`` takes grayscale images ``(B, 1, H, W)`` in ``[0, 1]`` and returns their Key.Net
response, a non-negative ``(B, 1, H, W)`` map, without non-maxima suppression: handcrafted first- and second-order
derivative filters and a small CNN run on the image and on ``num_levels - 1`` successive 1.2x downscales of it (two
by default), and a last convolution merges their features, resized back to the input size. The pretrained weights,
the default, come back in evaluation mode; a random model (``pretrained=False``) stays in training mode, so call
``.eval()`` before inference (see :ref:`pretrained-models-conventions`). For keypoints, use
:class:`KeyNetDetector`, which finds the maxima of this response on an image pyramid.

This is based on the original code from the paper "Key.Net: Keypoint Detection by Handcrafted and Learned CNN
Filters". See :cite:`KeyNet2019` for more details.

.. image:: _static/img/KeyNet.png

Convention:
    - The input is a grayscale image, and the pretrained weights expect it in ``[0, 1]``, as the Key.Net
      reference scales its images. The response is not proportional to the intensity, so an image in
      ``[0, 255]`` gives other detections. A multi-channel image raises ``RuntimeError``.
    - The response is a non-negative map of the input's size when ``kernel_size`` is odd. With ``pretrained=False``
      and an even ``kernel_size``, the final convolution returns a map one pixel larger on each axis.

Args:
    pretrained: Download and set pretrained weights to the model.
    keynet_conf: Dict with initialization parameters. Do not pass it, unless you know what you are doing. A
        ``num_filters``, ``num_levels`` or an odd ``kernel_size`` other than the default changes the architecture.
        Pass
        ``pretrained=False`` with it, since the strict load of the weights raises ``RuntimeError``.

Returns:
    KeyNet response score.

Shape:
    - Input: ``(B, 1, H, W)``
    - Output: ``(B, 1, H, W)``

See Also:
    - :class:`KeyNetDetector`: detects LAFs at the maxima of this response on an image pyramid.
    - :class:`BlobHessian`: a handcrafted blob response, with no weights to load.
    - :class:`KeyNetHardNet`: KeyNet detection with OriNet orientation and HardNet descriptors.

c                ó:   <€ V ^8„  d   QhRS[ RS[S[,          RR/# )r   Ú
pretrainedÚkeynet_confr*   N)Úboolr   r   )r   r   s   "€r   r   ÚKeyNet.__annotate__¸   s(   ø€ ÷ ñ ¡4ð ¹XÁkÕ=Rð Ð^bñ r   c           	     ó  <€ \         SV `  4        Vf   \        pVR,          pVR,          V n        VR,          pV^,          p\	        V4      V n        \        P                  ! \        P                  ! W0P                  ,          ^WER7      \        P                  ! RR7      4      V n
        V'       dR   \        \        \        P                  ! R4      R7      pV P                  VR	,          RR
7       V P!                  4        R # R # )Nr   r   r   )r]   rs   r   ru   Try   rg   )Úmap_locationÚ
state_dict)Ústrict)r.   r/   Úkeynet_default_configr   r(   Úfeature_extractorr   rw   r{   r}   Ú	last_convr   Ú
KeyNet_URLr;   rl   Úload_state_dictÚeval)r4   r�   r‚   r   r   ru   Úpretrained_dictr5   s   &&&    €r   r/   ÚKeyNet.__init__¸   sÍ   ø€ Ü‰ÑÔØÒÜ/ˆKà! -Õ0ˆØ% lÕ3ˆŒØ! -Õ0ˆØ Õ"ˆä!2°;Ó!?ˆÔÜŸšÜ�IŠIØ'¯/©/Õ9ÈÐWbôô �GŠG˜DÔ!ó	
ˆŒ÷ Ü6´zÔPU×P\ÒP\Ð]bÓPcÔdˆOØ× Ñ  °Õ!>ÀtÐ ÔLØ�I‰IŽKñ r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r8   r:   )r   r   s   "€r   r   r„   Ï   s#   ø€ ÷ 	3ñ 	3™Ÿ™ð 	3©%¯,©,ñ 	3r   c                óŠ  € VP                   ^,          VP                   ^,          r2V P                  V4      .p\        ^V P                  4       FM  p\	        VRR7      pV P                  V4      p\
        P                  ! WbV3RRR7      pVP                  V4       KO  	  V P                  \        P                  ! V^4      4      # )zX - input image.g333333ó?)ÚfactorÚbilinearF)ÚsizeÚmodeÚalign_corners)ÚshaperŠ   Úranger   r
   ÚFÚinterpolateÚappendr‹   r;   rR   )r4   r9   ÚhÚwÚfeatsÚ_Úfeats_is   &&     r   rA   ÚKeyNet.forwardÏ   sœ   € à�w‰w�q�z˜1Ÿ7™7 1�:ˆ1Ø%)×%;Ñ%;¸AÓ%>Ð$?ˆÜ�q˜$Ÿ/™/Ö*ˆAÜ˜ #Ô&ˆAØ×,Ñ,¨QÓ/ˆGÜ—m’m G°a°&¸zÐY^Ô_ˆGØ�L‰L˜Ö!ñ	 +ð
 �~‰~œeŸiši¨¨qÓ1Ó2Ð2r   )rŠ   r‹   r   )TNrD   rF   s   @@r   r   r   Œ   s$   ù‡ € ñ)÷Võ ÷.	3÷ 	3ð 	3r   r   c                   óF   a a€ ] tR t^Ût oRtRV3R lV 3R llltRtVtV ;t# )ÚKeyNetDetectora(  Detect LAFs at the maxima of the learned Key.Net response on an image pyramid, one image per call.

``detector = KeyNetDetector(num_features=2048)``, then ``lafs, responses = detector(img)`` takes one grayscale
image ``(1, 1, H, W)`` in ``[0, 1]`` and returns ``(1, num_features, 2, 3)`` LAFs in input pixels and their
``(1, num_features)`` KeyNet responses, strongest first. ``laf_is_filled(lafs)`` is true for detections; index
every output with it to discard padded slots. It is a :class:`MultiResolutionDetector` on the :class:`KeyNet`
response with the default ``config``: maxima at the integer pixels of six pyramid levels, in upright frames unless
``ori_module`` or ``aff_module`` change them. For KeyNet detections with orientation and HardNet descriptors, use
:class:`KeyNetAffNetHardNet` instead.

This is based on the original code from the paper "Key.Net: Keypoint Detection by Handcrafted and Learned CNN
Filters". See :cite:`KeyNet2019` for more details.

.. image:: _static/img/keynet.jpg

Convention:
    A :class:`~kornia.feature.MultiResolutionDetector` with :class:`~kornia.feature.KeyNet` as its response; see
    their Convention blocks for the pixel convention and input range. Only KeyNet is in evaluation mode after
    construction, so this detector reports ``training=True``; calling ``.train()`` changes its detections.

Args:
    pretrained: Download and set pretrained weights to the model.
    num_features: Number of features to detect.
    keynet_conf: Dict with initialization parameters. Do not pass it, unless you know what you are doing. A
        ``num_filters``, ``num_levels`` or an odd ``kernel_size`` other than the default changes the architecture.
        Pass
        ``pretrained=False`` with it, since the strict load of the weights raises ``RuntimeError``.
    ori_module: for local feature orientation estimation. Default: :class:`~kornia.feature.PassLAF`,
       which does nothing. See :class:`~kornia.feature.LAFOrienter` for details.
    aff_module: for local feature affine shape estimation. Default: :class:`~kornia.feature.PassLAF`,
        which does nothing. See :class:`~kornia.feature.LAFAffineShapeEstimator` for details.
    compile_model: wrap the response function and the non-maxima suppression with :func:`torch.compile`.
    score_threshold: minimum response for a position to count as a detection. Must be non-negative:
        non-maxima suppression writes an exact zero at every suppressed position, so a negative
        threshold would admit all of them; it raises ``ValueError``.

See Also:
    - :class:`KeyNet`: the response network alone, a dense ``(B, 1, H, W)`` map.
    - :class:`MultiResolutionDetector`: the same detector on another response function.
    - :class:`ScaleSpaceDetector`: batched detection at the sub-pixel scale-space extrema of a pluggable response,
      the Hessian determinant by default.
    - :class:`KeyNetHardNet`: this detector with OriNet orientation and HardNet descriptors.
    - :class:`KeyNetAffNetHardNet`: the same, with AffNet affine shapes before the orientation.
    - :class:`LAFOrienter`: an ``ori_module`` that orients each frame from its image patch.
    - :class:`LAFAffineShapeEstimator`: an ``aff_module`` that adapts each frame to its patch's second moments.
    - :func:`laf_is_filled`: is true for detections; use it to discard padded slots.

c                ó    <€ V ^8„  d   QhRS[ RS[RS[S[,          RS[S[P
                  ,          RS[S[P
                  ,          RS[ RS[RR	/# )
r   r�   Únum_featuresr‚   Ú
ori_moduleÚ
aff_moduleÚcompile_modelÚscore_thresholdr*   N)rƒ   r   r   r   r   ÚModuleÚfloat)r   r   s   "€r   r   ÚKeyNetDetector.__annotate__  sr   ø€ ÷ 
ñ 
áð
ñ ð
ñ ™kÕ*ð	
ñ
 ™RŸY™YÕ'ð
ñ ™RŸY™YÕ'ð
ñ ð
ñ ð
ð 
ñ
r   c           	     ód   <€ Vf   \         p\        W4      p\        S	V `  W‚VR,          WEWg4       R # )Nr   )r‰   r   r.   r/   )
r4   r�   r¦   r‚   r§   r¨   r©   rª   Úmodelr5   s
   &&&&&&&& €r   r/   ÚKeyNetDetector.__init__  s6   ø€ ð ÒÜ/ˆKÜ�zÓ/ˆÜ‰ÑØ ¨_Õ!=¸zÐWdö	
r   r   )Ti   NNNFg        )	r   r   r    r!   r"   r/   r$   r%   rE   rF   s   @@r   r¤   r¤   Û   s   ù‡ € ñ/÷b
÷ 
õ 
r   r¤   c                ó@   € V ^8„  d   Qh/ ^ \         9   d
   \        ;R&   # )r   r‰   )Ú__conditional_annotations__r   )r   s   "r   r   r      s   € × ,Ñ ,÷:ò ”{ñ ò; -r   )rC   rC   é   rQ   r   rQ   )!r²   Útypingr   r   r   r;   Útorch.nn.functionalr   Ú
functionalrš   Úkornia.core.downloadr   r   Úkornia.filtersr	   Úkornia.geometry.transformr
   Úscale_space_detectorr   r   r   r   r‰   rŒ   r«   r(   r0   rw   r2   r`   r   r¤   r   )r²   s   @r   Ú<module>r»      sÌ   øð÷$ -Ö ,ã ß Ð Ý ç AÝ *Ý -ç gÑ gô#�)ô #ð$ �1Ø�!Ø�1àÑ0Ó2ð&Ð ó ñ ˆ8Ð)Ó*Ø^ð€
ô#˜Ÿ	™	ô #ô"q˜Ÿ	™	ô qô(5�b—m‘mô 5÷,ô&L3ˆR�Y‰Yô L3ô^A
Ð,ö A
r   