Ë
    ëÓ^j¼N  ã                   ó  — d dl mZmZ d dlZd dlmZ d dlmc mZ d dl	m
Z
  G d„ dej                  j                  «      Z G d„ dej                  «      Z G d„ d	ej                  «      Z G d
„ dej                  «      Zdej$                  dej$                  dedej$                  fd„Z	 	 ddej$                  deej$                  gej$                  f   dedededej$                  fd„Zdej$                  dej$                  fd„Zy)é    )ÚAnyÚCallableN)Ú_bilinear_grid_samplec                   óÆ  — e Zd ZdZedej                  j                  j                  dej                  dej                  dej                  dz  de
edf   d	e
edf   d
e
edf   dedej                  fd„«       Zedej                  j                  j                  dej                  de
ej                  dz  ej                  dz  ej                  dz  ddddf   fd„«       Zy)Ú_DepthwiseConvWithoutCuDNNa»  Depthwise conv2d with cuDNN disabled in both forward and backward.

    ``torch.backends.cudnn.flags(enabled=False)`` as a context manager only covers operations executed within its scope.
    ``nn.Conv2d`` records the forward op in the autograd graph; the corresponding backward kernels run later,
    **outside** that scope, with cuDNN re-enabled.  On some CUDA stacks (T4 / P100 on Kaggle / Colab) cuDNN fails engine
    selection for depthwise conv backward, raising::

        RuntimeError: GET was unable to find an engine to execute this computation

    This ``Function`` disables cuDNN in ``backward`` as well, fixing the crash.

    See: https://github.com/roboflow/rf-detr/issues/731
    ÚctxÚxÚweightÚbiasNÚstride.ÚpaddingÚdilationÚgroupsÚreturnc           
      ó(  — | j                  ||«       |du| _        || _        || _        || _        || _        t        j                  j                  j                  d¬«      5  t        j                  |||||||¬«      cddd«       S # 1 sw Y   yxY w)a  Run depthwise conv2d forward with cuDNN disabled.

        Args:
            ctx: Autograd context.
            x: Input feature map ``(N, C, H, W)``.
            weight: Convolution weight tensor.
            bias: Optional convolution bias tensor.
            stride: Convolution stride.
            padding: Convolution padding.
            dilation: Convolution dilation.
            groups: Number of groups (equals ``C`` for depthwise).

        Returns:
            Output feature map ``(N, C, H, W)``.
        NF©Úenabled©r   r   r   r   )Úsave_for_backwardÚhas_biasr   r   r   r   ÚtorchÚbackendsÚcudnnÚflagsÚFÚconv2d)r   r	   r
   r   r   r   r   r   s           úk/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/rfdetr/models/heads/segmentation.pyÚforwardz"_DepthwiseConvWithoutCuDNN.forward   sŒ   € ð4 	×Ñ˜a Ô(Ø 4Ð'ˆŒØˆŒ
ØˆŒØˆŒØˆŒ
ô
 �^‰^×!Ñ!×'Ñ'°Ð'Ó6ñ 	oÜ—8‘8˜A˜v t°FÀGÐV^ÐgmÔn÷	o÷ 	oò 	oús   Á"BÂBÚgrad_outputc           
      ó”  — | j                   \  }}| j                  d   }| j                  d   }| j                  xr | j                  d   }d}d}d}	|s|�r1|j                  |j                  ¬«      }
t
        j                  j                  j                  d¬«      5  |rbt
        j                  j                  j                  |j                  ||
| j                  | j                  | j                  | j                   ¬«      }|r|t
        j                  j                  j#                  |j                  |j                  ¬«      |j                  |
| j                  | j                  | j                  | j                   ¬«      }ddd«       |r,|j                  |j                  ¬«      j%                  d	¬
«      }	|||	ddddfS # 1 sw Y   Œ@xY w)u“  Compute gradients with cuDNN disabled.

        Args:
            ctx: Autograd context with saved tensors and conv parameters.
            grad_output: Upstream gradient ``(N, C, H, W)``.

        Returns:
            Gradients for each ``forward`` input.  Inputs that do not require gradients (``ctx.needs_input_grad[i]`` is
            ``False``) get ``None``. Non-tensor inputs always get ``None``.

        Note:
            Under AMP (``"bf16-mixed"`` or ``"16-mixed"``), ``grad_output`` may arrive in a reduced dtype while the
            saved ``weight`` stays ``fp32``.  Both tensors are upcast to ``weight.dtype`` before calling
            ``conv2d_input`` / ``conv2d_weight``.  ``grad_input`` is kept in ``weight.dtype`` (fp32) so that upstream
            gradient accumulation into fp32 leaf parameters stays in fp32 â€” matching standard ``F.conv2d`` backward
            behaviour.  Casting back to the activation dtype (``x.dtype``) would propagate a reduced-precision gradient
            to fp32 backbone parameters, causing a ``params, grads, exp_avgs, and exp_avg_sqs must have same dtype``
            crash in fused AdamW (see issue #959).
        r   é   é   N)ÚdtypeFr   r   )r   r"   é   ©Údim)Úsaved_tensorsÚneeds_input_gradr   Útor#   r   r   r   r   ÚnnÚgradÚconv2d_inputÚshaper   r   r   r   Úconv2d_weightÚsum)r   r   r	   r
   Úneeds_x_gradÚneeds_w_gradÚneeds_b_gradÚ
grad_inputÚgrad_weightÚ	grad_biasÚgrad_output_casts              r   Úbackwardz#_DepthwiseConvWithoutCuDNN.backwardF   s†  € ð0 ×%Ñ%‰	ˆˆ6à×+Ñ+¨AÑ.ˆØ×+Ñ+¨AÑ.ˆØ—|‘|Ò?¨×(<Ñ(<¸QÑ(?ˆàˆ
ØˆØˆ	áš<ð
  +Ÿ~™~°F·L±L˜~ÓAÐä—‘×%Ñ%×+Ñ+°EÐ+Ó:ñ ÙÜ!&§¡§¡×!;Ñ!;ØŸ™ØØ(Ø"Ÿz™zØ #§¡Ø!$§¡Ø"Ÿz™zð "<ó "�Jñ  Ü"'§(¡(§-¡-×"=Ñ"=ØŸ™ 6§<¡<˜Ó0ØŸ™Ø(Ø"Ÿz™zØ #§¡Ø!$§¡Ø"Ÿz™zð #>ó #�K÷ñ, Ø#Ÿ™¨V¯\©\˜Ó:×>Ñ>À9Ð>ÓMˆIà˜;¨	°4¸¸tÀTÐIÐI÷3ð ús   ÂC#F>Æ>G)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   ÚautogradÚfunctionÚFunctionCtxÚTensorÚtupleÚintr   r7   © ó    r   r   r      s8  „ ñð ð$oØ�^‰^×$Ñ$×0Ñ0ð$oà�<‰<ð$oð —‘ð$oð �l‰l˜TÑ!ð	$oð
 �c˜3�h‘ð$oð �s˜C�x‘ð$oð ˜˜S˜‘/ð$oð ð$oð 
�‰ò$oó ð$oðL ðAJØ�^‰^×$Ñ$×0Ñ0ðAJà—\‘\ðAJð 
ˆu�|‰|˜dÑ" E§L¡L°4Ñ$7¸¿¹ÈÑ9LÈdÐTXÐZ^Ð`dÐdÑ	eòAJó ñAJrD   r   c                   ób   ‡ — e Zd ZdZdˆ fd„	Zdej                  dej                  fd„Zd„ Zˆ xZ	S )ÚDepthwiseConvBlockz1Simplified ConvNeXt block without the MLP subnet.c                 ó~  •— t         ‰| �  «        t        j                  ||dd|¬«      | _        t        j
                  |d¬«      | _        t        j                  ||«      | _        t        j                  «       | _
        |dkD  r3t        j                  |t        j                  |«      z  d¬«      | _        y d | _        y )	Nr$   r!   )Úkernel_sizer   r   g�íµ ÷Æ°>)Úepsr   T©Úrequires_grad)ÚsuperÚ__init__r*   ÚConv2dÚdwconvÚ	LayerNormÚnormÚLinearÚpwconv1ÚGELUÚactÚ	Parameterr   ÚonesÚgamma©Úselfr&   Úlayer_scale_init_valueÚ	__class__s      €r   rM   zDepthwiseConvBlock.__init__Ž   s”   ø€ Ü‰ÑÔÜ—i‘i  S°aÀÈ3ÔOˆŒÜ—L‘L ¨$Ô/ˆŒ	Ü—y‘y  cÓ*ˆŒÜ—7‘7“9ˆŒð &¨Ò)ô �L‰LÐ/´%·*±*¸cÓ2CÑCÐSWÔXð 	�
ð ð 	�
rD   r	   r   c           	      ó(  — t         j                  || j                  j                  | j                  j                  | j                  j
                  | j                  j                  | j                  j                  | j                  j                  «      S ©N)	r   ÚapplyrO   r
   r   r   r   r   r   )rZ   r	   s     r   Ú_depthwise_convz"DepthwiseConvBlock._depthwise_convš   sh   € ô
 *×/Ñ/ØØ�K‰K×ÑØ�K‰K×ÑØ�K‰K×ÑØ�K‰K×ÑØ�K‰K× Ñ Ø�K‰K×Ñó
ð 	
rD   c                 ó  — |}| j                  |«      }|j                  dddd«      }| j                  |«      }| j                  |«      }| j	                  |«      }| j
                  �| j
                  |z  }|j                  dddd«      }||z   S )Nr   r"   r$   r!   )r`   ÚpermuterQ   rS   rU   rX   )rZ   r	   Úinputs      r   r   zDepthwiseConvBlock.forward©   s‡   € ØˆØ× Ñ  Ó#ˆØ�I‰I�a˜˜A˜qÓ!ˆØ�I‰I�a‹LˆØ�L‰L˜‹OˆØ�H‰H�Q‹KˆØ�:‰:Ð!Ø—
‘
˜Q‘ˆAØ�I‰I�a˜˜A˜qÓ!ˆà�5‰yÐrD   ©r   )
r8   r9   r:   r;   rM   r   r@   r`   r   Ú__classcell__©r\   s   @r   rF   rF   ‹   s+   ø„ Ù<õ

ð
 §¡ð 
°%·,±,ó 
örD   rF   c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )ÚMLPBlockc                 óŽ  •— t         ‰| �  «        t        j                  |«      | _        t        j
                  t        j                  ||dz  «      t        j                  «       t        j                  |dz  |«      g«      | _        |dkD  r3t        j                  |t        j                  |«      z  d¬«      | _        y d | _        y )Né   r   TrJ   )rL   rM   r*   rP   Únorm_inÚ
ModuleListrR   rT   ÚlayersrV   r   rW   rX   rY   s      €r   rM   zMLPBlock.__init__¸   s�   ø€ Ü‰ÑÔÜ—|‘| CÓ(ˆŒÜ—m‘mä—	‘	˜#˜s Q™wÓ'Ü—‘“	Ü—	‘	˜# ™' 3Ó'ðó
ˆŒð &¨Ò)ô �L‰LÐ/´%·*±*¸cÓ2CÑCÐSWÔXð 	�
ð ð 	�
rD   c                 óš   — |}| j                  |«      }| j                  D ]
  } ||«      }Œ | j                  �| j                  |z  }||z   S r^   )rk   rm   rX   )rZ   r	   rc   Úlayers       r   r   zMLPBlock.forwardÈ   sQ   € ØˆØ�L‰L˜‹OˆØ—[‘[ò 	ˆEÙ�a“‰Að	à�:‰:Ð!Ø—
‘
˜Q‘ˆAØ�5‰yÐrD   rd   )r8   r9   r:   rM   r   re   rf   s   @r   rh   rh   ·   s   ø„ õ
ö rD   rh   c                   óŠ  ‡ — e Zd Zddededefˆ fd„Zd„ Z	 ddej                  deej                     de	eef   d	e
d
eej                     f
d„Z	 ddej                  deej                     de	eef   d	e
d
eej                     f
d„Z	 ddej                  deej                     de	eef   d	e
d
eej                     f
d„Zˆ xZS )ÚSegmentationHeadÚ
num_blocksÚbottleneck_ratioÚdownsample_ratioc                 óF  •— t         ‰| �  «        || _        |�||z  n|| _        t	        j
                  t        |«      D �cg c]  }t        |«      ‘Œ c}«      | _        |€t	        j                  «       n!t	        j                  || j                  d¬«      | _        t        |«      | _        |€t	        j                  «       nt	        j                  || j                  «      | _        t	        j                   t#        j$                  d«      d¬«      | _        d| _        y c c}w )Nr!   )rH   TrJ   F)rL   rM   rt   Úinteraction_dimr*   rl   ÚrangerF   ÚblocksÚIdentityrN   Úspatial_features_projrh   Úquery_features_blockrR   Úquery_features_projrV   r   Úzerosr   Ú_export)rZ   Úin_dimrr   rs   rt   Ú_r\   s         €r   rM   zSegmentationHead.__init__Ó   sß   ø€ Ü‰ÑÔà 0ˆÔØ=MÐ=Y˜vÐ)9Ò9Ð_eˆÔÜ—m‘mÌÈzÓIZÖ$[ÀAÔ%7¸Õ%?Ò$[Ó\ˆŒà-Ð5ŒB�K‰KŒM¼2¿9¹9ÀVÈT×MaÑMaÐopÔ;qð 	Ô"ô %-¨VÓ$4ˆÔ!à-Ð5ŒB�K‰KŒM¼2¿9¹9ÀVÈT×MaÑMaÓ;bð 	Ô ô —L‘L¤§¡¨Q£¸tÔDˆŒ	àˆ�ùò %\s   ÁDc                 ó*  — d| _         | j                  | _        | j                  | _        | j	                  «       D ]W  \  }}t        |d«      sŒt        |j                  t        «      sŒ.t        |d«      sŒ;|j                   rŒH|j                  «        ŒY y )NTÚexportr~   )	r~   r   Ú_forward_originÚforward_exportÚnamed_modulesÚhasattrÚ
isinstancer‚   r   )rZ   ÚnameÚms      r   r‚   zSegmentationHead.exportæ   sr   € ØˆŒØ#Ÿ|™|ˆÔØ×*Ñ*ˆŒØ×)Ñ)Ó+ò 	‰GˆD�!Ü�q˜(Õ#¬
°1·8±8¼XÕ(FÌ7ÐSTÐV_ÕK`Ðij×irÓirØ—‘•
ñ	rD   Úspatial_featuresÚquery_featuresÚ
image_sizeÚskip_blocksr   c                 óv  — |d   | j                   z  |d   | j                   z  f}t        j                  ||dd¬«      }g }|sŒt        | j                  |«      D ]q  \  }} ||«      }| j                  |«      }	| j                  | j                  |«      «      }|j                  t        j                  d|	|«      | j                  z   «       Œs |S t        |«      dk(  sJ d«       ‚| j                  | j                  |d   «      «      }|j                  t        j                  d||«      | j                  z   «       |S )Nr   r!   ÚbilinearF©ÚsizeÚmodeÚalign_cornersúbchw,bnc->bnhwú9skip_blocks is only supported for length 1 query features)rt   r   ÚinterpolateÚziprx   rz   r|   r{   Úappendr   Úeinsumr   Úlen)
rZ   rŠ   r‹   rŒ   r�   Útarget_sizeÚmask_logitsÚblockÚqfrz   s
             r   r   zSegmentationHead.forwardî   sD  € ð " !‘}¨×(=Ñ(=Ñ=¸zÈ!¹}ÐPT×PeÑPeÑ?eÐfˆÜŸ=™=Ð)9ÀÐR\ÐlqÔrÐàˆÙÜ  §¡¨nÓ=ò j‘	��rÙ#(Ð)9Ó#:Ð Ø(,×(BÑ(BÐCSÓ(TÐ%Ø×-Ñ-¨d×.GÑ.GÈÓ.KÓL�Ø×"Ñ"¤5§<¡<Ð0@ÐBWÐY[Ó#\Ð_c×_hÑ_hÑ#hÕið	jð Ðô	 �~Ó&¨!Ò+ÐhÐ-hÓhÐ+Ø×)Ñ)¨$×*CÑ*CÀNÐSTÑDUÓ*VÓWˆBØ×ÑœuŸ|™|Ð,<Ð>NÐPRÓSÐVZ×V_ÑV_Ñ_Ô`àÐrD   c                 ó&  — |d   | j                   z  |d   | j                   z  f}t        j                  ||dd¬«      }g }|sxt        | j                  |«      D ]]  \  }} ||«      }| j                  |«      }	| j                  | j                  |«      «      }|j                  |	|| j                  dœ«       Œ_ |S t        |«      dk(  sJ d«       ‚| j                  | j                  |d   «      «      }|j                  ||| j                  dœ«       |S )Nr   r!   r�   Fr�   )rŠ   r‹   r   r•   )rt   r   r–   r—   rx   rz   r|   r{   r˜   r   rš   )
rZ   rŠ   r‹   rŒ   r�   r›   Úoutput_dictsr�   rž   rz   s
             r   Úsparse_forwardzSegmentationHead.sparse_forward	  s2  € ð " !‘}¨×(=Ñ(=Ñ=¸zÈ!¹}ÐPT×PeÑPeÑ?eÐfˆÜŸ=™=Ð)9ÀÐR\ÐlqÔrÐð ˆáÜ  §¡¨nÓ=ò ‘	��rÙ#(Ð)9Ó#:Ð Ø(,×(BÑ(BÐCSÓ(TÐ%Ø×-Ñ-¨d×.GÑ.GÈÓ.KÓL�à×#Ñ#à,AØ*,Ø $§	¡	ñõðð2 Ðô �~Ó&¨!Ò+ÐhÐ-hÓhÐ+à×)Ñ)¨$×*CÑ*CÀNÐSTÑDUÓ*VÓWˆBà×Ñà(8Ø&(Ø ŸI™Iñôð ÐrD   c                 óŽ  — t        |«      dk(  sJ d«       ‚|d   | j                  z  |d   | j                  z  f}t        j                  ||dd¬«      }|s| j                  D ]
  } ||«      }Œ | j                  |«      }| j                  | j                  |d   «      «      }t        j                  d||«      | j                  z   gS )Nr!   zCat export time, segmentation head expects exactly one query featurer   r�   Fr�   r”   )rš   rt   r   r–   rx   rz   r|   r{   r   r™   r   )	rZ   rŠ   r‹   rŒ   r�   r›   r�   rz   rž   s	            r   r„   zSegmentationHead.forward_export6  sÕ   € ô �>Ó" aÒ'ÐnÐ)nÓnÐ'à! !‘}¨×(=Ñ(=Ñ=¸zÈ!¹}ÐPT×PeÑPeÑ?eÐfˆÜŸ=™=Ð)9ÀÐR\ÐlqÔrÐáØŸ™ò ;�Ù#(Ð)9Ó#:Ñ ð;ð !%× :Ñ :Ð;KÓ LÐà×%Ñ% d×&?Ñ&?ÀÈqÑ@QÓ&RÓSˆÜ—‘Ð-Ð/DÀbÓIÈDÏIÉIÑUÐVÐVrD   )r!   rj   )F)r8   r9   r:   rB   rM   r‚   r   r@   ÚlistrA   Úboolr   r¡   r„   re   rf   s   @r   rq   rq   Ò   s3  ø„ ñ¨3ð À#ð Ð]`õ ò&ð "ñàŸ,™,ðð ˜UŸ\™\Ñ*ðð ˜#˜s˜(‘Oð	ð
 ðð 
ˆe�l‰lÑ	óð@ "ñ+àŸ,™,ð+ð ˜UŸ\™\Ñ*ð+ð ˜#˜s˜(‘Oð	+ð
 ð+ð 
ˆe�l‰lÑ	ó+ðd "ñWàŸ,™,ðWð ˜UŸ\™\Ñ*ðWð ˜#˜s˜(‘Oð	Wð
 ðWð 
ˆe�l‰lÑ	÷WrD   rq   rc   Úpoint_coordsÚkwargsr   c                 ó  — d}|j                  «       dk(  rd}|j                  d«      }d|z  dz
  }|j                  dd«      }|j                  d	d«      }|j                  d
d«      }|dk(  rg|r6dj                  t	        |j                  «       «      «      }t        d|› �«      ‚|dvrt        j                  | ||||¬«      }	n+t        | |||¬«      }	nt        j                  | |f|||dœ|¤Ž}	|r|	j                  d«      }	|	S )aý  A wrapper around :func:`~rfdetr.utilities.tensors._bilinear_grid_sample` to support 3D point_coords tensors.
    Unlike :func:`torch.nn.functional.grid_sample` it assumes `point_coords` to lie inside [0, 1] x [0, 1] square.

    Args:
        input: A tensor of shape (N, C, H, W) that contains features map on a H x W grid.
        point_coords: A tensor of shape (N, P, 2) or (N, Hgrid, Wgrid, 2) that contains
            [0, 1] x [0, 1] normalized point coordinates.

    Returns:
        A tensor of shape (N, C, P) or (N, C, Hgrid, Wgrid) that contains
            features for points in `point_coords`. The features are obtained via bilinear
            interpolation from `input` the same way as :func:`~rfdetr.utilities.tensors._bilinear_grid_sample`.
    Fr$   Tr"   g       @g      ð?r’   r�   r“   Úpadding_modeÚborderz, z2Unexpected keyword argument(s) for bilinear mode: )r}   r©   )r’   r¨   r“   )r¨   r“   )r&   Ú	unsqueezeÚpopÚjoinÚsortedÚkeysÚ	TypeErrorr   Úgrid_sampler   Úsqueeze)
rc   r¥   r¦   Úadd_dimÚgridr’   r“   r¨   Ú
unexpectedÚoutputs
             r   Úpoint_sampler¶   L  s3  € ð €GØ×ÑÓ˜QÒØˆØ#×-Ñ-¨aÓ0ˆð �Ñ Ñ#€Dð �:‰:�f˜jÓ)€DØ—J‘J˜°Ó6€MØ—:‘:˜n¨hÓ7€LàˆzÒÙØŸ™¤6¨&¯+©+«-Ó#8Ó9ˆJÜÐPÐQ[ÐP\Ð]Ó^Ð^ð Ð2Ñ2Ü—]‘]ØØØØ)Ø+ô‰Fô +ØØØ)Ø+ô	‰Fô —‘ØØð
ð Ø%Ø'ñ
ð ñ
ˆñ Ø—‘ Ó"ˆØ€MrD   Úcoarse_logitsÚuncertainty_funcÚ
num_pointsÚoversample_ratioÚimportance_sample_ratioc           	      ó¶  — |dk\  sJ ‚|dk  r|dk\  sJ ‚| j                   d   }t        ||z  «      }t        j                  ||d| j                  ¬«      }t        | |d¬«      } ||«      }	t        ||z  «      }
||
z
  }t        j                  |	dd…ddd…f   |
d¬«      d   }|t        j                  |t        j                  | j                  ¬	«      z  }||dd…df   z  }|j                  d
d«      |j                  d
«      dd…f   j                  ||
d«      }|dkD  r:t        j                  |t        j                  ||d| j                  ¬«      gd¬«      }|S )a’  Sample points in [0, 1] x [0, 1] coordinate space based on their uncertainty.

    The uncertainties are calculated for each point using 'uncertainty_func' function that takes point's logit
    prediction as input. See PointRend paper for details.

    Args:
        coarse_logits: A tensor of shape (N, C, Hmask, Wmask) or (N, 1, Hmask, Wmask) for
            class-specific or class-agnostic prediction.
        uncertainty_func: A function that takes a Tensor of shape (N, C, P) or (N, 1, P) that
            contains logit predictions for P points and returns their uncertainties as a Tensor of shape (N, 1, P).
        num_points: The number of points P to sample.
        oversample_ratio: Oversampling parameter.
        importance_sample_ratio: Ratio of points that are sampled via importance sampling.

    Returns:
        A tensor of shape (N, P, 2) that contains the coordinates of sampled points.
    r!   r   r"   )ÚdeviceF)r“   N)Úkr&   )r#   r½   éÿÿÿÿr%   )r-   rB   r   Úrandr½   r¶   ÚtopkÚarangeÚlongÚviewÚcat)r·   r¸   r¹   rº   r»   Ú	num_boxesÚnum_sampledr¥   Úpoint_logitsÚpoint_uncertaintiesÚnum_uncertain_pointsÚnum_random_pointsÚidxÚshifts                 r   Ú*get_uncertain_point_coords_with_randomnessrÎ   �  sj  € ð0 ˜qÒ Ð Ð Ø" aÒ'Ð,CÀqÒ,HÐHÐHØ×#Ñ# AÑ&€IÜ�jÐ#3Ñ3Ó4€KÜ—:‘:˜i¨°aÀ×@TÑ@TÔU€LÜ ¨|È5ÔQ€Lñ +¨<Ó8ÐÜÐ6¸ÑCÓDÐØ"Ð%9Ñ9ÐÜ
�*‰*Ð(ª¨Aªq¨Ñ1Ð5IÈqÔ
QÐRSÑ
T€CØœ%Ÿ,™, y¼¿
¹
È=×K_ÑK_Ô`Ñ`€EØˆ5’�D�‰>Ñ€CØ×$Ñ$ R¨Ó+¨C¯H©H°R«Lº!¨OÑ<×AÑAÀ)ÐMaÐcdÓe€LØ˜1ÒÜ—y‘yàÜ—
‘
˜9Ð&7¸À=×CWÑCWÔXðð ô
ˆð ÐrD   Úlogitsc                 óv   — | j                   d   dk(  sJ ‚| j                  «       }t        j                  |«       S )a"  We estimate uncertainty as L1 distance between 0.0 and the logit prediction in 'logits' for the foreground class
    in `classes`.

    Args:
        logits: A tensor of shape (R, 1, ...) for class-specific or
            class-agnostic, where R is the total number of predicted masks in all images and C is the number of
            foreground classes. The values are logits.

    Returns:
        A tensor of shape (R, 1, ...) that contains uncertainty scores with the most uncertain locations having the
        highest uncertainty score.
    r!   )r-   Úcloner   Úabs)rÏ   Úgt_class_logitss     r   Úcalculate_uncertaintyrÔ   Æ  s7   € ð �<‰<˜‰?˜aÒÐÐØ—l‘l“n€OÜ�Y‰Y�Ó'Ð(Ð(rD   )r$   g      è?)Útypingr   r   r   Útorch.nnr*   Útorch.nn.functionalÚ
functionalr   Úrfdetr.utilities.tensorsr   r=   ÚFunctionr   ÚModulerF   rh   rq   r@   r¶   rB   ÚfloatrÎ   rÔ   rC   rD   r   ú<module>rÝ      s  ð÷ !ã Ý ß Ð å :ôxJ §¡×!8Ñ!8ô xJôv)˜Ÿ™ô )ôXˆr�y‰yô ô6wW�r—y‘yô wWðt@˜Ÿ™ð @°E·L±Lð @ÈCð @ÐTY×T`ÑT`ó @ðN Ø%)ñ4Ø—<‘<ð4à §¡˜~¨u¯|©|Ð;Ñ<ð4ð ð4ð ð	4ð
 #ð4ð ‡\�\ó4ðn) %§,¡,ð )°5·<±<ô )rD   