ó
    Eñi[V  ã                   ó  • S SK r S SKJr  S SKJr  S SKrS SKJrJr  S SKJ	r
  S SKJrJrJrJr   " S S5      r\R"                  R$                  S	\S
\S\S\4S j5       r " S S5      r " S S5      r " S S5      r " S S\5      rS\R0                  S\SS4S jrS\R0                  S\\\4   S\\   4S jr\R"                  R>                  S\S\4S j5       r S\S\S\S\4S  jr! S(S!\"S"\S#\S$\S%\S&\\#\"\4      S\4S' jjr$g))é    N)ÚOrderedDict)ÚOptional)ÚnnÚTensor)Ú
functional)Úcomplete_box_iou_lossÚdistance_box_iou_lossÚFrozenBatchNorm2dÚgeneralized_box_iou_lossc                   ó\   • \ rS rSrSrS\S\SS4S jrS\\	   S\
\\	   \\	   4   4S	 jrS
rg)ÚBalancedPositiveNegativeSampleré   zX
This class samples batches, ensuring that they contain a fixed proportion of positives
Úbatch_size_per_imageÚpositive_fractionÚreturnNc                 ó   • Xl         X l        g)zœ
Args:
    batch_size_per_image (int): number of elements to be selected per image
    positive_fraction (float): percentage of positive elements per batch
N©r   r   )Úselfr   r   s      Ú`/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/models/detection/_utils.pyÚ__init__Ú(BalancedPositiveNegativeSampler.__init__   s   € ð %9Ô!Ø!2Õó    Úmatched_idxsc                 ó  • / n/ nU GHy  n[         R                  " US:¬  5      S   n[         R                  " US:H  5      S   n[        U R                  U R                  -  5      n[        UR                  5       U5      nU R                  U-
  n[        UR                  5       U5      n[         R                  " UR                  5       UR                  S9SU n	[         R                  " UR                  5       UR                  S9SU n
XY   nXj   n[         R                  " U[         R                  S9n[         R                  " U[         R                  S9nSXÛ'   SXì'   UR                  U5        UR                  U5        GM|     X#4$ )a½  
Args:
    matched_idxs: list of tensors containing -1, 0 or positive values.
        Each tensor corresponds to a specific image.
        -1 values are ignored, 0 are considered as negatives and > 0 as
        positives.

Returns:
    pos_idx (list[tensor])
    neg_idx (list[tensor])

Returns two lists of binary masks for each image.
The first list contains the positive elements that were selected,
and the second list the negative example.
é   r   ©ÚdeviceN©Údtype)ÚtorchÚwhereÚintr   r   ÚminÚnumelÚrandpermr   Ú
zeros_likeÚuint8Úappend)r   r   Úpos_idxÚneg_idxÚmatched_idxs_per_imageÚpositiveÚnegativeÚnum_posÚnum_negÚperm1Úperm2Úpos_idx_per_imageÚneg_idx_per_imageÚpos_idx_per_image_maskÚneg_idx_per_image_masks                  r   Ú__call__Ú(BalancedPositiveNegativeSampler.__call__   sa  € ð  ˆØˆÜ&2Ð"Ü—{’{Ð#9¸QÑ#>Ó?ÀÑBˆHÜ—{’{Ð#9¸QÑ#>Ó?ÀÑBˆHä˜$×3Ñ3°d×6LÑ6LÑLÓMˆGä˜(Ÿ.™.Ó*¨GÓ4ˆGØ×/Ñ/°'Ñ9ˆGä˜(Ÿ.™.Ó*¨GÓ4ˆGô —N’N 8§>¡>Ó#3¸H¿O¹OÑLÈXÈgÐVˆEÜ—N’N 8§>¡>Ó#3¸H¿O¹OÑLÈXÈgÐVˆEà (¡ÐØ (¡Ðô &+×%5Ò%5Ð6LÔTY×T_ÑT_Ñ%`Ð"Ü%*×%5Ò%5Ð6LÔTY×T_ÑT_Ñ%`Ð"à89Ð"Ñ5Ø89Ð"Ñ5à�N‰NÐ1Ô2Ø�N‰NÐ1×2ñ5 '3ð8 ÐÐr   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   Úfloatr   Úlistr   Útupler6   Ú__static_attributes__© r   r   r   r      sJ   † ñð3¨Sð 3ÀUð 3Ètô 3ð.  T¨&¡\ð . °e¸DÀ¹LÈ$ÈvÉ,Ð<VÑ6W÷ . r   r   Úreference_boxesÚ	proposalsÚweightsr   c                 óÜ  • US   nUS   nUS   nUS   nUSS2S4   R                  S5      nUSS2S4   R                  S5      nUSS2S4   R                  S5      n	USS2S4   R                  S5      n
U SS2S4   R                  S5      nU SS2S4   R                  S5      nU SS2S4   R                  S5      nU SS2S4   R                  S5      nX—-
  nX¨-
  nUSU-  -   nUSU-  -   nXÛ-
  nXì-
  nUSU-  -   nUSU-  -   nUUU-
  -  U-  nUUU-
  -  U-  nU[        R                  " UU-  5      -  nU[        R                  " UU-  5      -  n[        R                  " UUUU4SS9nU$ )zÛ
Encode a set of proposals with respect to some
reference boxes

Args:
    reference_boxes (Tensor): reference boxes
    proposals (Tensor): boxes to be encoded
    weights (Tensor[4]): the weights for ``(x, y, w, h)``
r   r   é   é   Nç      à?©Údim)Ú	unsqueezer    ÚlogÚcat)rB   rC   rD   ÚwxÚwyÚwwÚwhÚproposals_x1Úproposals_y1Úproposals_x2Úproposals_y2Úreference_boxes_x1Úreference_boxes_y1Úreference_boxes_x2Úreference_boxes_y2Ú	ex_widthsÚ
ex_heightsÚex_ctr_xÚex_ctr_yÚ	gt_widthsÚ
gt_heightsÚgt_ctr_xÚgt_ctr_yÚ
targets_dxÚ
targets_dyÚ
targets_dwÚ
targets_dhÚtargetss                               r   Úencode_boxesrg   J   sÂ  € ð 
�‰€BØ	�‰€BØ	�‰€BØ	�‰€BàšQ ˜T‘?×,Ñ,¨QÓ/€LØšQ ˜T‘?×,Ñ,¨QÓ/€LØšQ ˜T‘?×,Ñ,¨QÓ/€LØšQ ˜T‘?×,Ñ,¨QÓ/€Là(ª¨A¨Ñ.×8Ñ8¸Ó;ÐØ(ª¨A¨Ñ.×8Ñ8¸Ó;ÐØ(ª¨A¨Ñ.×8Ñ8¸Ó;ÐØ(ª¨A¨Ñ.×8Ñ8¸Ó;Ðð Ñ+€IØÑ,€JØ˜c I™oÑ-€HØ˜c JÑ.Ñ.€Hà"Ñ7€IØ#Ñ8€JØ! C¨)¡OÑ3€HØ! C¨*Ñ$4Ñ4€Hà�x (Ñ*Ñ+¨iÑ7€JØ�x (Ñ*Ñ+¨jÑ8€JØ”e—i’i 	¨IÑ 5Ó6Ñ6€JØ”e—i’i 
¨ZÑ 7Ó8Ñ8€Jä�iŠi˜ Z°¸ZÐHÈaÑP€GØ€Nr   c                   óÒ   • \ rS rSrSr\R                  " S5      4S\\\\\4   S\SS4S jjr	S	\
\   S
\
\   S\
\   4S jrS	\S
\S\4S jrS\S\
\   S\4S jrS\S\S\4S jrSrg)ÚBoxCoderéz   zr
This class encodes and decodes a set of bounding boxes into
the representation used for training the regressors.
g     @O@rD   Úbbox_xform_clipr   Nc                 ó   • Xl         X l        g)zA
Args:
    weights (4-element tuple)
    bbox_xform_clip (float)
N)rD   rk   )r   rD   rk   s      r   r   ÚBoxCoder.__init__€   s   € ð ŒØ.Õr   rB   rC   c                 óÜ   • U Vs/ s H  n[        U5      PM     nn[        R                  " USS9n[        R                  " USS9nU R                  X5      nUR	                  US5      $ s  snf )Nr   rI   )Úlenr    rM   Úencode_singleÚsplit)r   rB   rC   ÚbÚboxes_per_imagerf   s         r   ÚencodeÚBoxCoder.encode‹   s`   € Ù+:Ó;ª? aœ3˜qž6©?ˆÐ;ÜŸ)š) O¸Ñ;ˆÜ—I’I˜i¨QÑ/ˆ	Ø×$Ñ$ _Ó@ˆØ�}‰}˜_¨aÓ0Ð0ùò	 <s   …A)c                 óŒ   • UR                   nUR                  n[        R                  " U R                  X4S9n[        XU5      nU$ )z¡
Encode a set of proposals with respect to some
reference boxes

Args:
    reference_boxes (Tensor): reference boxes
    proposals (Tensor): boxes to be encoded
©r   r   )r   r   r    Ú	as_tensorrD   rg   )r   rB   rC   r   r   rD   rf   s          r   rp   ÚBoxCoder.encode_single’   s?   € ð  ×%Ñ%ˆØ ×'Ñ'ˆÜ—/’/ $§,¡,°eÑKˆÜ˜¸7ÓCˆàˆr   Ú	rel_codesÚboxesc                 óÐ  • [         R                  " [        U[        [        45      S5        [         R                  " [        U[         R
                  5      S5        U Vs/ s H  o3R                  S5      PM     nn[         R                  " USS9nSnU H  nXg-  nM	     US:”  a  UR                  US5      nU R                  X5      nUS:”  a  UR                  USS5      nU$ s  snf )Nz2This function expects boxes of type list or tuple.z5This function expects rel_codes of type torch.Tensor.r   rI   éÿÿÿÿé   )
r    Ú_assertÚ
isinstancer>   r?   r   ÚsizerM   ÚreshapeÚdecode_single)	r   rz   r{   rr   rs   Úconcat_boxesÚbox_sumÚvalÚ
pred_boxess	            r   ÚdecodeÚBoxCoder.decode¢   sÏ   € Ü�ŠÜ�uœt¤U˜mÓ,Ø@ô	
ô 	�ŠÜ�y¤%§,¡,Ó/ØCô	
ñ /4Ó4ªe¨Ÿ6™6 !ž9©eˆÐ4Ü—y’y ¨AÑ.ˆØˆÛ"ˆCØ‰NŠGñ #à�Q‹;Ø!×)Ñ)¨'°2Ó6ˆIØ×'Ñ'¨	Ó@ˆ
Ø�Q‹;Ø#×+Ñ+¨G°R¸Ó;ˆJØÐùò 5s   ÁC#c                 óÒ  • UR                  UR                  5      nUSS2S4   USS2S4   -
  nUSS2S4   USS2S4   -
  nUSS2S4   SU-  -   nUSS2S4   SU-  -   nU R                  u  pxpšUSS2SSS24   U-  nUSS2SSS24   U-  nUSS2SSS24   U	-  nUSS2SSS24   U
-  n[        R                  " XÐR
                  S9n[        R                  " XàR
                  S9nX³SS2S4   -  USS2S4   -   nXÄSS2S4   -  USS2S4   -   n[        R                  " U5      USS2S4   -  n[        R                  " U5      USS2S4   -  n[        R                  " SUR                  UR                  S	9U-  n[        R                  " SUR                  UR                  S	9U-  nUU-
  nUU-
  nUU-   nUU-   n[        R                  " UUUU4SS
9R                  S5      nU$ )z©
From a set of original boxes and encoded relative box offsets,
get the decoded boxes.

Args:
    rel_codes (Tensor): encoded boxes
    boxes (Tensor): reference boxes.
NrF   r   rG   r   rH   r~   )Úmaxrw   rI   )Útor   rD   r    Úclamprk   ÚexpÚtensorr   ÚstackÚflatten)r   rz   r{   ÚwidthsÚheightsÚctr_xÚctr_yrN   rO   rP   rQ   ÚdxÚdyÚdwÚdhÚ
pred_ctr_xÚ
pred_ctr_yÚpred_wÚpred_hÚc_to_c_hÚc_to_c_wÚpred_boxes1Úpred_boxes2Úpred_boxes3Úpred_boxes4r‡   s                             r   rƒ   ÚBoxCoder.decode_single·   s  € ð —‘˜Ÿ™Ó)ˆà’q˜!�t‘˜u¢Q¨ T™{Ñ*ˆØš˜1˜‘+ ¢a¨ d¡Ñ+ˆØ’a˜�d‘˜c F™lÑ*ˆØ’a˜�d‘˜c G™mÑ+ˆàŸ™‰ˆ�Ø’q˜!˜$˜Q˜$�wÑ "Ñ$ˆØ’q˜!˜$˜Q˜$�wÑ "Ñ$ˆØ’q˜!˜$˜Q˜$�wÑ "Ñ$ˆØ’q˜!˜$˜Q˜$�wÑ "Ñ$ˆô �[Š[˜×!5Ñ!5Ñ6ˆÜ�[Š[˜×!5Ñ!5Ñ6ˆà¢ D ™/Ñ)¨E²!°T°'©NÑ:ˆ
Ø¢! T 'Ñ*Ñ*¨U²1°d°7©^Ñ;ˆ
Ü—’˜2“ ª¨4¨¡Ñ0ˆÜ—’˜2“ ª¨D¨Ñ!1Ñ1ˆô —<’< ¨:×+;Ñ+;ÀFÇMÁMÑRÐU[Ñ[ˆÜ—<’< ¨:×+;Ñ+;ÀFÇMÁMÑRÐU[Ñ[ˆà  8Ñ+ˆØ  8Ñ+ˆØ  8Ñ+ˆØ  8Ñ+ˆÜ—[’[ +¨{¸KÈÐ!UÐ[\Ñ]×eÑeÐfgÓhˆ
ØÐr   )rk   rD   )r8   r9   r:   r;   r<   ÚmathrL   r?   r=   r   r>   r   rt   rp   rˆ   rƒ   r@   rA   r   r   ri   ri   z   sÀ   † ñð TX×S[ÒS[Ð\gÓShñ	/Ø˜U E¨5°%Ð7Ñ8ð	/ØKPð	/à	õ	/ð1 d¨6¡lð 1¸tÀF¹|ð 1ÐPTÐU[ÑP\ô 1ð¨Vð Àð È6ô ð  ð ¨t°F©|ð Àô ð*) vð )°fð )À÷ )r   ri   c                   óZ   • \ rS rSrSrSS\SS4S jjrS\S\S\4S	 jrS
\S\S\4S jr	Sr
g)ÚBoxLinearCoderéã   z¨
The linear box-to-box transform defined in FCOS. The transformation is parameterized
by the distance from the center of (square) src box to 4 edges of the target box.
Únormalize_by_sizer   Nc                 ó   • Xl         g)zY
Args:
    normalize_by_size (bool): normalize deltas by the size of src (anchor) boxes.
N©r©   )r   r©   s     r   r   ÚBoxLinearCoder.__init__é   s
   € ð
 "3Õr   rB   rC   c                 ó,  • SUS   US   -   -  nSUS   US   -   -  nX2S   -
  nXBS   -
  nUS   U-
  nUS   U-
  n[         R                  " XVXx4SS9n	U R                  (       a1  US   US   -
  n
US   US   -
  n[         R                  " X«X«4SS9nXœ-  n	U	$ )a  
Encode a set of proposals with respect to some reference boxes

Args:
    reference_boxes (Tensor): reference boxes
    proposals (Tensor): boxes to be encoded

Returns:
    Tensor: the encoded relative box offsets that can be used to
    decode the boxes.

rH   ©.r   ©.rF   ©.r   ©.rG   r}   rI   )r    r�   r©   )r   rB   rC   Úreference_boxes_ctr_xÚreference_boxes_ctr_yÚtarget_lÚtarget_tÚtarget_rÚtarget_brf   Úreference_boxes_wÚreference_boxes_hÚreference_boxes_sizes                r   rt   ÚBoxLinearCoder.encodeð   sè   € ð !$ °vÑ'>ÀÐQWÑAXÑ'XÑ YÐØ # °vÑ'>ÀÐQWÑAXÑ'XÑ YÐð )°VÑ+<Ñ<ˆØ(°VÑ+<Ñ<ˆØ˜VÑ$Ð'<Ñ<ˆØ˜VÑ$Ð'<Ñ<ˆä—+’+˜x°8ÐFÈBÑOˆà×!×!Ø /°Ñ 7¸/È&Ñ:QÑ QÐØ /°Ñ 7¸/È&Ñ:QÑ QÐÜ#(§;¢;Ø"Ð7HÐ\Ðbdñ$Ð ð Ñ4ˆGØˆr   rz   r{   c                 óZ  • UR                  UR                  S9nSUS   US   -   -  nSUS   US   -   -  nU R                  (       a1  US   US   -
  nUS   US   -
  n[        R                  " XVXV4SS9nX-  nX1S   -
  nXAS   -
  n	X1S   -   n
XAS   -   n[        R                  " X‰X«4SS9nU$ )	aˆ  
From a set of original boxes and encoded relative box offsets,
get the decoded boxes.

Args:
    rel_codes (Tensor): encoded boxes
    boxes (Tensor): reference boxes.

Returns:
    Tensor: the predicted boxes with the encoded relative box offsets.

.. note::
    This method assumes that ``rel_codes`` and ``boxes`` have same size for 0th dimension. i.e. ``len(rel_codes) == len(boxes)``.

r   rH   r®   r¯   r°   r±   r}   rI   )rŒ   r   r©   r    r�   )r   rz   r{   r”   r•   Úboxes_wÚboxes_hÚlist_box_sizer    r¡   r¢   r£   r‡   s                r   rˆ   ÚBoxLinearCoder.decode  sá   € ð" —‘˜yŸ™�Ð/ˆà�u˜V‘} u¨V¡}Ñ4Ñ5ˆØ�u˜V‘} u¨V¡}Ñ4Ñ5ˆà×!×!Ø˜F‘m e¨F¡mÑ3ˆGØ˜F‘m e¨F¡mÑ3ˆGä!ŸKšK¨¸7Ð(LÐRTÑUˆMØ!Ñ1ˆIà¨Ñ/Ñ/ˆØ¨Ñ/Ñ/ˆØ¨Ñ/Ñ/ˆØ¨Ñ/Ñ/ˆä—[’[ +¸KÐ!UÐ[]Ñ^ˆ
ØÐr   r«   )T)r8   r9   r:   r;   r<   Úboolr   r   rt   rˆ   r@   rA   r   r   r§   r§   ã   sO   † ññ
3¨$ð 3¸$õ 3ð! fð !¸ð !ÀFô !ðF# ð #¨vð #¸&÷ #r   r§   c            	       ót   • \ rS rSrSrSrSr\\S.rSS\	S\	S\
S	S
4S jjrS\S	\4S jrS\S\S\S	S
4S jrSrg
)ÚMatcheri9  aa  
This class assigns to each predicted "element" (e.g., a box) a ground-truth
element. Each predicted element will have exactly zero or one matches; each
ground-truth element may be assigned to zero or more predicted elements.

Matching is based on the MxN match_quality_matrix, that characterizes how well
each (ground-truth, predicted)-pair match. For example, if the elements are
boxes, the matrix may contain box IoU overlap values.

The matcher returns a tensor of size N containing the index of the ground-truth
element m that matches to prediction n. If there is no match, a negative value
is returned.
r}   éþÿÿÿ)ÚBELOW_LOW_THRESHOLDÚBETWEEN_THRESHOLDSÚhigh_thresholdÚlow_thresholdÚallow_low_quality_matchesr   Nc                 óv   • SU l         SU l        [        R                  " X!:*  S5        Xl        X l        X0l        g)aO  
Args:
    high_threshold (float): quality values greater than or equal to
        this value are candidate matches.
    low_threshold (float): a lower quality threshold used to stratify
        matches into three levels:
        1) matches >= high_threshold
        2) BETWEEN_THRESHOLDS matches in [low_threshold, high_threshold)
        3) BELOW_LOW_THRESHOLD matches in [0, low_threshold)
    allow_low_quality_matches (bool): if True, produce additional matches
        for predictions that have only low-quality match candidates. See
        set_low_quality_matches_ for more details.
r}   rÄ   z)low_threshold should be <= high_thresholdN)rÅ   rÆ   r    r   rÇ   rÈ   rÉ   )r   rÇ   rÈ   rÉ   s       r   r   ÚMatcher.__init__P  s8   € ð $&ˆÔ Ø"$ˆÔÜ�Š�mÑ5Ð7bÔcØ,ÔØ*ÔØ)BÕ&r   Úmatch_quality_matrixc                 óö  • UR                  5       S:X  a)  UR                  S   S:X  a  [        S5      e[        S5      eUR                  SS9u  p#U R                  (       a  UR                  5       nOSnX R                  :  nX R                  :¬  X R                  :  -  nU R                  X5'   U R                  X6'   U R                  (       a.  Uc  [        R                  " SS5        U$ U R                  X4U5        U$ )aI  
Args:
    match_quality_matrix (Tensor[float]): an MxN tensor, containing the
    pairwise quality between M ground-truth elements and N predicted elements.

Returns:
    matches (Tensor[int64]): an N tensor where N[i] is a matched gt in
    [0, M - 1] or a negative value indicating that prediction i could not
    be matched.
r   zENo ground-truth boxes available for one of the images during trainingzANo proposal boxes available for one of the images during trainingrI   NFzall_matches should not be None)r$   ÚshapeÚ
ValueErrorr‹   rÉ   ÚclonerÈ   rÇ   rÅ   rÆ   r    r   Úset_low_quality_matches_)r   rÌ   Úmatched_valsÚmatchesÚall_matchesÚbelow_low_thresholdÚbetween_thresholdss          r   r6   ÚMatcher.__call__e  sø   € ð  ×%Ñ%Ó'¨1Ó,à#×)Ñ)¨!Ñ,°Ó1Ü Ð!hÓiÐiä Ð!dÓeÐeð !5× 8Ñ 8¸QÐ 8Ð ?ÑˆØ×)×)Ø!Ÿ-™-›/‰KàˆKð +×-?Ñ-?Ñ?ÐØ*×.@Ñ.@Ñ@À\×TgÑTgÑEgÑhÐØ'+×'?Ñ'?ˆÑ$Ø&*×&=Ñ&=ˆÑ#à×)×)ØÑ"Ü—’˜eÐ%EÔFð ˆð ×-Ñ-¨gÐDXÔYàˆr   rÓ   rÔ   c                 óz   • UR                  SS9u  pE[        R                  " X4SS2S4   :H  5      nUS   nX'   X'   g)aH  
Produce additional matches for predictions that have only low-quality matches.
Specifically, for each ground-truth find the set of predictions that have
maximum overlap with it (including ties); for each prediction in that set, if
it is unmatched, then match it to the ground-truth with which it has the highest
quality value.
r   rI   N)r‹   r    r!   )r   rÓ   rÔ   rÌ   Úhighest_quality_foreach_gtÚ_Ú gt_pred_pairs_of_highest_qualityÚpred_inds_to_updates           r   rÑ   Ú Matcher.set_low_quality_matches_�  sR   € ð )=×(@Ñ(@ÀQÐ(@Ð(GÑ%Ð"ä+0¯;ª;Ð7KÒjkÐmqÐjqÑOrÑ7rÓ+sÐ(ð ?¸qÑAÐØ'2Ñ'GˆÒ$r   )rÅ   rÆ   rÉ   rÇ   rÈ   )F)r8   r9   r:   r;   r<   rÅ   rÆ   r"   Ú__annotations__r=   rÁ   r   r   r6   rÑ   r@   rA   r   r   rÃ   rÃ   9  sˆ   † ñð ÐØÐð  #Ø!ñ€Oñ
C uð C¸Uð CÐ_cð CÐptõ Cð*&¨Vð &¸ô &ðPH°ð HÀVð HÐcið HÐnr÷ Hr   rÃ   c                   óL   ^ • \ rS rSrS\SS4U 4S jjrS\S\4U 4S jjrSrU =r	$ )	Ú
SSDMatcheri£  Ú	thresholdr   Nc                 ó"   >• [         TU ]  XSS9  g )NF)rÉ   )Úsuperr   )r   rá   Ú	__class__s     €r   r   ÚSSDMatcher.__init__¤  s   ø€ Ü‰Ñ˜ÈÐÒOr   rÌ   c                 óÆ   >• [         TU ]  U5      nUR                  SS9u  p4[        R                  " UR                  S5      [        R                  UR                  S9X$'   U$ )Nr   rI   r   rw   )rã   r6   r‹   r    Úaranger�   Úint64r   )r   rÌ   rÓ   rÚ   Úhighest_quality_pred_foreach_gträ   s        €r   r6   ÚSSDMatcher.__call__§  sa   ø€ Ü‘'Ñ"Ð#7Ó8ˆð .B×-EÑ-EÈ!Ð-EÐ-LÑ*ˆÜ38·<²<Ø+×0Ñ0°Ó3¼5¿;¹;ÐOn×OuÑOuñ4
ˆÑ0ð ˆr   rA   )
r8   r9   r:   r;   r=   r   r   r6   r@   Ú__classcell__)rä   s   @r   rà   rà   £  s1   ø† ðP %ð P¨D÷ Pð	¨Vð 	¸÷ 	õ 	r   rà   ÚmodelÚepsc                 ól   • U R                  5        H   n[        U[        5      (       d  M  Xl        M"     g)aÈ  
This method overwrites the default eps values of all the
FrozenBatchNorm2d layers of the model with the provided value.
This is necessary to address the BC-breaking change introduced
by the bug-fix at pytorch/vision#2933. The overwrite is applied
only when the pretrained weights are loaded to maintain compatibility
with previous versions.

Args:
    model (nn.Module): The model on which we perform the overwrite.
    eps (float): The new value of eps.
N)Úmodulesr€   r
   rí   )rì   rí   Úmodules      r   Úoverwrite_epsrñ   ³  s'   € ð —-‘-–/ˆÜ�fÔ/×0Ó0ØŽJò "r   r�   c                 ó  • U R                   nU R                  5         [        R                  " 5          [	        U R                  5       5      R                  n[        R                  " SSUS   US   4US9nU " U5      n[        U[        R                  5      (       a  [        SU4/5      nUR                  5        Vs/ s H  ofR                  S5      PM     nnSSS5        U(       a  U R                  5         W$ s  snf ! , (       d  f       N,= f)ak  
This method retrieves the number of output channels of a specific model.

Args:
    model (nn.Module): The model for which we estimate the out_channels.
        It should return a single Tensor or an OrderedDict[Tensor].
    size (Tuple[int, int]): The size (wxh) of the input.

Returns:
    out_channels (List[int]): A list of the output channels of the model.
r   rG   r   r   Ú0N)ÚtrainingÚevalr    Úno_gradÚnextÚ
parametersr   Úzerosr€   r   r   Úvaluesr�   Útrain)rì   r�   Úin_trainingr   Útmp_imgÚfeaturesÚxÚout_channelss           r   Úretrieve_out_channelsr  Å  sÍ   € ð —.‘.€KØ	‡J�J„Lä	�Š�ä�e×&Ñ&Ó(Ó)×0Ñ0ˆÜ—+’+˜q ! T¨!¡W¨d°1©gÐ6¸vÑFˆÙ˜“>ˆÜ�h¤§¡×-Ñ-Ü" S¨( OÐ#4Ó5ˆHØ+3¯?©?Ô+<Ó=Ò+< aŸ™˜qž	Ñ+<ˆÐ=÷ 
ö Ø�‰ŒàÐùò >÷ 
�ús   ²B
C>Â<C9ÃC>Ã9C>Ã>
DÚvc                 ó   • U $ ©NrA   )r  s    r   Ú_fake_cast_onnxr  ã  s   € à€Hr   ÚinputÚ	orig_kvalÚaxisc           	      óx  • [         R                  R                  5       (       d  [        XR	                  U5      5      $ [         R
                  " U 5      U   R                  S5      n[         R                  " [         R                  " [         R                  " U/UR                  S9U4S5      5      n[        U5      $ )aA  
ONNX spec requires the k-value to be less than or equal to the number of inputs along
provided dim. Certain models use the number of elements along a particular axis instead of K
if K exceeds the number of elements along that axis. Previously, python's min() function was
used to determine whether to use the provided k-value or the specified dim axis value.

However, in cases where the model is being exported in tracing mode, python min() is
static causing the model to be traced incorrectly and eventually fail at the topk node.
In order to avoid this situation, in tracing mode, torch.min() is used instead.

Args:
    input (Tensor): The original input tensor.
    orig_kval (int): The provided k-value.
    axis(int): Axis along which we retrieve the input size.

Returns:
    min_kval (int): Appropriately selected k-value.
r   r   )r    ÚjitÚ
is_tracingr#   r�   Ú_shape_as_tensorrK   rM   r�   r   r  )r  r  r  Úaxis_dim_valÚmin_kvals        r   Ú	_topk_minr  è  s‰   € ô& �9‰9×Ñ×!Ñ!Ü�9Ÿj™j¨Ó.Ó/Ð/Ü×)Ò)¨%Ó0°Ñ6×@Ñ@ÀÓC€LÜ�yŠyœŸš¤E§L¢L°)°ÀL×DVÑDVÑ$WÐYeÐ#fÐhiÓjÓk€HÜ˜8Ó$Ð$r   ÚtypeÚ	box_coderÚanchors_per_imageÚmatched_gt_boxes_per_imageÚbbox_regression_per_imageÚcnfc                 óª  • [         R                  " U S;   SU  35        U S:X  a&  UR                  X25      n[        R                  " XFSS9$ U S:X  a7  UR                  X25      nUb  SU;   a  US   OSn[        R
                  " XFSUS	9$ UR                  XB5      nUb  S
U;   a  US
   OSn	U S:X  a  [        XƒSU	S9$ U S:X  a  [        XƒSU	S9$ [        XƒSU	S9$ )N)Úl1Ú	smooth_l1ÚciouÚdiouÚgiouzUnsupported loss: r  Úsum)Ú	reductionr  Úbetag      ð?)r  r  rí   gH¯¼šò×z>r  )r  rí   r  )
r    r   rp   ÚFÚl1_lossÚsmooth_l1_lossrƒ   r   r	   r   )
r  r  r  r  r  r  Útarget_regressionr  Úbbox_per_imagerí   s
             r   Ú	_box_lossr$    sü   € ô 
‡M‚M�$ÐEÑEÐI[Ð\`Ð[aÐGbÔcàˆtƒ|Ø%×3Ñ3Ð4NÓbÐÜ�yŠyÐ2ÐQVÑWÐWØ	�Ó	Ø%×3Ñ3Ð4NÓbÐØ!™o°&¸C³-ˆs�6Š{ÀSˆÜ×ÒÐ 9ÐX]ÐdhÑiÐià"×0Ñ0Ð1JÓ^ˆØ™O°¸³ˆc�%ŠjÀ$ˆØ�6‹>Ü(¨Ð_dÐjmÑnÐnØ�6‹>Ü(¨Ð_dÐjmÑnÐnä'¨Ð^cÐilÑmÐmr   r  )%r¥   Úcollectionsr   Útypingr   r    r   r   Útorch.nnr   r  Útorchvision.opsr   r	   r
   r   r   r
  Ú_script_if_tracingrg   ri   r§   rÃ   rà   ÚModuler=   rñ   r?   r"   r>   r  Úunusedr  r  ÚstrÚdictr$  rA   r   r   Ú<module>r.     s‘  ðÛ Ý #Ý ã ß Ý $ß uÓ u÷< ñ < ð~ ‡�×Ñð, &ð ,°Vð ,Àfð ,ÐQWó ,ó ð,÷^fñ f÷RSñ S÷lgHñ gHôT�ô ð ˜Ÿ™ð ¨ð °4ô ð$ §¡ð °%¸¸S¸±/ð ÀdÈ3Áiô ð< ‡�×Ñð�vð  #ó ó ðð%�Vð %¨ð %°3ð %¸3ô %ð@ '+ñnØ
ðnàðnð ðnð !'ð	nð
  &ðnð 
�$�s˜E�zÑ"Ñ	#ðnð önr   