Ë
    T^(h"›  ã            
       ó  — d Z ddlZddlmZ ddlmZmZmZ ddlZddlm	Z	 ddl
mZmZ ddlmZ dd	lmZmZ dd
lmZmZmZ ddlmZ  ej0                  e«      ZdZdZdeej:                     deej:                     deej:                     fd„Zdej:                  dededej:                  fd„Z dej:                  dej:                  dej:                  dedej:                  f
d„Z!dej:                  dej:                  dedej:                  fd„Z"d edej:                  fd!„Z#e G d"„ d#e«      «       Z$ G d$„ d%e	jJ                  «      Z& G d&„ d'e	jJ                  «      Z' G d(„ d)e	jJ                  «      Z( G d*„ d+e	jJ                  «      Z)d,e(iZ* G d-„ d.e	jJ                  «      Z+ G d/„ d0e	jJ                  «      Z, G d1„ d2e	jJ                  «      Z- G d3„ d4e	jJ                  «      Z. G d5„ d6e«      Z/d7Z0d8Z1 ed9e0«       G d:„ d;e/«      «       Z2d6d;gZ3y)<zPyTorch SuperGlue model.é    N)Ú	dataclass)ÚOptionalÚTupleÚUnion)Únn)ÚPreTrainedModelÚadd_start_docstrings)ÚSuperGlueConfigé   )Ú find_pruneable_heads_and_indicesÚprune_linear_layer)ÚModelOutputÚ%add_start_docstrings_to_model_forwardÚloggingé   )ÚAutoModelForKeypointDetectionr
   z%magic-leap-community/superglue_indoorÚtensor_tuple0Útensor_tuple1Úreturnc           
      óˆ   — t        t        | |«      D ��cg c]  \  }}t        j                  ||g«      ‘Œ c}}«      S c c}}w )a'  
    Concatenate two tuples of tensors pairwise

    Args:
        tensor_tuple0 (`Tuple[torch.Tensor]`):
            Tuple of tensors.
        tensor_tuple1 (`Tuple[torch.Tensor]`):
            Tuple of tensors.

    Returns:
        (`Tuple[torch.Tensor]`): Tuple of concatenated tensors.
    )ÚtupleÚzipÚtorchÚcat)r   r   Útensor0Útensor1s       ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/superglue/modeling_superglue.pyÚconcat_pairsr   %   s8   € ô ÌÈMÐ[hÓHi×jÑ4D°G¸W”%—)‘)˜W gÐ.Õ/ÓjÓkÐkùÓjs   •!>
Ú	keypointsÚheightÚwidthc                 óæ   — t        j                  ||g| j                  | j                  ¬«      d   }|dz  }|j	                  dd¬«      j
                  dz  }| |dd…ddd…f   z
  |dd…ddd…f   z  S )a©  
    Normalize keypoints locations based on image image_shape

    Args:
        keypoints (`torch.Tensor` of shape `(batch_size, num_keypoints, 2)`):
            Keypoints locations in (x, y) format.
        height (`int`):
            Image height.
        width (`int`):
            Image width.

    Returns:
        Normalized keypoints locations of shape (`torch.Tensor` of shape `(batch_size, num_keypoints, 2)`).
    )ÚdeviceÚdtypeNr   é   T)Úkeepdimgffffffæ?)r   Útensorr#   r$   ÚmaxÚvalues)r   r    r!   ÚsizeÚcenterÚscalings         r   Únormalize_keypointsr-   5   sv   € ô �<‰<˜ ˜°	×0@Ñ0@È	ÏÉÔXÐY]Ñ^€DØ�A‰X€FØ�h‰h�q $ˆhÓ'×.Ñ.°Ñ4€GØ˜šq $ª˜zÑ*Ñ*¨g²a¸ºq°jÑ.AÑAÐAó    Úlog_cost_matrixÚlog_source_distributionÚlog_target_distributionÚnum_iterationsc                 ór  — t        j                  |«      }t        j                  |«      }t        |«      D ]Z  }|t        j                  | |j	                  d«      z   d¬«      z
  }|t        j                  | |j	                  d«      z   d¬«      z
  }Œ\ | |j	                  d«      z   |j	                  d«      z   S )az  
    Perform Sinkhorn Normalization in Log-space for stability

    Args:
        log_cost_matrix (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`):
            Logarithm of the cost matrix.
        log_source_distribution (`torch.Tensor` of shape `(batch_size, num_rows)`):
            Logarithm of the source distribution.
        log_target_distribution (`torch.Tensor` of shape `(batch_size, num_columns)`):
            Logarithm of the target distribution.

    Returns:
        log_cost_matrix (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`): Logarithm of the optimal
        transport matrix.
    r%   r   ©Údim)r   Ú
zeros_likeÚrangeÚ	logsumexpÚ	unsqueeze)r/   r0   r1   r2   Úlog_u_scalingÚlog_v_scalingÚ_s          r   Úlog_sinkhorn_iterationsr=   J   sµ   € ô* ×$Ñ$Ð%<Ó=€MÜ×$Ñ$Ð%<Ó=€MÜ�>Ó"ò wˆØ/´%·/±/À/ÐTa×TkÑTkÐlmÓTnÑBnÐtuÔ2vÑvˆØ/´%·/±/À/ÐTa×TkÑTkÐlmÓTnÑBnÐtuÔ2vÑv‰ðwð ˜]×4Ñ4°QÓ7Ñ7¸-×:QÑ:QÐRSÓ:TÑTÐTr.   ÚscoresÚ	reg_paramÚ
iterationsc                 ó  — | j                   \  }}}| j                  d«      }||z  j                  | «      ||z  j                  | «      }}|j                  ||d«      }	|j                  |d|«      }
|j                  |dd«      }t	        j
                  t	        j
                  | |	gd«      t	        j
                  |
|gd«      gd«      }||z   j                  «        }t	        j
                  |j                  |«      |j                  «       d   |z   g«      }t	        j
                  |j                  |«      |j                  «       d   |z   g«      }|d   j                  |d«      |d   j                  |d«      }}t        ||||¬«      }||z
  }|S )a  
    Perform Differentiable Optimal Transport in Log-space for stability

    Args:
        scores: (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`):
            Cost matrix.
        reg_param: (`torch.Tensor` of shape `(batch_size, 1, 1)`):
            Regularization parameter.
        iterations: (`int`):
            Number of Sinkhorn iterations.

    Returns:
        log_optimal_transport_matrix: (`torch.Tensor` of shape `(batch_size, num_rows, num_columns)`): Logarithm of the
        optimal transport matrix.
    r%   éÿÿÿÿN)r2   )ÚshapeÚ
new_tensorÚtoÚexpandr   r   Úlogr=   )r>   r?   r@   Ú
batch_sizeÚnum_rowsÚnum_columnsÚ
one_tensorÚnum_rows_tensorÚnum_columns_tensorÚsource_reg_paramÚtarget_reg_paramÚ	couplingsÚlog_normalizationr0   r1   Úlog_optimal_transport_matrixs                   r   Úlog_optimal_transportrS   g   s±  € ð  )/¯©Ñ%€J�˜+Ø×"Ñ" 1Ó%€JØ+3°jÑ+@×*DÑ*DÀVÓ*LÈ{Ð]gÑOg×NkÑNkÐlrÓNsÐ'€Oà ×'Ñ'¨
°H¸aÓ@ÐØ ×'Ñ'¨
°A°{ÓCÐØ× Ñ  ¨Q°Ó2€Iä—	‘	œ5Ÿ9™9 fÐ.>Ð%?ÀÓDÄeÇiÁiÐQaÐclÐPmÐoqÓFrÐsÐuvÓw€Ià)Ð,>Ñ>×CÑCÓEÐEÐÜ#Ÿi™iØ	×	!Ñ	! (Ó	+Ð-?×-CÑ-CÓ-EÀdÑ-KÐN_Ñ-_Ð`óÐô $Ÿi™iØ	×	!Ñ	! +Ó	.°×0CÑ0CÓ0EÀdÑ0KÐN_Ñ0_Ð`óÐð 	  Ñ%×,Ñ,¨Z¸Ó<Ø Ñ%×,Ñ,¨Z¸Ó<ð 5Ðô
 $;ØÐ*Ð,CÐT^ô$Ð ð $@ÐBSÑ#SÐ Ø'Ð'r.   r5   c                 ób   — | j                  | j                  |   «      j                  d«      dz
  S ©Nr   r%   )Únew_onesrC   Úcumsum)Úxr5   s     r   Úarange_likerY   ”   s)   € Ø�:‰:�a—g‘g˜c‘lÓ#×*Ñ*¨1Ó-°Ñ1Ð1r.   c                   ó6  — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeeej                        ed<   dZeeej                        ed	<   y)
ÚKeypointMatchingOutputa,  
    Base class for outputs of keypoint matching models. Due to the nature of keypoint detection and matching, the number
    of keypoints is not fixed and can vary from image to image, which makes batching non-trivial. In the batch of
    images, the maximum number of matches is set as the dimension of the matches and matching scores. The mask tensor is
    used to indicate which values in the keypoints, matches and matching_scores tensors are keypoint matching
    information.

    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*):
            Loss computed during training.
        mask (`torch.IntTensor` of shape `(batch_size, num_keypoints)`):
            Mask indicating which values in matches and matching_scores are keypoint matching information.
        matches (`torch.FloatTensor` of shape `(batch_size, 2, num_matches)`):
            Index of keypoint matched in the other image.
        matching_scores (`torch.FloatTensor` of shape `(batch_size, 2, num_matches)`):
            Scores of predicted matches.
        keypoints (`torch.FloatTensor` of shape `(batch_size, num_keypoints, 2)`):
            Absolute (x, y) coordinates of predicted keypoints in a given image.
        hidden_states (`Tuple[torch.FloatTensor, ...]`, *optional*):
            Tuple of `torch.FloatTensor` (one for the output of each stage) of shape `(batch_size, 2, num_channels,
            num_keypoints)`, returned when `output_hidden_states=True` is passed or when
            `config.output_hidden_states=True`)
        attentions (`Tuple[torch.FloatTensor, ...]`, *optional*):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, 2, num_heads, num_keypoints,
            num_keypoints)`, returned when `output_attentions=True` is passed or when `config.output_attentions=True`)
    NÚlossÚmatchesÚmatching_scoresr   ÚmaskÚhidden_statesÚ
attentions)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r\   r   r   ÚFloatTensorÚ__annotations__r]   r^   r   r_   Ú	IntTensorr`   r   ra   © r.   r   r[   r[   ˜   s¤   … ñð6 )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø+/€GˆX�e×'Ñ'Ñ(Ó/Ø37€O�X˜e×/Ñ/Ñ0Ó7Ø-1€Iˆx˜×)Ñ)Ñ*Ó1Ø&*€Dˆ(�5—?‘?Ñ
#Ó*Ø8<€M�8˜E %×"3Ñ"3Ñ4Ñ5Ó<Ø59€J�˜˜u×0Ñ0Ñ1Ñ2Ô9r.   r[   c                   óh   ‡ — e Zd Zdedededdfˆ fd„Zdej                  dej                  fd„Zˆ xZ	S )	ÚSuperGlueMultiLayerPerceptronÚconfigÚin_channelsÚout_channelsr   Nc                 ó¾   •— t         ‰| �  «        t        j                  ||«      | _        t        j
                  |«      | _        t        j                  «       | _        y ©N)	ÚsuperÚ__init__r   ÚLinearÚlinearÚBatchNorm1dÚ
batch_normÚReLUÚ
activation)Úselfrl   rm   rn   Ú	__class__s       €r   rr   z&SuperGlueMultiLayerPerceptron.__init__¿   s=   ø€ Ü‰ÑÔÜ—i‘i ¨\Ó:ˆŒÜŸ.™.¨Ó6ˆŒÜŸ'™'›)ˆ�r.   Úhidden_statec                 ó´   — | j                  |«      }|j                  dd«      }| j                  |«      }|j                  dd«      }| j                  |«      }|S )NrB   éþÿÿÿ)rt   Ú	transposerv   rx   )ry   r{   s     r   Úforwardz%SuperGlueMultiLayerPerceptron.forwardÅ   sV   € Ø—{‘{ <Ó0ˆØ#×-Ñ-¨b°"Ó5ˆØ—‘ |Ó4ˆØ#×-Ñ-¨b°"Ó5ˆØ—‘ |Ó4ˆØÐr.   )
rb   rc   rd   r
   Úintrr   r   ÚTensorr   Ú__classcell__©rz   s   @r   rk   rk   ¾   sA   ø„ ð$˜ð $¸Sð $ÐPSð $ÐX\õ $ð E§L¡Lð °U·\±\÷ r.   rk   c                   ó°   ‡ — e Zd Zdeddfˆ fd„Z	 d	dej                  dej                  dee   de	ej                  ee	ej                        f   fd„Z
ˆ xZS )
ÚSuperGlueKeypointEncoderrl   r   Nc           	      ól  •— t         ‰| �  «        |j                  }|j                  }dg|z   |gz   }t	        dt        |«      dz
  «      D �cg c]  }t        |||dz
     ||   «      ‘Œ }}|j                  t        j                  |d   |d   «      «       t        j                  |«      | _        y c c}w )Nr   r%   r}   rB   )rq   rr   Úkeypoint_encoder_sizesÚhidden_sizer7   Úlenrk   Úappendr   rs   Ú
ModuleListÚencoder)ry   rl   Úlayer_sizesrˆ   Úencoder_channelsÚiÚlayersrz   s          €r   rr   z!SuperGlueKeypointEncoder.__init__Ï   s½   ø€ Ü‰ÑÔØ×3Ñ3ˆØ×(Ñ(ˆà˜3 Ñ,°¨}Ñ<Ðô ˜1œcÐ"2Ó3°aÑ7Ó8ö
àô *¨&Ð2BÀ1ÀqÁ5Ñ2IÐK[Ð\]ÑK^Õ_ð
ˆð 
ð 	�‰”b—i‘iÐ 0°Ñ 4Ð6FÀrÑ6JÓKÔLÜ—}‘} VÓ,ˆ�ùò
s   ÁB1r   r>   Úoutput_hidden_statesc                 ó®   — |j                  d«      }t        j                  ||gd¬«      }|rdnd }| j                  D ]  } ||«      }|sŒ||fz   }Œ ||fS )Nr   r4   ri   )r9   r   r   rŒ   )ry   r   r>   r‘   r{   Úall_hidden_statesÚlayers          r   r   z SuperGlueKeypointEncoder.forwardÝ   sp   € ð ×!Ñ! !Ó$ˆÜ—y‘y )¨VÐ!4¸!Ô<ˆÙ"6™B¸DÐØ—\‘\ò 	HˆEÙ  Ó.ˆLÚ#Ø$5¸¸Ñ$GÑ!ð	Hð Ð.Ð.Ð.r.   )F©rb   rc   rd   r
   rr   r   r�   r   Úboolr   r   r‚   rƒ   s   @r   r…   r…   Î   sn   ø„ ð-˜ð -°4õ -ð$ 05ñ	/à—<‘<ð/ð —‘ð/ð ' t™nð	/ð
 
ˆu�|‰|˜X e¨E¯L©LÑ&9Ñ:Ð:Ñ	;÷/r.   r…   c                   óP  ‡ — e Zd Zdˆ fd„	Zdej
                  dej
                  fd„Z	 	 	 	 	 	 ddej
                  deej                     deej                     deej                     d	eej                     d
ee	e	ej                           dee
   de	ej
                     fd„Zˆ xZS )ÚSuperGlueSelfAttentionc                 óâ  •— t         ‰| �  «        |j                  |j                  z  dk7  r2t	        |d«      s&t        d|j                  › d|j                  › d�«      ‚|j                  | _        t        |j                  |j                  z  «      | _        | j                  | j                  z  | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  «      | _        |xs t#        |dd«      | _        | j$                  dk(  s| j$                  d	k(  rF|j&                  | _        t        j(                  d
|j&                  z  dz
  | j                  «      | _        |j,                  | _        y )Nr   Úembedding_sizezThe hidden size (z6) is not a multiple of the number of attention heads (ú)Úposition_embedding_typeÚabsoluteÚrelative_keyÚrelative_key_queryr   r%   )rq   rr   rˆ   Únum_attention_headsÚhasattrÚ
ValueErrorr€   Úattention_head_sizeÚall_head_sizer   rs   ÚqueryÚkeyÚvalueÚDropoutÚattention_probs_dropout_probÚdropoutÚgetattrrœ   Úmax_position_embeddingsÚ	EmbeddingÚdistance_embeddingÚ
is_decoder©ry   rl   rœ   rz   s      €r   rr   zSuperGlueSelfAttention.__init__ï   s�  ø€ Ü‰ÑÔØ×Ñ × :Ñ :Ñ:¸aÒ?ÌÐPVÐXhÔHiÜØ# F×$6Ñ$6Ð#7ð 8Ø ×4Ñ4Ð5°Qð8óð ð
 $*×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÑ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÑPˆÔä—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
Ü—9‘9˜V×/Ñ/°×1CÑ1CÓDˆŒÜ—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
ä—z‘z &×"EÑ"EÓFˆŒØ'>ò (
Ä'ØÐ-¨zóC
ˆÔ$ð ×'Ñ'¨>Ò9¸T×=YÑ=YÐ]qÒ=qØ+1×+IÑ+IˆDÔ(Ü&(§l¡l°1°v×7UÑ7UÑ3UÐXYÑ3YÐ[_×[sÑ[sÓ&tˆDÔ#à ×+Ñ+ˆ�r.   rX   r   c                 ó¤   — |j                  «       d d | j                  | j                  fz   }|j                  |«      }|j	                  dddd«      S )NrB   r   r   r%   r   )r*   r    r£   ÚviewÚpermute)ry   rX   Únew_x_shapes      r   Útranspose_for_scoresz+SuperGlueSelfAttention.transpose_for_scores	  sL   € Ø—f‘f“h˜s �m t×'?Ñ'?À×AYÑAYÐ&ZÑZˆØ�F‰F�;ÓˆØ�y‰y˜˜A˜q !Ó$Ð$r.   r`   Úattention_maskÚ	head_maskÚencoder_hidden_statesÚencoder_attention_maskÚpast_key_valueÚoutput_attentionsc                 ó$  — | j                  |«      }|d u}	|	r|�|d   }
|d   }|}�n |	rC| j                  | j                  |«      «      }
| j                  | j                  |«      «      }|}n»|�y| j                  | j                  |«      «      }
| j                  | j                  |«      «      }t	        j
                  |d   |
gd¬«      }
t	        j
                  |d   |gd¬«      }n@| j                  | j                  |«      «      }
| j                  | j                  |«      «      }| j                  |«      }|d u}| j                  r|
|f}t	        j                  ||
j                  dd«      «      }| j                  dk(  s| j                  dk(  �r—|j                  d   |
j                  d   }}|rDt	        j                  |dz
  t        j                  |j                  ¬	«      j                  dd«      }n@t	        j                  |t        j                  |j                  ¬	«      j                  dd«      }t	        j                  |t        j                  |j                  ¬	«      j                  dd«      }||z
  }| j!                  || j"                  z   dz
  «      }|j%                  |j&                  ¬
«      }| j                  dk(  rt	        j(                  d||«      }||z   }nE| j                  dk(  r6t	        j(                  d||«      }t	        j(                  d|
|«      }||z   |z   }|t+        j,                  | j.                  «      z  }|�||z   }t0        j2                  j5                  |d¬«      }| j7                  |«      }|�||z  }t	        j                  ||«      }|j9                  dddd«      j;                  «       }|j=                  «       d d | j>                  fz   }|j                  |«      }|r||fn|f}| j                  r||fz   }|S )Nr   r%   r   r4   rB   r}   rž   rŸ   )r$   r#   ©r$   zbhld,lrd->bhlrzbhrd,lrd->bhlrr   ) r¥   rµ   r¦   r§   r   r   r¯   Úmatmulr~   rœ   rC   r'   Úlongr#   r²   Úaranger®   r¬   rE   r$   ÚeinsumÚmathÚsqrtr£   r   Ú
functionalÚsoftmaxrª   r³   Ú
contiguousr*   r¤   )ry   r`   r¶   r·   r¸   r¹   rº   r»   Úmixed_query_layerÚis_cross_attentionÚ	key_layerÚvalue_layerÚquery_layerÚ	use_cacheÚattention_scoresÚquery_lengthÚ
key_lengthÚposition_ids_lÚposition_ids_rÚdistanceÚpositional_embeddingÚrelative_position_scoresÚrelative_position_scores_queryÚrelative_position_scores_keyÚattention_probsÚcontext_layerÚnew_context_layer_shapeÚoutputss                               r   r   zSuperGlueSelfAttention.forward  sç  € ð !ŸJ™J }Ó5Ðð
 3¸$Ð>Ðá .Ð"<à& qÑ)ˆIØ(¨Ñ+ˆKØ3ŠNÙØ×1Ñ1°$·(±(Ð;PÓ2QÓRˆIØ×3Ñ3°D·J±JÐ?TÓ4UÓVˆKØ3‰NØÐ'Ø×1Ñ1°$·(±(¸=Ó2IÓJˆIØ×3Ñ3°D·J±J¸}Ó4MÓNˆKÜŸ	™	 >°!Ñ#4°iÐ"@ÀaÔHˆIÜŸ)™) ^°AÑ%6¸Ð$DÈ!ÔL‰Kà×1Ñ1°$·(±(¸=Ó2IÓJˆIØ×3Ñ3°D·J±J¸}Ó4MÓNˆKà×/Ñ/Ð0AÓBˆà"¨$Ð.ˆ	Ø�?Š?ð (¨Ð5ˆNô !Ÿ<™<¨°Y×5HÑ5HÈÈRÓ5PÓQÐà×'Ñ'¨>Ò9¸T×=YÑ=YÐ]qÓ=qØ'2×'8Ñ'8¸Ñ';¸Y¿_¹_ÈQÑ=O˜*ˆLÙÜ!&§¡¨j¸1©nÄEÇJÁJÐWd×WkÑWkÔ!l×!qÑ!qØ˜ó"‘ô "'§¡¨lÄ%Ç*Á*ÐUb×UiÑUiÔ!j×!oÑ!oÐprÐtuÓ!v�Ü"Ÿ\™\¨*¼E¿J¹JÈ}×OcÑOcÔd×iÑiÐjkÐmoÓpˆNØ%¨Ñ6ˆHà#'×#:Ñ#:¸8Àd×FbÑFbÑ;bÐefÑ;fÓ#gÐ Ø#7×#:Ñ#:À×ARÑARÐ#:Ó#SÐ à×+Ñ+¨~Ò=Ü+0¯<©<Ð8HÈ+ÐWkÓ+lÐ(Ø#3Ð6NÑ#NÑ Ø×-Ñ-Ð1EÒEÜ16·±Ð>NÐP[Ð]qÓ1rÐ.Ü/4¯|©|Ð<LÈiÐYmÓ/nÐ,Ø#3Ð6TÑ#TÐWsÑ#sÐ à+¬d¯i©i¸×8PÑ8PÓ.QÑQÐØÐ%à/°.Ñ@Ðô Ÿ-™-×/Ñ/Ð0@ÀbÐ/ÓIˆð Ÿ,™, Ó7ˆð Ð Ø-°	Ñ9ˆOäŸ™ _°kÓBˆà%×-Ñ-¨a°°A°qÓ9×DÑDÓFˆØ"/×"4Ñ"4Ó"6°s¸Ð";¸t×?QÑ?QÐ>SÑ"SÐØ%×*Ñ*Ð+BÓCˆá6G�= /Ñ2ÈmÐM]ˆà�?Š?Ø Ð 1Ñ1ˆGØˆr.   rp   ©NNNNNF)rb   rc   rd   rr   r   r�   rµ   r   rf   r   r–   r   r‚   rƒ   s   @r   r˜   r˜   î   så   ø„ õ,ð4% e§l¡lð %°u·|±|ó %ð 7;Ø15Ø=AØ>BØDHØ,1ñcà—|‘|ðcð ! ×!2Ñ!2Ñ3ðcð ˜E×-Ñ-Ñ.ð	cð
  (¨×(9Ñ(9Ñ:ðcð !)¨×):Ñ):Ñ ;ðcð !  u¨U×->Ñ->Ñ'?Ñ!@ÑAðcð $ D™>ðcð 
ˆu�|‰|Ñ	÷cr.   r˜   c                   ó\   ‡ — e Zd Zdefˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚSuperGlueSelfOutputrl   c                 ó€   •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        y rp   )rq   rr   r   rs   rˆ   Údense)ry   rl   rz   s     €r   rr   zSuperGlueSelfOutput.__init__u  s,   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆ�
r.   r`   r   c                 ó(   — | j                  |«      }|S rp   )rß   )ry   r`   Úargss      r   r   zSuperGlueSelfOutput.forwardy  s   € ØŸ
™
 =Ó1ˆØÐr.   ©	rb   rc   rd   r
   rr   r   r�   r   r‚   rƒ   s   @r   rÝ   rÝ   t  s,   ø„ ðG˜õ Gð U§\¡\ð ¸U¿\¹\÷ r.   rÝ   Úeagerc                   ó  ‡ — e Zd Zdˆ fd„	Zd„ Z	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     dee	e	ej                           d	ee
   d
e	ej                     fd„Zˆ xZS )ÚSuperGlueAttentionc                 óž   •— t         ‰| �  «        t        |j                     ||¬«      | _        t        |«      | _        t        «       | _        y )N)rœ   )	rq   rr   Ú SUPERGLUE_SELF_ATTENTION_CLASSESÚ_attn_implementationry   rÝ   ÚoutputÚsetÚpruned_headsr°   s      €r   rr   zSuperGlueAttention.__init__…  sC   ø€ Ü‰ÑÔÜ4°V×5PÑ5PÑQØÐ,Cô
ˆŒ	ô *¨&Ó1ˆŒÜ›EˆÕr.   c                 ó>  — t        |«      dk(  ry t        || j                  j                  | j                  j                  | j
                  «      \  }}t        | j                  j                  |«      | j                  _        t        | j                  j                  |«      | j                  _        t        | j                  j                  |«      | j                  _	        t        | j                  j                  |d¬«      | j                  _        | j                  j                  t        |«      z
  | j                  _        | j                  j                  | j                  j                  z  | j                  _        | j
                  j                  |«      | _        y )Nr   r%   r4   )r‰   r   ry   r    r£   rë   r   r¥   r¦   r§   ré   rß   r¤   Úunion)ry   ÚheadsÚindexs      r   Úprune_headszSuperGlueAttention.prune_heads�  s  € Üˆu‹:˜Š?ØÜ7Ø�4—9‘9×0Ñ0°$·)±)×2OÑ2OÐQU×QbÑQbó
‰ˆˆuô
 -¨T¯Y©Y¯_©_¸eÓDˆ�	‰	ŒÜ*¨4¯9©9¯=©=¸%Ó@ˆ�	‰	ŒÜ,¨T¯Y©Y¯_©_¸eÓDˆ�	‰	ŒÜ.¨t¯{©{×/@Ñ/@À%ÈQÔOˆ�‰Ôð )-¯	©	×(EÑ(EÌÈEË
Ñ(Rˆ�	‰	Ô%Ø"&§)¡)×"?Ñ"?À$Ç)Á)×B_ÑB_Ñ"_ˆ�	‰	ÔØ ×-Ñ-×3Ñ3°EÓ:ˆÕr.   r`   r¶   r·   r¸   r¹   rº   r»   r   c           	      óp   — | j                  |||||||«      }| j                  |d   |«      }	|	f|dd  z   }
|
S rU   )ry   ré   )ry   r`   r¶   r·   r¸   r¹   rº   r»   Úself_outputsÚattention_outputrÚ   s              r   r   zSuperGlueAttention.forwardŸ  sW   € ð —y‘yØØØØ!Ø"ØØó
ˆð  Ÿ;™; |°A¡¸ÓFÐØ#Ð%¨°Q°RÐ(8Ñ8ˆØˆr.   rp   rÛ   )rb   rc   rd   rr   rð   r   r�   r   rf   r   r–   r   r‚   rƒ   s   @r   rå   rå   „  sÆ   ø„ õ"ò;ð* 7;Ø15Ø=AØ>BØDHØ,1ñà—|‘|ðð ! ×!2Ñ!2Ñ3ðð ˜E×-Ñ-Ñ.ð	ð
  (¨×(9Ñ(9Ñ:ðð !)¨×):Ñ):Ñ ;ðð !  u¨U×->Ñ->Ñ'?Ñ!@ÑAðð $ D™>ðð 
ˆu�|‰|Ñ	÷r.   rå   c                   ó  ‡ — e Zd Zdeddfˆ fd„Z	 	 	 	 	 ddej                  deej                     deej                     deej                     d	ed
ede	ej                  ee	ej                        ee	ej                        f   fd„Z
ˆ xZS )ÚSuperGlueAttentionalPropagationrl   r   Nc           	      óv  •— t         ‰| �  «        |j                  }t        |«      | _        |dz  |dz  |g}t        dt        |«      dz
  «      D �cg c]  }t        |||dz
     ||   «      ‘Œ }}|j                  t        j                  |d   |d   «      «       t        j                  |«      | _        y c c}w )Nr   r%   r}   rB   )rq   rr   rˆ   rå   Ú	attentionr7   r‰   rk   rŠ   r   rs   r‹   Úmlp)ry   rl   rˆ   Úmlp_channelsr�   r�   rz   s         €r   rr   z(SuperGlueAttentionalPropagation.__init__¸  s¸   ø€ Ü‰ÑÔØ×(Ñ(ˆÜ+¨FÓ3ˆŒØ# a™¨°q©¸+ÐFˆô ˜1œc ,Ó/°!Ñ3Ó4ö
àô *¨&°,¸qÀ1¹uÑ2EÀ|ÐTUÁÕWð
ˆð 
ð 	�‰”b—i‘i ¨RÑ 0°,¸rÑ2BÓCÔDÜ—=‘= Ó(ˆ�ùò
s   ÁB6Údescriptorsr¶   r¸   r¹   r»   r‘   c                 óÎ   — | j                  |||||¬«      }|d   }|dd  }	t        j                  ||gd¬«      }
|rdnd }| j                  D ]  } ||
«      }
|sŒ||
fz   }Œ |
||	fS )N)r¶   r¸   r¹   r»   r   r%   r   r4   ri   )r÷   r   r   rø   )ry   rú   r¶   r¸   r¹   r»   r‘   Úattention_outputsré   r÷   r{   r“   r”   s                r   r   z'SuperGlueAttentionalPropagation.forwardÄ  s�   € ð !ŸN™NØØ)Ø"7Ø#9Ø/ð +ó 
Ðð # 1Ñ%ˆØ% a bÐ)ˆ	ä—y‘y +¨vÐ!6¸AÔ>ˆá"6™B¸DÐØ—X‘Xò 	HˆEÙ  Ó.ˆLÚ#Ø$5¸¸Ñ$GÑ!ð	Hð
 Ð.°	Ð9Ð9r.   )NNNFFr•   rƒ   s   @r   rõ   rõ   ·  s»   ø„ ð
)˜ð 
)°4õ 
)ð 26Ø8<Ø9=Ø"'Ø%*ñ:à—\‘\ð:ð ! §¡Ñ.ð:ð  (¨¯©Ñ5ð	:ð
 !)¨¯©Ñ 6ð:ð  ð:ð #ð:ð 
ˆu�|‰|˜X e¨E¯L©LÑ&9Ñ:¸HÀUÈ5Ï<É<ÑEXÑ<YÐYÑ	Z÷:r.   rõ   c                   ó¬   ‡ — e Zd Zdeddfˆ fd„Z	 	 	 d
dej                  deej                     dedee   de	ej                  ee	   ee	   f   f
d	„Z
ˆ xZS )ÚSuperGlueAttentionalGNNrl   r   Nc                 ó
  •— t         ‰| �  «        |j                  | _        |j                  | _        t        j                  t        t        | j                  «      «      D �cg c]  }t        |«      ‘Œ c}«      | _
        y c c}w rp   )rq   rr   rˆ   Úgnn_layers_typesÚlayers_typesr   r‹   r7   r‰   rõ   r�   )ry   rl   r<   rz   s      €r   rr   z SuperGlueAttentionalGNN.__init__ã  sb   ø€ Ü‰ÑÔØ!×-Ñ-ˆÔØ"×3Ñ3ˆÔÜ—m‘mÔV[Ô\_Ð`d×`qÑ`qÓ\rÓVsÖ$tÐQRÔ%DÀVÕ%LÒ$tÓuˆ�ùÒ$ts   Á!B rú   r_   r»   r‘   c           	      ó  — |rdnd }|rdnd }|j                   \  }}}	|r||fz   }t        | j                  | j                  «      D ]¼  \  }
}d }d }|dk(  r‚|j	                  dd|| j
                  «      j                  d«      j	                  ||| j
                  «      }|�6|j	                  dddd|«      j                  d«      j	                  |dd|«      nd } |
||||||¬«      }|d   }|r||d   z   }|r||d   z   }||z   }Œ¾ |||fS )Nri   ÚcrossrB   r   r%   )r¶   r¸   r¹   r‘   r»   r   )rC   r   r�   r  Úreshaperˆ   Úflip)ry   rú   r_   r»   r‘   r“   Úall_attentionsrH   Únum_keypointsr<   Ú	gnn_layerÚ
layer_typer¸   r¹   Úgnn_outputsÚdeltas                   r   r   zSuperGlueAttentionalGNN.forwardé  sY  € ñ #7™B¸DÐÙ0™°dˆà'2×'8Ñ'8Ñ$ˆ
�M 1ÙØ 1°[°NÑ BÐä%(¨¯©°d×6GÑ6GÓ%Hò 	.Ñ!ˆI�zØ$(Ð!Ø%)Ð"Ø˜WÒ$à×'Ñ'¨¨A¨}¸d×>NÑ>NÓOß‘T˜!“Wß‘W˜Z¨¸×8HÑ8HÓIð &ð Ð'ð —L‘L  Q¨¨1¨mÓ<×AÑAÀ!ÓD×LÑLÈZÐYZÐ\]Ð_lÔmàð 'ñ $ØØ#Ø&;Ø'=Ø%9Ø"3ôˆKð   ‘NˆEá#Ø$5¸ÀA¹Ñ$FÐ!Ù Ø!/°+¸a±.Ñ!@�à%¨Ñ-‰Kð=	.ð> Ð-¨~Ð=Ð=r.   )NFFr•   rƒ   s   @r   rþ   rþ   â  s‚   ø„ ðv˜ð v°4õ vð (,Ø"'Ø/4ñ->à—\‘\ð->ð �u—|‘|Ñ$ð->ð  ð	->ð
 ' t™nð->ð 
ˆu�|‰|˜X e™_¨h°u©oÐ=Ñ	>÷->r.   rþ   c                   ó`   ‡ — e Zd Zdeddfˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚSuperGlueFinalProjectionrl   r   Nc                 ót   •— t         ‰| �  «        |j                  }t        j                  ||d¬«      | _        y )NT)Úbias)rq   rr   rˆ   r   rs   Ú
final_proj)ry   rl   rˆ   rz   s      €r   rr   z!SuperGlueFinalProjection.__init__  s-   ø€ Ü‰ÑÔØ×(Ñ(ˆÜŸ)™) K°À4ÔHˆ�r.   rú   c                 ó$   — | j                  |«      S rp   )r  )ry   rú   s     r   r   z SuperGlueFinalProjection.forward  s   € Ø�‰˜{Ó+Ð+r.   râ   rƒ   s   @r   r  r    s4   ø„ ðI˜ð I°4õ Ið
, 5§<¡<ð ,°E·L±L÷ ,r.   r  c                   ó@   — e Zd ZdZeZdZdZdej                  ddfd„Z
y)ÚSuperGluePreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    Ú	superglueÚpixel_valuesÚmoduler   Nc                 ó¢  — t        |t        j                  t        j                  t        j                  f«      rm|j
                  j                  j                  d| j                  j                  ¬«       |j                  �%|j                  j                  j                  «        yyt        |t        j                  «      rJ|j                  j                  j                  «        |j
                  j                  j                  d«       yt        |t        «      r5t        j                  j!                  |j"                  j                  d«       yy)zInitialize the weightsg        )ÚmeanÚstdNç      ð?)Ú
isinstancer   rs   ÚConv2dÚConv1dÚweightÚdataÚnormal_rl   Úinitializer_ranger  Úzero_Ú	LayerNormÚfill_rk   ÚinitÚ	constant_rt   )ry   r  s     r   Ú_init_weightsz&SuperGluePreTrainedModel._init_weights-  s×   € ä�fœrŸy™y¬"¯)©)´R·Y±YÐ?Ô@ð �M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)Ü˜Ô =Ô>Ü�G‰G×Ñ˜fŸm™m×0Ñ0°#Õ6ð ?r.   )rb   rc   rd   re   r
   Úconfig_classÚbase_model_prefixÚmain_input_namer   ÚModuler'  ri   r.   r   r  r  #  s0   „ ñð
 #€LØ#ÐØ$€Oð7 B§I¡Ið 7°$ô 7r.   r  aO  
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`SuperGlueConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
    añ  
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`SuperGlueImageProcessor`]. See
            [`SuperGlueImageProcessor.__call__`] for details.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors. See `attentions` under returned tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
zLSuperGlue model taking images as inputs and outputting the matching of them.c                   ó‚  ‡ — e Zd ZdZdeddfˆ fd„Z	 	 	 ddej                  dej                  dej                  d	ed
ede	ej                     de	e
   de	e
   deej                  ej                  eef   fd„Z ee«      	 	 	 	 ddej                  de	ej                      de	e
   de	e
   de	e
   deeef   fd„«       Zˆ xZS )ÚSuperGlueForKeypointMatchingað  SuperGlue feature matching middle-end

    Given two sets of keypoints and locations, we determine the
    correspondences by:
      1. Keypoint Encoding (normalization + visual feature and location fusion)
      2. Graph Neural Network with multiple self and cross-attention layers
      3. Final projection layer
      4. Optimal Transport Layer (a differentiable Hungarian matching algorithm)
      5. Thresholding matrix based on mutual exclusivity and a match_threshold

    The correspondence ids use -1 to indicate non-matching points.

    Paul-Edouard Sarlin, Daniel DeTone, Tomasz Malisiewicz, and Andrew
    Rabinovich. SuperGlue: Learning Feature Matching with Graph Neural
    Networks. In CVPR, 2020. https://arxiv.org/abs/1911.11763
    rl   r   Nc                 ót  •— t         ‰| �  |«       t        j                  |j                  «      | _        t        |«      | _        t        |«      | _	        t        |«      | _        t        j                  j                  t        j                  d«      «      }| j!                  d|«       | j#                  «        y )Nr  Ú	bin_score)rq   rr   r   Úfrom_configÚkeypoint_detector_configÚkeypoint_detectorr…   Úkeypoint_encoderrþ   Úgnnr  Úfinal_projectionr   r   Ú	Parameterr'   Úregister_parameterÚ	post_init)ry   rl   r/  rz   s      €r   rr   z%SuperGlueForKeypointMatching.__init__l  s†   ø€ Ü‰Ñ˜Ô ä!>×!JÑ!JÈ6×KjÑKjÓ!kˆÔä 8¸Ó @ˆÔÜ*¨6Ó2ˆŒÜ 8¸Ó @ˆÔä—H‘H×&Ñ&¤u§|¡|°CÓ'8Ó9ˆ	Ø×Ñ ¨YÔ7à�‰Õr.   r   rú   r>   r    r!   r_   r»   r‘   c	                 óD	  ‡&‡'— |rdnd}	|rdnd}
|j                   d   dk(  rD|j                   dd }|j                  |dt        j                  ¬«      |j	                  |«      |	|
fS |j                   \  Š&}Š'}|j                  ‰&dz  ‰'d«      }|j                  ‰&dz  ‰'| j                  j                  «      }|j                  ‰&dz  ‰'«      }|�|j                  ‰&dz  ‰'«      nd}t        |||«      }| j                  |||¬«      }|d   }||z   }|�#|j                  «       }| j                  ||«      }n#t        j                  ‰&‰'f|j                  ¬«      }| j                  ||||¬	«      }|d   }| j                  |«      }|j                  ‰&d‰'| j                  j                  «      }|dd…df   }|dd…d
f   }||j!                  d
d«      z  }|| j                  j                  dz  z  }|�Q|j                  ‰&d‰'«      }|dd…df   j#                  d«      j%                  dd‰'«      }|j'                  |dk(  d«      }t)        || j*                  | j                  j,                  ¬«      }|dd…dd…dd…f   j/                  d«      }|dd…dd…dd…f   j/                  d
«      }|j0                  }|j0                  }t3        |d
«      d   |j5                  d
|«      k(  }t3        |d
«      d   |j5                  d
|«      k(  }|j7                  d«      }t        j8                  ||j:                  j=                  «       |«      }t        j8                  || j                  j>                  kD  ||«      }t        j8                  ||j5                  d
|«      |«      }|||kD  z  } || j5                  d
|«      z  }!t        j8                  | ||j7                  d«      «      }"t        j8                  |!||j7                  d«      «      }#t        j@                  |"|#g«      j                  ‰&dd«      }$t        j@                  ||g«      j                  ‰&dd«      }%|r+|	|d
   z   }	|	|d
   z   }	|	|fz   }	tC        ˆ&ˆ'fd„|	D «       «      }	|r|
|d   z   }
tC        ˆ&ˆ'fd„|
D «       «      }
|$|%|	|
fS )a=  
        Perform keypoint matching between two images.

        Args:
            keypoints (`torch.Tensor` of shape `(batch_size, 2, num_keypoints, 2)`):
                Keypoints detected in the pair of image.
            descriptors (`torch.Tensor` of shape `(batch_size, 2, descriptor_dim, num_keypoints)`):
                Descriptors of the keypoints detected in the image pair.
            scores (`torch.Tensor` of shape `(batch_size, 2, num_keypoints)`):
                Confidence scores of the keypoints detected in the image pair.
            height (`int`): Image height.
            width (`int`): Image width.
            mask (`torch.Tensor` of shape `(batch_size, 2, num_keypoints)`, *optional*):
                Mask indicating which values in the keypoints, matches and matching_scores tensors are keypoint matching
                information.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors. Default to `config.output_attentions`.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. Default to `config.output_hidden_states`.

        Returns:
            matches (`torch.Tensor` of shape `(batch_size, 2, num_keypoints)`):
                For each image pair, for each keypoint in image0, the index of the keypoint in image1 that was matched
                with. And for each keypoint in image1, the index of the keypoint in image0 that was matched with.
            matching_scores (`torch.Tensor` of shape `(batch_size, 2, num_keypoints)`):
                Scores of predicted matches for each image pair
            all_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
                Tuple of `torch.FloatTensor` (one for the output of each stage) of shape `(1, 2, num_keypoints,
                num_channels)`.
            all_attentions (`tuple(torch.FloatTensor)`, *optional*):
                Tuple of `torch.FloatTensor` (one for each layer) of shape `(1, 2, num_heads, num_keypoints,
                num_keypoints)`.
        ri   Nr   r   rB   r½   )r‘   )r#   )r_   r‘   r»   r%   g      à?g    eÍÍÁ)r@   c              3   óf   •K  — | ](  }|j                  ‰d ‰d«      j                  dd«      –— Œ* y­w)r   rB   r}   N)r  r~   ©Ú.0rX   rH   r  s     €€r   ú	<genexpr>zASuperGlueForKeypointMatching._match_image_pair.<locals>.<genexpr>ý  s2   øè ø€ ò &ØRS�—	‘	˜* a¨¸Ó;×EÑEÀbÈ"×Mñ&ùs   ƒ.1c              3   óH   •K  — | ]  }|j                  ‰d d‰‰«      –— Œ y­w)r   rB   N)r  r;  s     €€r   r=  zASuperGlueForKeypointMatching._match_image_pair.<locals>.<genexpr>  s#   øè ø€ Ò"vÐbc 1§9¡9¨Z¸¸BÀÈ}×#]Ñ"vùs   ƒ")"rC   Únew_fullr   r€   Ú	new_zerosr  rl   rˆ   r-   r3  r*   Úget_extended_attention_maskÚonesr#   r4  r5  r~   r9   rF   Úmasked_fillrS   r/  Úsinkhorn_iterationsr(   ÚindicesrY   ÚgatherrD   Úwherer)   ÚexpÚmatching_thresholdr   r   )(ry   r   rú   r>   r    r!   r_   r»   r‘   r“   r  rC   r<   Úencoded_keypointsÚlast_hidden_stateÚinput_shapeÚextended_attention_maskr
  Úprojected_descriptorsÚfinal_descriptorsÚfinal_descriptors0Úfinal_descriptors1Úmask0Úmax0Úmax1Úindices0Úindices1Úmutual0Úmutual1ÚzeroÚmatching_scores0Úmatching_scores1Úvalid0Úvalid1Úmatches0Úmatches1r]   r^   rH   r  s(                                         @@r   Ú_match_image_pairz.SuperGlueForKeypointMatching._match_image_pairz  sÜ  ù€ ñX #7™B¸DÐÙ0™°dˆà�?‰?˜1Ñ Ò"Ø—O‘O C RÐ(ˆEà×"Ñ" 5¨"´E·I±IÐ"Ó>Ø×#Ñ# EÓ*Ø!Øð	ð ð +4¯/©/Ñ'ˆ
�A�} aà×%Ñ% j°1¡n°mÀQÓGˆ	Ø!×)Ñ)¨*°q©.¸-ÈÏÉ×I`ÑI`ÓaˆØ—‘ 
¨Q¡°Ó>ˆØ>BÐ>Nˆt�|‰|˜J¨™N¨MÔ:ÐTXˆô (¨	°6¸5ÓAˆ	à ×1Ñ1°)¸VÐZnÐ1ÓoÐà-¨aÑ0Ðð "Ð$5Ñ5ˆàÐØ%×*Ñ*Ó,ˆKØ&*×&FÑ&FÀtÈ[Ó&YÑ#ä&+§j¡j°*¸mÐ1LÐU^×UeÑUeÔ&fÐ#ð —h‘hØØ(Ø!5Ø/ð	 ó 
ˆð " !‘nˆð !%× 5Ñ 5°kÓ BÐð 2×9Ñ9¸*ÀaÈÐX\×XcÑXc×XoÑXoÓpÐØ.ªq°!¨tÑ4ÐØ.ªq°!¨tÑ4Ðð $Ð&8×&BÑ&BÀ1ÀaÓ&HÑHˆØ˜$Ÿ+™+×1Ñ1°3Ñ6Ñ6ˆàÐØ—<‘< 
¨A¨}Ó=ˆDØš˜A˜‘J×(Ñ(¨Ó,×3Ñ3°B¸¸MÓJˆEØ×'Ñ'¨°©
°DÓ9ˆFô ' v¨t¯~©~È$Ï+É+×JiÑJiÔjˆð ’a˜˜"˜˜c˜r˜c�kÑ"×&Ñ& qÓ)ˆØ’a˜˜"˜˜c˜r˜c�kÑ"×&Ñ& qÓ)ˆØ—<‘<ˆØ—<‘<ˆÜ˜h¨Ó*¨4Ñ0°H·O±OÀAÀxÓ4PÑPˆÜ˜h¨Ó*¨4Ñ0°H·O±OÀAÀxÓ4PÑPˆØ× Ñ  Ó#ˆÜ Ÿ;™; w°·±·±Ó0AÀ4ÓHÐÜ Ÿ;™;Ð'7¸$¿+¹+×:XÑ:XÑ'XÐZjÐlpÓqÐÜ Ÿ;™; wÐ0@×0GÑ0GÈÈ8Ó0TÐVZÓ[ÐØÐ,¨tÑ3Ñ4ˆØ˜6Ÿ=™=¨¨HÓ5Ñ5ˆÜ—;‘;˜v x°×1DÑ1DÀRÓ1HÓIˆÜ—;‘;˜v x°×1DÑ1DÀRÓ1HÓIˆä—)‘)˜X xÐ0Ó1×9Ñ9¸*ÀaÈÓLˆÜŸ)™)Ð%5Ð7GÐ$HÓI×QÑQÐR\Ð^_ÐacÓdˆáØ 1Ð4EÀaÑ4HÑ HÐØ 1°KÀ±NÑ BÐØ 1Ð5JÐ4LÑ LÐÜ %ô &ØWhô&ó !Ðñ Ø+¨k¸!©nÑ<ˆNÜ"Ô"vÐguÔ"vÓvˆNð ØØØð	
ð 	
r.   r  ÚlabelsÚreturn_dictc           
      óð  — d}|�t        d«      ‚|�|n| j                  j                  }|�|n| j                  j                  }|�|n| j                  j                  }|j
                  dk7  s|j                  d«      dk7  rt        d«      ‚|j                  \  }}}	}
}|j                  |dz  |	|
|«      }| j                  |«      }|dd \  }}}}|j                  |ddd«      j                  |«      }|j                  |dd«      j                  |«      }|j                  |dd| j                  j                  «      j                  |«      }|j                  |dd«      }|j                  «       }|dd…dd…dd…d	f   |z  |dd…dd…dd…d	f<   |dd…dd…dd…df   |
z  |dd…dd…dd…df<   | j                  ||||
||||¬
«      \  }}}}|st        d„ |||||||fD «       «      S t        |||||||¬«      S )a  
        Examples:

        ```python
        >>> from transformers import AutoImageProcessor, AutoModel
        >>> import torch
        >>> from PIL import Image
        >>> import requests

        >>> url = "https://github.com/magicleap/SuperGluePretrainedNetwork/blob/master/assets/phototourism_sample_images/london_bridge_78916675_4568141288.jpg?raw=true"
        >>> image1 = Image.open(requests.get(url, stream=True).raw)
        >>> url = "https://github.com/magicleap/SuperGluePretrainedNetwork/blob/master/assets/phototourism_sample_images/london_bridge_19481797_2295892421.jpg?raw=true"
        >>> image2 = Image.open(requests.get(url, stream=True).raw)
        >>> images = [image1, image2]

        >>> processor = AutoImageProcessor.from_pretrained("magic-leap-community/superglue_outdoor")
        >>> model = AutoModel.from_pretrained("magic-leap-community/superglue_outdoor")

        >>> with torch.no_grad():
        >>>     inputs = processor(images, return_tensors="pt")
        >>>     outputs = model(**inputs)
        ```Nz9SuperGlue is not trainable, no labels should be provided.é   r%   r   zOInput must be a 5D tensor of shape (batch_size, 2, num_channels, height, width)é   rB   r   )r_   r»   r‘   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wrp   ri   )r<  Úvs     r   r=  z7SuperGlueForKeypointMatching.forward.<locals>.<genexpr>Q  s   è ø€ ò àØ�=ô ñùs   ‚)r\   r]   r^   r   r_   r`   ra   )r¢   rl   r»   r‘   Úuse_return_dictÚndimr*   rC   r  r2  rE   rˆ   Úcloner`  r   r[   )ry   r  ra  r»   r‘   rb  r\   rH   r<   Úchannelsr    r!   Úkeypoint_detectionsr   r>   rú   r_   Úabsolute_keypointsr]   r^   r`   ra   s                         r   r   z$SuperGlueForKeypointMatching.forward  sG  € ð> ˆØÐÜÐXÓYÐYà1BÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà×Ñ Ò! \×%6Ñ%6°qÓ%9¸QÒ%>ÜÐnÓoÐoà1=×1CÑ1CÑ.ˆ
�A�x ¨Ø#×+Ñ+¨J¸©N¸HÀfÈeÓTˆØ"×4Ñ4°\ÓBÐà/BÀ2ÀAÐ/FÑ,ˆ	�6˜;¨Ø×%Ñ% j°!°R¸Ó;×>Ñ>¸|ÓLˆ	Ø—‘ 
¨A¨rÓ2×5Ñ5°lÓCˆØ!×)Ñ)¨*°a¸¸T¿[¹[×=TÑ=TÓU×XÑXÐYeÓfˆØ�|‰|˜J¨¨2Ó.ˆà&Ÿ_™_Ó.ÐØ);ºAºqÂ!ÀQ¸JÑ)GÈ%Ñ)OÐš1ša¢ A˜:Ñ&Ø);ºAºqÂ!ÀQ¸JÑ)GÈ&Ñ)PÐš1ša¢ A˜:Ñ&à>B×>TÑ>TØØØØØØØ/Ø!5ð ?Uó 	?
Ñ;ˆ� -°ñ Üñ à ¨¸)ÀTÈ=ÐZdÐeôó ð ô &ØØØ+ØØØ'Ø!ô
ð 	
r.   )NNN)NNNN)rb   rc   rd   re   r
   rr   r   r�   r€   r   r–   r   r`  r   ÚSUPERGLUE_INPUTS_DOCSTRINGrf   Ú
LongTensorr   r[   r   r‚   rƒ   s   @r   r-  r-  V  sT  ø„ ñ
ð"˜ð °4õ ð* (,Ø,0Ø/3ñO
à—<‘<ðO
ð —\‘\ðO
ð —‘ð	O
ð
 ðO
ð ðO
ð �u—|‘|Ñ$ðO
ð $ D™>ðO
ð ' t™nðO
ð 
ˆu�|‰|˜UŸ\™\¨5°%Ð7Ñ	8óO
ñb +Ð+EÓFð .2Ø,0Ø/3Ø&*ñS
à×'Ñ'ðS
ð ˜×)Ñ)Ñ*ðS
ð $ D™>ð	S
ð
 ' t™nðS
ð ˜d‘^ðS
ð 
ˆuÐ,Ð,Ñ	-òS
ó GôS
r.   r-  )4re   rÂ   Údataclassesr   Útypingr   r   r   r   r   Útransformersr   r	   Ú5transformers.models.superglue.configuration_supergluer
   Úpytorch_utilsr   r   Úutilsr   r   r   Úautor   Ú
get_loggerrb   ÚloggerÚ_CONFIG_FOR_DOC_Ú_CHECKPOINT_FOR_DOC_r�   r   r€   r-   r=   rS   rY   r[   r+  rk   r…   r˜   rÝ   rç   rå   rõ   rþ   r  r  ÚSUPERGLUE_START_DOCSTRINGrn  r-  Ú__all__ri   r.   r   ú<module>r}     sR  ðñ ã Ý !ß )Ñ )ã Ý ç >Ý Qç Qß PÑ PÝ 0ð 
ˆ×	Ñ	˜HÓ	%€à$Ð Ø>Ð ðl  e§l¡lÑ 3ð lÀEÈ%Ï,É,ÑDWð lÐ\aÐbg×bnÑbnÑ\oó lð B 5§<¡<ð B¸ð BÀSð BÈUÏ\É\ó Bð*UØ—\‘\ðUà"Ÿ\™\ðUð #Ÿ\™\ðUð ð	Uð
 ‡\�\óUð:*( %§,¡,ð *(¸5¿<¹<ð *(ÐUXð *(Ð]b×]iÑ]ió *(ðZ2˜ð 2 §¡ó 2ð ô":˜[ó ":ó ð":ôJ B§I¡Iô ô /˜rŸy™yô /ô@C˜RŸY™Yô CôL˜"Ÿ)™)ô ð Ð#ð$Ð  ô0˜Ÿ™ô 0ôf(: b§i¡iô (:ôV4>˜bŸi™iô 4>ôn,˜rŸy™yô ,ô7˜ô 7ð2	Ð ðÐ ñ ØRØóôE
Ð#;ó E
ó	ðE
ðP &Ð'EÐ
F�r.   