+
    åûjÊ6  ã                   ó"  a € R t0 t ^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIHtH	t	 ^ RI
HtHtHt ^ RIHt / t] ^ k ]! RR	4      R
.]R&   ]! RR4      R.]R&   ]! RR4      R.]R&    ! R R]P"                  4      t ! R R]P"                  4      tR# )é    )ÚDictN)Únn)ÚKORNIA_CHECK_SHAPE)Úhf_urlÚload_state_dict_from_url)Ú_is_tracing_or_exportingÚ_l2_normalizeÚis_mps_tensor_safe)Ú_patch_conv_layoutÚhardnetzHardNetPP.pthz]https://github.com/DagnyT/hardnet/raw/master/pretrained/pretrained_all_datasets/HardNet++.pthz	hardnet++zcheckpoint_liberty_with_aug.pthznhttps://github.com/DagnyT/hardnet/raw/master/pretrained/train_liberty_with_aug/checkpoint_liberty_with_aug.pthÚliberty_augzhardnet8v2.ptz0https://cmp.felk.cvut.cz/~mishkdmy/hardnet8v2.ptÚ
hardnet8v2c                   ó|   a a€ ] tR t^+t oRt^ tR	V3R lV 3R lllt]R
V3R lR ll4       tV3R lR lt	Rt
VtV ;t# )ÚHardNeta?  Describe 32 x 32 grayscale patches with the learned 128-D HardNet CNN.

``hardnet = HardNet()`` builds the network with its pretrained weights, in eval mode, and
``descs = hardnet(patches)`` takes grayscale patches ``(B, 1, 32, 32)`` and returns unit-norm descriptors
``(B, 128)``. Each patch is standardised first, so its intensity range does not matter. To describe LAFs on an
image, use :class:`LAFDescriptor`, which holds a pretrained HardNet by default; the HardNet local features such as
:class:`DoGHardNet` and :class:`KeyNetHardNet` use it that way. :class:`HardNet8` is the wider follow-up network,
with the same patches and output size. This is based on the original code from paper "Working hard to know your
neighbor's margins: Local descriptor learning loss". See :cite:`HardNet2017` for more details.

Convention:
    - Patches are ``(B, 1, 32, 32)``, one grayscale channel, and another shape raises; ``patch_size`` is a class
      attribute. :func:`~kornia.feature.get_laf_descriptors` extracts such patches from LAFs at its default
      ``patch_size``, sampled as :func:`~kornia.feature.extract_patches_from_pyramid` describes
      (see :ref:`Local features <local-features-conventions>`).
      :class:`~kornia.feature.HardNet8`, :class:`~kornia.feature.SOSNet`, :class:`~kornia.feature.TFeat` and
      :class:`~kornia.feature.HyNet` take the same patches.
    - The intensity range does not matter: HardNet and HardNet8 standardise each patch to zero mean and unit
      standard deviation, and SOSNet and TFeat start with an ``InstanceNorm2d``, so :math:`a x + b` with
      :math:`a > 0` gives the same descriptor unless it leaves the patch nearly flat. That InstanceNorm adds
      ``1e-5`` to the variance, so for SOSNet and TFeat a low-contrast patch in ``[0, 1]`` can already give a
      different descriptor than the same patch in ``[0, 255]``. HyNet is invariant to a scale only; see its
      Convention block.
    - The descriptors have unit L2 norm, except TFeat's (see its Convention block); with ``pretrained=False``
      and ``.eval()`` (the initial BatchNorm statistics), HardNet and HardNet8 map a flat patch to an all-zero
      descriptor.
    - ``pretrained=True``, the default, downloads the trained weights (Liberty with augmentation for HardNet,
      ``hardnet8v2`` for HardNet8) and returns the model in evaluation mode. ``pretrained=False`` gives random
      weights in training mode; call ``.eval()`` before inference.

Args:
    pretrained: Download and set pretrained weights to the model.

Returns:
    torch.Tensor: HardNet descriptor of the patches.

Shape:
    - Input: ``(B, 1, 32, 32)``
    - Output: ``(B, 128)``

See Also:
    - :class:`HardNet8`: the follow-up network, wider, with a PCA from 512 to 128 dimensions.
    - :class:`SOSNet`: the same convolution stack, trained with second-order similarity regularisation.
    - :class:`HyNet`: a descriptor of the same patches, with FRN layers that subtract no mean.
    - :class:`TFeat`: a shallow network for the same patches, without L2 normalisation.
    - :class:`SIFTDescriptor`: handcrafted SIFT histograms of patches, with no weights.
    - :class:`LAFDescriptor`: runs this network, by default, on a patch per LAF of an image.

Examples:
    >>> input = torch.rand(16, 1, 32, 32)
    >>> hardnet = HardNet(pretrained=False).eval()
    >>> descs = hardnet(input) # 16x128

c                ó$   <€ V ^8„  d   QhRS[ RR/# ©é   Ú
pretrainedÚreturnN©Úbool)ÚformatÚ__classdict__s   "€ÚRC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\hardnet.pyÚ__annotate__ÚHardNet.__annotate__e   s   ø€ ÷ ñ ¡4ð °4ñ ó    c                óâ  <€ \         SV `  4        \        P                  ! \        P                  ! ^^ ^^RR7      \        P
                  ! ^ RR7      \        P                  ! 4       \        P                  ! ^ ^ ^^RR7      \        P
                  ! ^ RR7      \        P                  ! 4       \        P                  ! ^ ^@^^^RR7      \        P
                  ! ^@RR7      \        P                  ! 4       \        P                  ! ^@^@^^RR7      \        P
                  ! ^@RR7      \        P                  ! 4       \        P                  ! ^@^€^^^RR7      \        P
                  ! ^€RR7      \        P                  ! 4       \        P                  ! ^€^€^^RR7      \        P
                  ! ^€RR7      \        P                  ! 4       \        P                  ! R4      \        P                  ! ^€^€^RR7      \        P
                  ! ^€RR7      4      V n        V'       dY   \        \        R,          \        P                  ! R4      R	7      pV P                  VR
,          RR7       V P                  4        R# R# )é   F©Úkernel_sizeÚpaddingÚbias©Úaffine©r!   Ústrider"   r#   ç333333Ó?©r!   r#   r   Úcpu©Úmap_locationÚ
state_dictT©ÚstrictN)ÚsuperÚ__init__r   Ú
SequentialÚConv2dÚBatchNorm2dÚReLUÚDropoutÚfeaturesr   ÚurlsÚtorchÚdeviceÚload_state_dictÚeval©Úselfr   Úpretrained_dictÚ	__class__s   && €r   r1   ÚHardNet.__init__e   s˜  ø€ Ü‰ÑÔÜŸšÜ�IŠI�a˜¨°A¸EÔBÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜"¨!°Q¸UÔCÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜"¨!°A¸qÀuÔMÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜"¨!°Q¸UÔCÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜#¨1°QÀÈÔNÜ�NŠN˜3 uÔ-Ü�GŠG‹IÜ�IŠI�c˜3¨A°q¸uÔEÜ�NŠN˜3 uÔ-Ü�GŠG‹IÜ�JŠJ�s‹OÜ�IŠI�c˜3¨A°EÔ:Ü�NŠN˜3 uÔ-ó+
ˆŒ÷2 Ü6´t¸MÕ7JÔY^×YeÒYeÐfkÓYlÔmˆOØ× Ñ  °Õ!>ÀtÐ ÔLØ�I‰IŽKñ r   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# ©r   ÚxÚepsr   ©r9   ÚTensorÚfloat)r   r   s   "€r   r   r   †   ó*   ø€ ÷ 7ñ 7™EŸL™Lð 7©uð 7ÁÇÁñ 7r   c                óD  € \        V 4      '       g   \        4       '       d4   \        P                  ! V RRR7      p\        P                  ! V RRR7      pM\        P
                  ! V RRR7      w  r2WP                  4       ,
          VP                  4       V,           ,          # ©z@Standardise each patch to zero mean and unit standard deviation.T)ÚdimÚkeepdim)éýÿÿÿéþÿÿÿéÿÿÿÿ©r
   r   r9   ÚmeanÚstdÚstd_meanÚdetach©rD   rE   ÚmpÚsps   &&  r   Ú_normalize_inputÚHardNet._normalize_input…   óp   € ô ˜a× Ò Ô$<×$>Ò$>ä—’˜A <¸Ô>ˆBÜ—’˜1 ,¸Ô=‰Bä—^’^ A¨<ÀÔF‰FˆBð —I‘I“K• B§I¡I£K°#Õ$5Õ6Ð6r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úinputr   ©r9   rG   )r   r   s   "€r   r   r   “   s#   ø€ ÷ +ñ +™UŸ\™\ð +©e¯l©lñ +r   c                ó°   € \        V. RO4       V P                  V4      pV P                  \        V4      4      pVP	                  ^4      p\        V^R7      # )zÆCompute HardNet descriptors for grayscale 32x32 patches.

Args:
    input: Grayscale patch tensor of shape ``(B, 1, 32, 32)``.

Returns:
    L2-normalized descriptor tensor with shape ``(B, 128)``.
©rL   ©ÚBÚ1Ú32re   )r   rY   r7   r   Úflattenr	   )r>   r^   Úx_normÚ
x_featuresÚx_outs   &&   r   ÚforwardÚHardNet.forward“   sR   € ô 	˜5Ò"8Ô9Ø#×4Ñ4°UÓ;ˆØ#'§=¡=Ô1CÀFÓ1KÓ#Lˆ
Ø×"Ñ" 1Ó%ˆô ˜U¨Ô*Ð*r   ©r7   ©T)g�íµ ÷Æ°>)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú
patch_sizer1   ÚstaticmethodrY   rj   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r@   r   s   @@r   r   r   +   sE   ù‡ € ñ5ðn €J÷õ ð@ ÷7ñ 7ó ð7÷+÷ +ð +r   r   c                   ó˜   a a€ ] tR t^¥t oRt^ tRV3R lV 3R lllt]V3R lR l4       t]RV3R lR ll4       t	V3R lR	 lt
R
tVtV ;t# )ÚHardNet8aÎ  Describe 32 x 32 grayscale patches with HardNet8, a wider HardNet with a PCA to 128-D.

``hardnet8 = HardNet8()`` builds the network with its pretrained ``hardnet8v2`` weights, in eval mode, and
``descs = hardnet8(patches)`` takes grayscale patches ``(B, 1, 32, 32)`` and returns unit-norm descriptors
``(B, 128)``: the 512 L2-normalised features of the network, projected by the PCA stored with the weights and
normalised again. It takes the patches of :class:`HardNet` and returns descriptors of the same size, but they are
not interchangeable with HardNet's; pass it to :class:`LAFDescriptor` to describe LAFs on an image. This is based
on the original code from paper "Improving the HardNet Descriptor". See :cite:`HardNet2020` for more details.

Convention:
    See the Convention block on :class:`~kornia.feature.HardNet`.

Args:
    pretrained: Download and set pretrained weights to the model. The 512-d features are projected to 128-d by a
        PCA stored with the weights; without them, the projection keeps the first 128 features.

Returns:
    torch.Tensor: HardNet8 descriptor of the patches.

Shape:
    - Input: ``(B, 1, 32, 32)``
    - Output: ``(B, 128)``

See Also:
    - :class:`HardNet`: the original, narrower network, the default descriptor of :class:`LAFDescriptor`.
    - :class:`SOSNet`: HardNet's convolution stack, trained with second-order similarity regularisation.
    - :class:`HyNet`: a descriptor of the same patches, with FRN layers that subtract no mean.
    - :class:`LAFDescriptor`: runs a patch descriptor such as this one on a patch per LAF of an image.

Examples:
    >>> input = torch.rand(16, 1, 32, 32)
    >>> hardnet = HardNet8(pretrained=False).eval()
    >>> descs = hardnet(input) # 16x128

c                ó$   <€ V ^8„  d   QhRS[ RR/# r   r   )r   r   s   "€r   r   ÚHardNet8.__annotate__Ì   s   ø€ ÷ &ñ &¡4ð &°4ñ &r   c                ó‚  <€ \         SV `  4        \        P                  ! \        P                  ! ^^ ^^RR7      \        P
                  ! ^ RR7      \        P                  ! 4       \        P                  ! ^ ^ ^^RR7      \        P
                  ! ^ RR7      \        P                  ! 4       \        P                  ! ^ ^@^^^RR7      \        P
                  ! ^@RR7      \        P                  ! 4       \        P                  ! ^@^@^^RR7      \        P
                  ! ^@RR7      \        P                  ! 4       \        P                  ! ^@^€^^^RR7      \        P
                  ! ^€RR7      \        P                  ! 4       \        P                  ! ^€^€^^RR7      \        P
                  ! ^€RR7      \        P                  ! 4       \        P                  ! ^€R^^RR7      \        P
                  ! RRR7      \        P                  ! 4       \        P                  ! R4      \        P                  ! RR^RR7      \        P
                  ! RRR7      4      V n        V P                  P                  V P                  4       V P                  R	\        P                  ! R^€\        P                  R
7      4       V P                  R\        P                  ! R\        P                  R
7      4       V'       dR   \!        \"        R,          \        P$                  ! R4      R7      pV P'                  VRR7       V P)                  4        R# R# )r   Fr    r$   r&   é   r(   i   r)   Ú
components)ÚdtyperR   r   r*   r+   Tr.   N)r0   r1   r   r2   r3   r4   r5   r6   r7   ÚapplyÚweights_initÚregister_bufferr9   ÚeyerH   Úzerosr   r8   r:   r;   r<   r=   s   && €r   r1   ÚHardNet8.__init__Ì   s  ø€ Ü‰ÑÔÜŸšÜ�IŠI�a˜¨°A¸EÔBÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜"¨!°Q¸UÔCÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜"¨!°A¸qÀuÔMÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜"¨!°Q¸UÔCÜ�NŠN˜2 eÔ,Ü�GŠG‹IÜ�IŠI�b˜#¨1°QÀÈÔNÜ�NŠN˜3 uÔ-Ü�GŠG‹IÜ�IŠI�c˜3¨A°q¸uÔEÜ�NŠN˜3 uÔ-Ü�GŠG‹IÜ�IŠI�c˜3¨A°q¸uÔEÜ�NŠN˜3 uÔ-Ü�GŠG‹IÜ�JŠJ�s‹OÜ�IŠI�c˜3¨A°EÔ:Ü�NŠN˜3 uÔ-ó1
ˆŒð4 	�‰×Ñ˜D×-Ñ-Ô.ð 	×Ñ˜\¬5¯9ª9°S¸#ÄUÇ[Á[Ô+QÔRØ×Ñ˜V¤U§[¢[°¼E¿K¹KÔ%HÔI÷ Ü6´t¸LÕ7IÔX]×XdÒXdÐejÓXkÔlˆOØ× Ñ  ¸Ð Ô>Ø�I‰IŽKñ r   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úmr   N)Úobject)r   r   s   "€r   r   r|   õ   s   ø€ ÷ 	5ñ 	5™ð 	5 4ñ 	5r   c                ó<  € \        V \        P                  4      '       d|   \        P                  P	                  V P
                  P                  RR7       V P                  e7   \        P                  P                  V P                  P                  R4       R# R# R# )zkInitialize convolutional layers for HardNet8.

Args:
    m: Module instance passed by ``nn.Module.apply``.
g333333ã?)ÚgainNg{®Gáz„?)	Ú
isinstancer   r3   ÚinitÚorthogonal_ÚweightÚdatar#   Ú	constant_)rˆ   s   &r   r‚   ÚHardNet8.weights_initô   sd   € ô �aœŸ™×#Ò#Ü�G‰G×Ñ §¡§¡°CÐÔ8Ø�v‰vÒ!Ü—‘×!Ñ! !§&¡&§+¡+¨tÖ4ñ "ñ $r   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# rC   rF   )r   r   s   "€r   r   r|     rI   r   c                óD  € \        V 4      '       g   \        4       '       d4   \        P                  ! V RRR7      p\        P                  ! V RRR7      pM\        P
                  ! V RRR7      w  r2WP                  4       ,
          VP                  4       V,           ,          # rK   rQ   rV   s   &&  r   rY   ÚHardNet8._normalize_input   r[   r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# r]   r_   )r   r   s   "€r   r   r|     s#   ø€ ÷ )ñ )™UŸ\™\ð )©e¯l©lñ )r   c                óä  € \        V. RO4       V P                  V4      pV P                  \        V4      4      p\        P
                  P                  \        P                  V P                  4      p\        P
                  P                  \        P                  V P                  4      pVP                  ^4      p\        V^R7      p\        P                  ! Wt,
          V4      p\        V^R7      # )zÙCompute HardNet8 descriptors with PCA projection.

Args:
    input: Grayscale patch tensor of shape ``(B, 1, 32, 32)``.

Returns:
    L2-normalized descriptor tensor with shape ``(B, 128)``, after the PCA projection.
ra   rb   )r   rY   r7   r   r9   ÚjitÚannotaterG   rR   r   rf   r	   Úmm)	r>   r^   rg   rh   rR   r   Úx_flatÚx_prePCAÚpcas	   &&       r   rj   ÚHardNet8.forward  sª   € ô 	˜5Ò"8Ô9Ø#×4Ñ4°UÓ;ˆØ#'§=¡=Ô1CÀFÓ1KÓ#Lˆ
Ü"ŸY™Y×/Ñ/´·±¸d¿i¹iÓHˆÜ#(§9¡9×#5Ñ#5´e·l±lÀDÇOÁOÓ#Tˆ
Ø×#Ñ# AÓ&ˆÜ  ¨QÔ/ˆÜ�hŠh�x•¨
Ó3ˆÜ˜S aÔ(Ð(r   rl   rm   )gH¯¼šò×z>)rn   ro   rp   rq   rr   rs   r1   rt   r‚   rY   rj   ru   rv   rw   rx   s   @@r   rz   rz   ¥   sY   ù‡ € ñ"ðH €J÷&õ &ðP ÷	5ó ð	5ð ÷7ñ 7ó ð7÷)÷ )ð )r   rz   c                óŽ   € V ^8„  d   Qh/ ^ \         9   d1   \        \        \        \        \        ,          ,          3,          ;R&   # )r   r8   )Ú__conditional_annotations__r   ÚstrÚlist)r   s   "r   r   r      s,   € × Ñ ÷ &Ò %„dŒ3””dœ3•i•ÐÕ Ñ %ò r   )r    Útypingr   r9   r   Úkornia.core.checkr   Úkornia.core.downloadr   r   Úkornia.core.utilsr   r	   r
   Úkornia.feature._layoutr   r8   ÚModuler   rz   r   )r    s   @r   Ú<module>r©      s    øð÷$ Ò ã Ý å 0ß Aß YÑ YÝ 5à#%€Ó %á
ˆ9�oÓ&Øcð€€[Ñ ñ
 ˆ9Ð7Ó8Øtð€€]Ñ ñ
 ˆ9�oÓ&Ø6ð€€\Ñ ôw+ˆb�i‰iô w+ôtz)ˆr�y‰yö z)r   