+
    åûjÊ@  ã                   óD  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 ^ 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 R]P                  4      tR# )é    )ÚDictN)Únn)ÚKORNIA_CHECK_SHAPE)Úhf_urlÚload_state_dict_from_url)Ú_patch_conv_layout)Ú_DescriptorSequentialÚhynetzHyNet_LIB.pthzXhttps://github.com/ducha-aiki/Key.Net-Pytorch/raw/main/model/HyNet/weights/HyNet_LIB.pthÚlibertyzHyNet_ND.pthzWhttps://github.com/ducha-aiki/Key.Net-Pytorch/raw/main/model/HyNet/weights/HyNet_ND.pthÚ	notredamezHyNet_YOS.pthzXhttps://github.com/ducha-aiki/Key.Net-Pytorch/raw/main/model/HyNet/weights/HyNet_YOS.pthÚyosemitec                   ó|   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V3R lR ltV3R lR	 ltR
t	Vt
V ;t# )ÚFilterResponseNorm2da�  Normalise each channel map by its root mean square, without batch statistics (FRN).

``frn = FilterResponseNorm2d(C)``, then ``y = frn(x)`` takes feature maps ``(B, C, H, W)`` and returns them in the
same shape, each map divided by the root of its mean square plus ``|eps|``, then, by default, scaled and shifted per
channel. It subtracts no mean and uses no batch statistics, so it behaves the same in training and eval mode and for
any batch size. :class:`HyNet` applies it, followed by :class:`TLU`, after every convolution but the last, where
:class:`HardNet` uses BatchNorm and ReLU, and on the raw patch, which HardNet standardises instead. A float16 or
bfloat16 input is normalised in float32, and the output dtype is the promotion of the input's and the layer's, so a
float16 input to a float32 layer returns float32. This is the Filter Response Normalization layer from 'Filter
Response Normalization Layer: Eliminating Batch Dependence in the Training of Deep Neural Networks', see
:cite:`FRN2019` for more details.

.. math::
    y = \gamma \frac{x}{\sqrt{\nu^2 + |\epsilon|}} + \beta

Convention:
    - :math:`\nu^2` is the mean of :math:`x^2` over the ``H x W`` map of each sample and channel, so the output
      does not depend on the rest of the batch; no mean is subtracted. :math:`\gamma` (``weight``) and
      :math:`\beta` (``bias``) are per-channel parameters initialised to 1 and 0, applied only when ``is_scale``
      and ``is_bias`` are set.

Args:
    num_features: number of channels
    eps: normalization constant
    is_bias: use bias
    is_scale: use scale
    is_eps_leanable: if eps is learnable

Returns:
    torch.Tensor: Normalized features

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

See Also:
    - :class:`TLU`: the learned threshold that follows each of these layers in HyNet.
    - :class:`HyNet`: the patch descriptor built from these layers.

c                ó<   <€ V ^8„  d   QhRS[ RS[RS[RS[RS[RR/# )é   Únum_featuresÚepsÚis_biasÚis_scaleÚis_eps_leanableÚreturnN)ÚintÚfloatÚbool)ÚformatÚ__classdict__s   "€ÚPC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\hynet.pyÚ__annotate__Ú!FilterResponseNorm2d.__annotate__U   sG   ø€ ÷  ñ  áð ñ ð ñ ð	 ñ
 ð ñ ð ð 
ñ ó    c                ó  <€ \         SV `  4        Wn        W n        WPn        W0n        W@n        \        P                  ! \        P                  ! ^V^^4      RR7      V n        \        P                  ! \        P                  ! ^V^^4      RR7      V n        V'       d4   \        P                  ! \        P                  ! V.4      RR7      V n        M'V P!                  R\        P                  ! V.4      4       V P#                  4        R# )é   T©Úrequires_gradr   N)ÚsuperÚ__init__r   Úinit_epsr   r   r   r   Ú	ParameterÚtorchÚonesÚweightÚzerosÚbiasÚtensorr   Úregister_bufferÚreset_parameters)Úselfr   r   r   r   r   Ú	__class__s   &&&&&&€r   r&   ÚFilterResponseNorm2d.__init__U   s¶   ø€ ô 	‰ÑÔà(ÔØŒØ.ÔØŒØ Œä—l’l¤5§:¢:¨a°¸qÀ!Ó#DÐTXÔYˆŒÜ—L’L¤§¢¨Q°¸aÀÓ!CÐSWÔXˆŒ	ßÜ—|’|¤E§L¢L°#°Ó$7ÀtÔLˆD�Hà× Ñ  ¬¯ª°c°UÓ(;Ô<Ø×ÑÖr    c                ó   <€ V ^8„  d   QhRR/# ©r   r   N© )r   r   s   "€r   r   r   m   s   ø€ ÷ 	7ñ 	7 $ñ 	7r    c                ó:  € \         P                  P                  V P                  4       \         P                  P	                  V P
                  4       V P                  '       d7   \         P                  P                  V P                  V P                  4       R# R# )úrReset learnable parameters to their initial values.

Returns:
    None. The module parameters are reset in place.
N)
r   ÚinitÚones_r+   Úzeros_r-   r   Ú	constant_r   r'   ©r1   s   &r   r0   Ú%FilterResponseNorm2d.reset_parametersm   sY   € ô 	�‰�‰�d—k‘kÔ"Ü
�‰�‰�t—y‘yÔ!Ø××ÐÜ�G‰G×Ñ˜dŸh™h¨¯©Ö6ñ  r    c                ó    <€ V ^8„  d   QhRS[ /# ©r   r   ©Ústr)r   r   s   "€r   r   r   x   s   ø€ ÷ Uñ U™Cñ Ur    c                ó:   € RP                   ! R/ V P                  B # )úwReturn a compact text summary for module printing.

Returns:
    Readable string summarizing the module configuration.
z+num_features={num_features}, eps={init_eps}r6   ©r   Ú__dict__r=   s   &r   Ú
extra_reprÚFilterResponseNorm2d.extra_reprx   s   € ð =×CÒCÑTÀdÇmÁmÑTÐTr    c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úxr   ©r)   ÚTensor)r   r   s   "€r   r   r   €   s#   ø€ ÷ ñ ™Ÿ™ð ©%¯,©,ñ r    c                óf  € VP                   pV\        P                  \        P                  39   pV'       d   VP	                  4       pVP                  ^4      P                  ^^.RR7      pV\        P                  ! W@P                  P                  4       ,           4      ,          pV P                  '       d   V P                  V,          pV P                  '       d   WP                  ,           pV'       d:   VP                  \        P                  ! W P                  P                   4      4      pV# )z³Apply filter response normalization to the input tensor.

Args:
    x: Input tensor with shape ``(B, C, H, W)``.

Returns:
    Normalized tensor with the same shape as the input.
T)ÚdimÚkeepdim)Údtyper)   Úfloat16Úbfloat16r   ÚpowÚmeanÚrsqrtr   Úabsr   r+   r   r-   ÚtoÚpromote_types)r1   rK   Úinput_dtypeÚhalfÚnu2s   &&   r   ÚforwardÚFilterResponseNorm2d.forward€   sË   € ð —g‘gˆØœuŸ}™}¬e¯n©nÐ=Ñ=ˆßð —‘“	ˆAà�e‰e�A‹h�m‰m  A °ˆmÓ5ˆð ”—’˜C§(¡(§,¡,£.Õ0Ó1Õ1ˆð �=�=ˆ=Ø—‘˜a•ˆAØ�<�<ˆ<Ø—I‘I•ˆAßð —‘”U×(Ò(¨·h±h·n±nÓEÓFˆAØˆr    )r-   r   r'   r   r   r   r   r+   )g�íµ ÷Æ°>TTF©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r&   r0   rG   r]   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r2   r   s   @@r   r   r   +   s:   ù‡ € ñ'÷R õ  ÷0	7ð 	7÷Uð U÷÷ ð 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# )ÚTLUa‰  Floor each channel at a learned threshold, the TLU activation that follows FRN in HyNet.

``tlu = TLU(C)``, then ``y = tlu(x)`` takes feature maps ``(B, C, H, W)`` and returns
``torch.max(x, tau)``, the input floored at a learned threshold ``tau`` per channel, in the same shape. It is the
activation that the FRN paper pairs with :class:`FilterResponseNorm2d`, which subtracts no mean, in place of a
ReLU. The output dtype is the promotion of the input's and the layer's. This is the TLU layer from 'Filter
Response Normalization Layer: Eliminating Batch Dependence in the Training of Deep Neural Networks', see
:cite:`FRN2019` for more details.

.. math::
    y = \max(x, {\tau})

Convention:
    - :math:`\tau` (``tau``) is a ``(1, num_features, 1, 1)`` parameter, one threshold per channel, initialised
      to -1.

Args:
    num_features: number of channels

Returns:
    torch.Tensor

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

See Also:
    - :class:`FilterResponseNorm2d`: the normalisation that each of these layers follows in HyNet.
    - :class:`HyNet`: the patch descriptor built from these layers.

c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   r   r   N)r   )r   r   s   "€r   r   ÚTLU.__annotate__Â   s   ø€ ÷  ñ  ¡Sð  ¨Tñ  r    c                óº   <€ \         SV `  4        Wn        \        P                  ! \
        P                  ! ^V^^4      ) RR7      V n        V P                  4        R# )z:max(y, tau) = max(y - tau, 0) + tau = ReLU(y - tau) + tau.Tr#   N)	r%   r&   r   r   r(   r)   r*   Útaur0   )r1   r   r2   s   &&€r   r&   ÚTLU.__init__Â   sE   ø€ ä‰ÑÔØ(ÔÜ—<’<¤§¢¨A¨|¸QÀÓ!BÐ BÐRVÔWˆŒØ×ÑÖr    c                ó   <€ V ^8„  d   QhRR/# r5   r6   )r   r   s   "€r   r   rl   É   s   ø€ ÷ (ñ ( $ñ (r    c                óZ   € \         P                  P                  V P                  R4       R# )r8   Néÿÿÿÿ)r   r9   r<   rn   r=   s   &r   r0   ÚTLU.reset_parametersÉ   s   € ô 	�‰×Ñ˜$Ÿ(™( BÖ'r    c                ó    <€ V ^8„  d   QhRS[ /# r@   rA   )r   r   s   "€r   r   rl   Ò   s   ø€ ÷ Eñ E™Cñ Er    c                ó:   € RP                   ! R/ V P                  B # )rD   znum_features={num_features}r6   rE   r=   s   &r   rG   ÚTLU.extra_reprÒ   s   € ð -×3Ò3ÑD°d·m±mÑDÐDr    c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rJ   rL   )r   r   s   "€r   r   rl   Ú   s#   ø€ ÷ 	&ñ 	&™Ÿ™ð 	&©%¯,©,ñ 	&r    c                óB   € \         P                  ! WP                  4      # )z¢Apply the thresholded linear unit to the input tensor.

Args:
    x: Input tensor.

Returns:
    Tensor with the same shape as the input, thresholded by ``tau``.
)r)   Úmaxrn   ©r1   rK   s   &&r   r]   ÚTLU.forwardÚ   s   € ô �yŠy˜ŸH™HÓ%Ð%r    )r   rn   r_   rh   s   @@r   rj   rj   ¡   s:   ù‡ € ñ÷@ ó  ÷(ð (÷Eð E÷	&÷ 	&ð 	&r    rj   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tRtVt	V ;t
# )ÚHyNetay  Describe 32 x 32 grayscale patches with the learned HyNet CNN, built on FRN layers.

``hynet = HyNet()`` builds the network with its pretrained weights (trained on Liberty), in eval mode, and
``descs = hynet(patches)`` takes grayscale patches ``(B, 1, 32, 32)`` and returns unit-norm descriptors
``(B, dim_desc)``, ``(B, 128)`` by default. Its :class:`FilterResponseNorm2d` layers, each followed by
:class:`TLU`, subtract no mean, and the first runs on the raw patch, so unlike :class:`HardNet` its descriptor
changes with an intensity offset (see the Convention block). To describe LAFs on an image, pass it to
:class:`LAFDescriptor`. This is based on the original code from paper "HyNet: Learning Local Descriptor with
Hybrid Similarity Measure and Triplet Loss". See :cite:`hynet2020` for more details.

Convention:
    - It takes the ``(B, 1, 32, 32)`` patches of :class:`~kornia.feature.HardNet` and returns unit-norm rows, but
      its first layer is a :class:`~kornia.feature.FilterResponseNorm2d` on the raw patch, which divides by the root
      mean square and subtracts no mean, as in the reference implementation. A scale :math:`a x` with
      :math:`a > 0` therefore gives the same descriptor as long as the mean squares of the patch and of its scaled
      copy are both large compared with that layer's ``eps``, while an offset :math:`x + b` changes it: feed
      non-negative intensities such as ``[0, 1]`` or ``[0, 255]``, not mean-subtracted or standardised patches.

Args:
    pretrained: Download and set pretrained weights to the model. The weights fit the default ``is_bias``,
        ``is_bias_FRN`` and ``dim_desc`` only, so pass ``pretrained=False`` with another value: the strict load
        raises ``RuntimeError`` for another ``is_bias`` or ``dim_desc``, and ``is_bias_FRN=False`` raises
        ``ValueError`` before downloading, since the weights would load but leave their trained FRN biases unused.
    is_bias: use bias in the convolution layers (the final 8 x 8 convolution has none either way)
    is_bias_FRN:  use bias in FRN layers
    dim_desc: descriptor dimensionality,
    drop_rate: dropout rate,
    eps_l2_norm: to avoid div by zero

Returns:
    HyNet descriptor of the patches.

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

See Also:
    - :class:`HardNet`: a descriptor of the same patches with BatchNorm, which standardises each patch first.
    - :class:`SOSNet`: a descriptor of the same patches, trained with second-order similarity regularisation.
    - :class:`HardNet8`: the wider follow-up of HardNet, with a PCA to 128 dimensions.
    - :class:`FilterResponseNorm2d`: the normalisation layer of this network.
    - :class:`TLU`: the learned-threshold activation that follows each of its FRN layers.
    - :class:`LAFDescriptor`: runs a patch descriptor such as this one on a patch per LAF of an image.

Note:
    With float16 weights, the final BatchNorm keeps its running statistics in float32.
    Convert the model to float16 before calling ``torch.jit.script``.

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

c                óB   <€ V ^8„  d   QhRS[ RS[ RS[ RS[RS[RS[RR/# )	r   Ú
pretrainedr   Úis_bias_FRNÚdim_descÚ	drop_rateÚeps_l2_normr   N)r   r   r   )r   r   s   "€r   r   ÚHyNet.__annotate__   sZ   ø€ ÷ Cñ CáðCñ ðCñ ð	Cñ
 ðCñ ðCñ ðCð 
ñCr    c                ó<  <€ \         SV `  4        V'       d   V'       g   \        R 4      hW`n        W@n        WPn        \        P                  ! \        ^VR7      \        ^4      \        P                  ! ^^ ^^VR7      \        ^ VR7      \        ^ 4      4      V n        \        P                  ! \        P                  ! ^ ^ ^^VR7      \        ^ VR7      \        ^ 4      4      V n        \        P                  ! \        P                  ! ^ ^@^^^VR7      \        ^@VR7      \        ^@4      4      V n        \        P                  ! \        P                  ! ^@^@^^VR7      \        ^@VR7      \        ^@4      4      V n        \        P                  ! \        P                  ! ^@^€^^^VR7      \        ^€VR7      \        ^€4      4      V n        \        P                  ! \        P                  ! ^€^€^^VR7      \        ^€VR7      \        ^€4      4      V n        \#        \        P$                  ! V P
                  4      \        P                  ! ^€V P                  ^RR7      \        P&                  ! V P                  RR7      4      V n        \        P*                  ! ^V P                  ,          RV P                  ,          RR	4      V n        V'       dR   \/        \0        R
,          \2        P4                  ! R4      R7      pV P7                  VRR7       V P9                  4        R# R# )zrHyNet's pretrained weights use their trained FRN biases; pass pretrained=False to build it with is_bias_FRN=False.)r   )Úkernel_sizeÚpaddingr-   )r†   Ústrider‡   r-   F)r†   r-   )Úaffineg       @g      à?g        r   Úcpu)Úmap_locationT)ÚstrictN)r%   r&   Ú
ValueErrorrƒ   r�   r‚   r   Ú
Sequentialr   rj   ÚConv2dÚlayer1Úlayer2Úlayer3Úlayer4Úlayer5Úlayer6r	   ÚDropoutÚBatchNorm2dÚlayer7ÚLocalResponseNormÚ	desc_normr   Úurlsr)   ÚdeviceÚload_state_dictÚeval)	r1   r   r   r€   r�   r‚   rƒ   Úpretrained_dictr2   s	   &&&&&&& €r   r&   ÚHyNet.__init__   sK  ø€ ô 	‰ÑÔßŸkäð%óð ð 'ÔØ ŒØ"ŒÜ—m’mÜ  ¨KÔ8Ü�‹FÜ�IŠI�a˜¨°A¸GÔDÜ  ¨[Ô9Ü�‹Gó
ˆŒô —m’mÜ�IŠI�b˜"¨!°Q¸WÔEÜ  ¨[Ô9Ü�‹Gó
ˆŒô —m’mÜ�IŠI�b˜"¨!°A¸qÀwÔOÜ  ¨[Ô9Ü�‹Gó
ˆŒô —m’mÜ�IŠI�b˜"¨!°Q¸WÔEÜ  ¨[Ô9Ü�‹Gó
ˆŒô
 —m’mÜ�IŠI�b˜#¨1°QÀÈÔPÜ  ¨kÔ:Ü�‹Hó
ˆŒô —m’mÜ�IŠI�c˜3¨A°q¸wÔGÜ  ¨kÔ:Ü�‹Hó
ˆŒô ,Ü�JŠJ�t—~‘~Ó&Ü�IŠI�c˜4Ÿ=™=°a¸eÔDÜ�NŠN˜4Ÿ=™=°Ô7ó
ˆŒô ×-Ò-¨a°$·-±-Õ.?ÀÀtÇ}Á}ÕATÐVYÐ[^Ó_ˆŒçÜ6´t¸IµÔUZ×UaÒUaÐbgÓUhÔiˆOØ× Ñ  ¸Ð Ô>Ø�I‰IŽKñ r    c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rJ   rL   )r   r   s   "€r   r   r„   e  s#   ø€ ÷  ñ  ™Ÿ™ð  ©%¯,©,ñ  r    c                ót  € \        V. RO4       V P                  \        V4      4      pV P                  V4      pV P	                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pVP                  \        P                  \        P                  39   dK   V P                  VP                  4       V P                  ,           4      P!                  VP                  4      pM!V P                  WP                  ,           4      pVP#                  ^4      # )z´Compute HyNet descriptors from grayscale image patches.

Args:
    x: Input grayscale patches with shape ``(B, 1, 32, 32)``.

Returns:
    HyNet descriptors with shape ``(B, D)``.
)ÚBÚ1Ú32r¥   )r   r�   r   r‘   r’   r“   r”   r•   r˜   rQ   r)   rR   rS   rš   r   rƒ   rX   Úflattenrz   s   &&r   r]   ÚHyNet.forwarde  sß   € ô 	˜1Ò4Ô5à�K‰KÔ*¨1Ó-Ó.ˆØ�K‰K˜‹NˆØ�K‰K˜‹NˆØ�K‰K˜‹NˆØ�K‰K˜‹NˆØ�K‰K˜‹NˆØ�K‰K˜‹Nˆð �7‰7”u—}‘}¤e§n¡nÐ5Ô5Ø—‘˜qŸw™w›y¨4×+;Ñ+;Õ;Ó<×?Ñ?ÀÇÁÓH‰Aà—‘˜q×#3Ñ#3Õ3Ó4ˆAØ�y‰y˜‹|Ðr    )rš   r�   r‚   rƒ   r�   r‘   r’   r“   r”   r•   r˜   )TTTé€   g333333Ó?g»½×Ùß|Û=)r`   ra   rb   rc   rd   Ú
patch_sizer&   r]   re   rf   rg   rh   s   @@r   r}   r}   æ   s.   ù‡ € ñ5ðn €J÷Cõ C÷J ÷  ð  r    r}   c                óŽ   € V ^8„  d   Qh/ ^ \         9   d1   \        \        \        \        \        ,          ,          3,          ;R&   # )r   r›   )Ú__conditional_annotations__r   rB   Úlist)r   s   "r   r   r      s,   € × Ñ ÷ &Ò %„dŒ3””dœ3•i•ÐÕ Ñ %ò r    )r«   Útypingr   r)   r   Úkornia.core.checkr   Úkornia.core.downloadr   r   Úkornia.feature._layoutr   Úkornia.feature._normalizationr	   r›   ÚModuler   rj   r}   r   )r«   s   @r   Ú<module>r³      s®   øð÷$ Ò ã Ý å 0ß AÝ 5Ý ?à#%€Ó %á
ˆ7�OÓ$Ø^ð€€Y�ñ
 ˆ7�NÓ#Ø]ð€€[Ñ ñ
 ˆ7�OÓ$Ø^ð€€ZÑ ôs˜2Ÿ9™9ô sôlB&ˆ"�)‰)ô B&ôJ_ˆB�I‰Iö _r    