o
    €o™ií  ã                   @   sh   U d dl mZ d dlZd dlmZ d dlmZ i Zeeef ed< ded< ded	< G d
d„ dej	ƒZ
dS )é    )ÚDictN)Únn)ÚKORNIA_CHECK_SHAPEÚurlszVhttps://github.com/yuruntian/SOSNet/raw/master/sosnet-weights/sosnet_32x32_liberty.pthÚlibzYhttps://github.com/yuruntian/SOSNet/raw/master/sosnet-weights/sosnet_32x32_hpatches_a.pthÚhp_ac                       sL   e Zd ZdZdZddeddf‡ fdd„Zdd
ejde	dejfdd„Z
‡  ZS )ÚSOSNetaò  128-dimensional SOSNet model definition for 32x32 patches.

    This is based on the original code from paper
    "SOSNet:Second Order Similarity Regularization for Local Descriptor Learning".

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

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

    Examples:
        >>> input = torch.rand(8, 1, 32, 32)
        >>> sosnet = SOSNet()
        >>> descs = sosnet(input) # 8x128

    é    FÚ
pretrainedÚreturnNc                    sr  t ƒ  ¡  t tjdddtjddddddtjdddt ¡ tjddddddtjdddt ¡ tjddddddd	tjdddt ¡ tjddddddtjdddt ¡ tjdd
ddddd	tjd
ddt ¡ tjd
d
ddddtjd
ddt ¡ t d¡tjd
d
dddtjd
dd¡| _	t tj
ddddd¡| _|r³tjjtd t d¡d}| j|dd |  ¡  d S )Né   F)Úaffiner	   é   )Úkernel_sizeÚpaddingÚbiasé@   é   )r   Ústrider   r   é€   gš™™™™™¹?é   )r   r   é   g      p@g      à?g        )ÚalphaÚbetaÚkr   Úcpu)Úmap_locationT)Ústrict)ÚsuperÚ__init__r   Ú
SequentialÚInstanceNorm2dÚConv2dÚBatchNorm2dÚReLUÚDropoutÚlayersÚLocalResponseNormÚ	desc_normÚtorchÚhubÚload_state_dict_from_urlr   ÚdeviceÚload_state_dictÚeval)Úselfr
   Úpretrained_dict©Ú	__class__© úI/home/ubuntu/.local/lib/python3.10/site-packages/kornia/feature/sosnet.pyr   4   s<   
êzSOSNet.__init__ç»½×Ùß|Û=ÚinputÚepsc                 C   s8   t |g d¢ƒ |  |  |¡| ¡}| | d¡d¡}|S )N)ÚBÚ1Ú32r:   r   éÿÿÿÿ)r   r(   r&   ÚviewÚsize)r/   r6   r7   Údescrr3   r3   r4   ÚforwardU   s   zSOSNet.forward)F)r5   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
patch_sizeÚboolr   r)   ÚTensorÚfloatr?   Ú__classcell__r3   r3   r1   r4   r      s
    $!r   )Útypingr   r)   r   Úkornia.core.checkr   r   ÚstrÚ__annotations__ÚModuler   r3   r3   r3   r4   Ú<module>   s   