+
    åûjBV  ã                  óö   € R t ^ RIHt ^ RIHt ^ RIt^ RIHu Ht	 ^ RIHt ^ RI
HtHt ^ RIHtHtHt ^ RIHt ^ RIHtHt RtR	 R
 ltR R ltR R ltR R ltRR R llt ! R R]P8                  4      tR# )u6   Module containing the SÃ¸rensen-Dice Coefficient loss.)Úannotations)ÚOptionalN)Únn)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSOR)Úis_autocast_enabledÚis_compilingÚis_exporting)Úmask_ignore_pixels)Ú_check_class_labelsÚone_hotc               ó$   € V ^8„  d   QhRRRRRR/# )é   Úpredútorch.TensorÚweightúOptional[torch.Tensor]ÚreturnÚbool© )Úformats   "ÚNC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\dice.pyÚ__annotate__r   ,   s#   € ÷ ñ  ,ð Ð8Nð ÐSWñ ó    c                ó„  € V P                   P                  R8H  ;'       Ed     V P                  \        P                  \        P
                  39   ;'       dë    VRJ ;'       gD    \        V\        P                  4      ;'       d½    VP                  V P                  8H  ;'       dœ    \        4       '       * ;'       d…    \        P                  P                  4       '       * ;'       dZ    V P                  4       \        8¬  ;'       d;    \        P                  P                  4       '       * ;'       d    \        4       '       * # )zlSelect native-precision CPU logits, whose one-hot target and full-size products are fresh memory every call.ÚcpuN)ÚdeviceÚtypeÚdtypeÚtorchÚfloat32Úfloat64Ú
isinstanceÚTensorr	   ÚjitÚ
is_tracingÚnumelÚ_CPU_MIN_NUMELÚ_CÚ _are_functorch_transforms_activer   )r   r   s   &&r   Ú_dice_loss_cpu_eligibler*   ,   sý   € ð 	�‰×Ñ˜EÑ!÷ 
	&ñ 
	&Ø�J‰Jœ5Ÿ=™=¬%¯-©-Ð8Ñ8÷
	&ð 
	&à�tˆ^×`Ð`¤
¨6´5·<±<Ó @÷
	&à _ÀVÇ\Á\ÐUY×U_ÑU_ÑE_÷
	&ð 
	&ô “Ô÷
	&ð 
	&ô —	‘	×$Ñ$Ó&Ô&÷
	&ð 
	&ð �J‰J‹LœNÑ*÷
	&ð 
	&ô —‘×9Ñ9Ó;Ô;÷
	&ð 
	&ô $Ó%Ô%ðr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r   r   ÚNoner   )r   s   "r   r   r   A   s!   € ÷ ñ ˜ð ¨lð ¸tñ r   c                óh  € V P                   ^,          p\        VR4       \        VP                   ^ ,          V8H  ;'       d    VP                  4       V8H  RVP                    RV P                    24       \        VP                  V P                  8H  RVP                   RV P                   24       R# )z5Validate the class weights as :func:`dice_loss` does.ú$weight must be torch.Tensor or None.úBweight must hold one value per class of pred: got weight of shape ú for pred of shape ú1weight and pred must be in the same device. Got: ú and N)Úshaper   r   r&   r   )r   r   Únum_of_classess   && r   Ú_check_weightr5   A   s–   € à—Z‘Z •]€NÜ˜6Ð#IÔJÜØ	�‰�a�˜NÑ	*×	OÐ	O¨v¯|©|«~ÀÑ/OØ
LÈVÏ\É\ÈNÐZmØ�:‰:ˆ,ð	ôô
 Ø�‰˜Ÿ™Ñ$Ø
;¸F¿M¹M¸?È%ÐPT×P[ÑP[È}Ð]ör   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Ú	pred_softr   ÚtargetÚfusedr   r   r   )r   s   "r   r   r   P   s)   € ÷ 
?ñ 
? <ð 
?¸ð 
?Èdð 
?ÐWcñ 
?r   c                ól  € V'       d~   \         P                  ! V P                  ^,          V P                  R7      P	                  ^R^^4      p\         P
                  ! W1P                  ^4      8H  V R4      P                  ^4      # V P                  ^VP                  ^4      4      P                  ^4      # )a‹  The probability ``(B, H, W)`` of each pixel's target class.

The one-hot selection sums one probability and exact zeros, so a gather gives the same values and gradients
bitwise. Eager code gathers: no full-size temporary. ``fused`` selects instead, for ``torch.compile`` to fuse the
selection into the softmax and its backward, where the gather's backward would be a separate full-size scatter.
)r   ç        éÿÿÿÿ)
r   Úaranger3   r   ÚviewÚwhereÚ	unsqueezeÚsumÚgatherÚsqueeze)r7   r8   r9   Úclassess   &&& r   Ú_target_probabilityrE   P   s�   € ÷ Ü—,’,˜yŸ™¨qÕ1¸)×:JÑ:JÔK×PÑPÐQRÐTVÐXYÐ[\Ó]ˆÜ�{Š{˜7×&6Ñ&6°qÓ&9Ñ9¸9ÀcÓJ×NÑNÈqÓQÐQØ×Ñ˜A˜v×/Ñ/°Ó2Ó3×;Ñ;¸AÓ>Ð>r   c               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# ©r   r   r   r8   ÚaverageÚstrÚepsÚfloatr   r   Úignore_indexúOptional[int]r   r   )r   s   "r   r   r   ]   s`   € ÷ JSñ JSØ
ðJSàðJSð ðJSð 
ð	JSð
 #ðJSð  ðJSð ñJSr   c                ó´  € V P                   R,          w  rg\        W4      w  r\        VP                  \        P
                  8H  RVP                   24       \        W4      pVe   \        W4       V P                  ^4      p	Vf"   \        P                  ! WP                  R7      MVP                  V P                  4      p
VR8X  EdR   Vf)   V	P                  ^4      V
,          P                  R4      pM?W”P                  ^R^^4      ,          P                  ^4      V
,          P                  R4      p\        W‘\        4       R7      pVf   T
pM˜VP                  R4      P                  \        P                   4      P#                  Wg4      P%                  ^VP'                  ^4      4      pVP                  VP                   4      P                  V P                  4      pWê,          pWÍ,          P                  R4      pW½P                  R4      ,           pRpEM0Vf   V	P                  R4      M\        P(                  ! RWš4      p\        W‘RR7      V
,          pVP'                  ^4      pV	P+                  Wg\        P                   R7      pVP-                  ^VVP'                  ^4      P                  \        P                   4      4      P                  V P                  4      pVP-                  ^VV
P'                  ^4      P                  \        P                   4      4      P                  V P                  4      pVV,           pV^ 8„  pVf   V P/                  V4      MTpV^ 8H  pR	V,          VV,           P1                  VR
4      ,          P1                  VR4      pV) R
,           pVea   VV,          pVP                  R4      pV^ 8H  pVV,          P                  R4      VP1                  V^4      ,          pVP1                  V^4      p\        P2                  ! V4      P                  \        P4                  ! V P                  VP                  4      4      # )až  The Dice loss of :func:`dice_loss` without a one-hot target.

A one-hot target makes every sum a full-size product: on a large CPU batch, fresh memory that is faulted in on
every call. Here the intersection is the softmax of each pixel's target class. The micro Dice sums
:math:`\sum_c w_c p_c` per pixel; the macro Dice needs the probability mass of class :math:`c` over the valid
pixels of sample :math:`b`, :math:`S_{bc} = \sum_{hw} m\, p_c`, a batched matrix-vector product, and adds its
per-class intersections and target pixel counts into ``(B, C)`` bins. The ratio and the averaging are those of
:func:`dice_loss`. Values agree with the one-hot sums to rounding.
:Nr   Nz*labels must be of dtype torch.int64. Got: N©r   Úmicro)r9   zbchw,bhw->bcFç       @ç      ð?r;   )é   r   r<   ©r   é   )r3   r
   r   r   r   Úint64r   r5   ÚsoftmaxÚ	ones_likeÚtorA   r>   rE   r   Úreshaper!   ÚexpandrB   ÚflattenÚeinsumÚ	new_zerosÚscatter_addÚnew_onesÚmasked_fillÚmeanÚpromote_types)r   r8   rH   rJ   r   rL   ÚbatchÚnum_classesÚtarget_maskr7   ÚvalidÚmassÚprob_targetÚtarget_massÚweight_targetÚintersectionÚcardinalityÚpresentÚ
class_massÚindexÚbinsÚtarget_countÚemptyÚ
dice_scoreÚ	dice_lossÚ
normalizers   &&&&&&                    r   Ú_dice_loss_cpurw   ]   s†  € ð" Ÿ™ B�Ñ€EÜ,¨VÓBÑ€FÜ�—‘¤§¡Ñ,Ð0ZÐ[a×[gÑ[gÐZhÐ.iÔjô ! Ó5€FØÒÜ�dÔ#à—‘˜Q“€IØ9DÒ9LŒE�OŠO˜F¯*©*Õ5ÐR]×R`ÑR`Ðae×akÑakÓRl€Eð �'ÕàŠ>Ø—M‘M !Ó$ uÕ,×1Ñ1°&Ó9‰Dà§¡¨Q°°A°qÓ!9Õ9×>Ñ>¸qÓAÀEÕI×NÑNÈvÓVˆDô *¨)Ä<Ã>ÔRˆØŠ>Ø‰Kð #ŸN™N¨2Ó.×1Ñ1´%·-±-Ó@×GÑGÈÓ[×bÑbÐcdÐfl×ftÑftÐuvÓfwÓxˆMØ)×.Ñ.¨v¯|©|Ó<×?Ñ?ÀÇ
Á
ÓKˆMØ'Õ/ˆKØ#Õ1×6Ñ6°vÓ>ˆØŸ_™_¨VÓ4Õ4ˆØŠà.9Ò.A�Y—]‘] 6Ô*ÄuÇ|Â|ÐTbÐdmÓGuˆ
ô *¨)À5ÔIÈEÕQˆØ—‘˜qÓ!ˆð ×"Ñ" 5¼U¿]¹]Ð"ÓKˆØ×'Ñ'¨¨5°+×2EÑ2EÀaÓ2H×2KÑ2KÌEÏMÉMÓ2ZÓ[×^Ñ^Ð_c×_iÑ_iÓjˆØ×'Ñ'¨¨5°%·-±-ÀÓ2B×2EÑ2EÄeÇmÁmÓ2TÓU×XÑXÐY]×YcÑYcÓdˆØ  <Õ/ˆØ Ñ"ˆà+1ª>ˆT�]‰]˜;Ô'¸v€FØ˜1Ñ€EØ˜Õ$¨°cÕ(9×'FÑ'FÀuÈcÓ'RÕR×_Ñ_Ð`eÐgjÓk€JØ�˜cÕ!€IØÒØ˜'Õ!ˆØ—Z‘Z “^ˆ
Ø˜a‘ˆØ Õ'×,Ñ,¨RÓ0°:×3IÑ3IÈ%ÐQRÓ3SÕSˆ	Ø×)Ñ)¨%°Ó3ˆ	Ü�:Š:�iÓ ×#Ñ#¤E×$7Ò$7¸¿
¹
ÀFÇLÁLÓ$QÓRÐRr   c               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# rG   r   )r   s   "r   r   r   ª   sW   € ÷ m2ñ m2Ø
ðm2àðm2ð ðm2ð 
ð	m2ð
 #ðm2ð  ðm2ð ñm2r   c                ó 
  € \        V 4       \        V4       \        V P                  4      ^8X  g   \        RV P                   24      hV P                  RR VP                  RR 8X  g&   \        RV P                   RVP                   24      hV P                  VP                  8X  g&   \        RV P                   RVP                   24      hV P                  ^ ,          VP                  ^ ,          8X  d*   V P                  R,          VP                  R,          8X  gV   \        R\
        P                  ! V P                  ^ ,          .V P                  R,          O54       R	VP                   24      h\        V\        \        34      '       d   VR
8  d   \        RV 24      hV P                  ^,          pRR0p\        W'9   RV RV 24       \        W4      '       d   \        WW#WE4      # \        P                  ! V ^R7      p\        W4      w  rV P                   \
        P"                  \
        P$                  39   d   \
        P&                  MV P                   p
\)        WP                  ^,          V P                  V
R7      pV	e"   V	P+                  ^4       W¹,          pW‰,          pVe    \        VR4       \        VP                  ^ ,          V8H  ;'       d    VP-                  4       V8H  RVP                   RV P                   24       \        VP                  V P                  8H  RVP                   RV P                   24       M"V P/                  V P                  ^,          4      p\
        P0                  ! V P                   VP                   4      pRpTpVR8X  d*   ^.VO5pVP3                  R^^4      pW„,          pW´,          pVP                   \
        P"                  \
        P$                  39   d   \
        P&                  MVP                   p\
        P4                  ! WŽ,          WßR7      p\
        P4                  ! W‹,           WßR7      pV^ 8H  pRV,          VV,           P7                  VR4      ,          P7                  VR
4      pV) R,           pVR8X  d†   V^8H  P9                  RR7      P9                  RR7      pVV,          pVP5                  R4      pV^ 8H  pVV,          P5                  R4      VP7                  V^4      ,          pVP7                  V^4      p\
        P:                  ! V4      P=                  V4      # )u$  Compute the SÃ¸rensen-Dice loss of ``(B, C, H, W)`` logits against ``(B, H, W)`` class indices.

``loss = dice_loss(pred, target)`` is one minus the Dice overlap [1] between the softmax of ``pred`` over the
classes (:math:`X`) and the one-hot ``target`` (:math:`Y`), averaged over the batch.

.. math::

    \text{loss} = 1 - \frac{2 |X \cap Y|}{|X| + |Y|}

Reference:
    [1] https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient

Convention:
    - ``pred`` and ``target`` are those of :func:`~kornia.losses.focal_loss` (logits with the softmax taken
      inside, int64 class indices; see its Convention block), restricted to ``(B, C, H, W)`` and ``(B, H, W)``.
      A one-channel ``pred`` has a softmax of 1 everywhere and gives a constant loss with zero gradient: a binary
      task passes two channels.
    - ``'micro'`` (default) computes one Dice per sample over all classes and pixels, ``weight`` scaling the
      terms of class ``c`` in both sums: :math:`1 - 2 \sum_c w_c |X_c \cap Y_c| / \sum_c w_c (|X_c| + |Y_c|)`.
      ``'macro'`` computes one Dice per sample and class and averages them as
      :math:`\sum_c w_c \, \text{loss}_c / \sum_c w_c` over the classes present in the sample's non-ignored
      target: a class that is predicted but absent from the target is left out. Both then average over the batch;
      there is no ``reduction``.
    - ``eps`` is added to the denominator only: :math:`1 - 2 |X \cap Y| / (|X| + |Y| + \epsilon)`.
    - Pixels labelled ``ignore_index`` (default ``-100``) leave both sums of their own sample. A sample whose
      pixels are all ignored, or whose present classes all have weight 0, enters the batch mean as loss 1 with a
      zero gradient, at ``eps=0`` as well.
    - On the CPU, float32 or float64 logits with at least :math:`2^{15}` values and a ``weight`` that is
      ``None`` or of their dtype skip the one-hot target, unless ``torch.export`` or ``torch.jit.trace`` captures
      the call, a functorch transform runs or autocast is on: the intersection takes each pixel's target-class
      probability, ``'micro'`` sums the (weighted) probabilities of each pixel over the classes, and ``'macro'``
      takes the probability mass of each class from a batched matrix-vector product and adds the per-class sums
      into ``(B, C)`` bins, so no full-size product with a one-hot target is formed. The result agrees with the
      one-hot sums to rounding, with the same NaN positions; a label outside ``[0, C)`` that is not
      ``ignore_index`` raises the same ``RuntimeError`` as ``one_hot``, also under ``torch.compile``. Some torch
      releases (2.5.1 and 2.9.1 among them) report a ``torch.compile`` capture as an export: a compiled call keeps
      the one-hot target there, and its compiled ``one_hot`` does not check the labels.

Args:
    pred: logits ``(B, C, H, W)``.
    target: int64 class indices ``(B, H, W)`` in ``[0, C)``, or ``ignore_index``.
    average: ``'micro'`` (default) or ``'macro'``.
    eps: term added to the denominator, non-negative.
    weight: class weights ``(C,)``; ``None`` weights every class by 1.
    ignore_index: label whose pixels are left out; ``None`` ignores no label.

Returns:
    the loss, a 0-d tensor.

Note:
    Spatial reductions use float32 for float16 and bfloat16 inputs to avoid
    overflow on large images. The returned loss retains the usual dtype
    promotion between the inputs and class weights.

See Also:
    - :class:`~kornia.losses.DiceLoss`: the module form.
    - :func:`~kornia.losses.tversky_loss`: weights false positives and false negatives separately; averages the
      classes present in each sample, as ``'macro'`` does.
    - :func:`~kornia.losses.lovasz_softmax_loss`: optimises the IoU instead of the Dice overlap.
    - :func:`~kornia.losses.focal_loss`: a per-pixel cross entropy that down-weights easy pixels, not an overlap.

Example:
    >>> N = 5  # num_classes
    >>> pred = torch.randn(1, N, 3, 5, requires_grad=True)
    >>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)
    >>> output = dice_loss(pred, target)
    >>> output.backward()

z,Invalid pred shape, we expect BxNxHxW. Got: Nz.pred and target shapes must be the same. Got: r2   z1pred and target must be in the same device. Got: :r   NN:rS   NNzExpected target size z, got r;   úeps must be non-negative. Got: rP   ÚmacroúThe `average` has to be one of ú. Got: )Údim)re   r   r   r.   r/   r0   r1   rO   rQ   rR   éþÿÿÿrT   r<   )r   Úlenr3   Ú
ValueErrorr   r   ÚSizer"   ÚintrK   r   r*   rw   ÚFrW   r
   r   Úfloat16Úbfloat16r    r   Ú
unsqueeze_r&   r`   rc   r>   rA   ra   Úanyrb   rY   )r   r8   rH   rJ   r   rL   r4   Úpossible_averager7   rf   Útarget_dtypeÚtarget_one_hotÚoutput_dtypeÚdimsÚintersection_targetÚreduction_dtyperl   rm   rs   rt   ru   rn   rv   s   &&&&&&                 r   ru   ru   ª   s€  € ôZ ˜4Ô Ü˜6Ô"äˆt�z‰z‹?˜aÔÜÐGÈÏ
É
À|ÐTÓUÐUà�:‰:�b�cˆ?˜fŸl™l¨2¨3Ð/Ô/ÜÐIÈ$Ï*É*ÈÐUZÐ[a×[gÑ[gÐZhÐiÓjÐjà�;‰;˜&Ÿ-™-Ô'ÜÐLÈTÏ[É[ÈMÐY^Ð_e×_lÑ_lÐ^mÐnÓoÐoà�J‰J�q�M˜VŸ\™\¨!�_Ô,°·±¸BµÀ6Ç<Á<ÐPRÕCSÔ1SÜÐ0´·²¸T¿Z¹ZÈ½]Ð<\ÈTÏZÉZÐXZÍ^Ñ<\Ó1]Ð0^Ð^dÐek×eqÑeqÐdrÐsÓtÐtô �#œœU�|×$Ò$¨¨s¬ÜÐ:¸3¸%Ð@ÓAÐAà—Z‘Z •]€NØ Ð)ÐÜ�Ñ,Ð0OÐP`ÐOaÐahÐipÐhqÐ.rÔsä˜t×,Ò,Ü˜d¨G¸&ÓOÐOô  Ÿiši¨°!Ô4€Iä,¨VÓBÑ€Fð
 %)§J¡J´5·=±=Ä%Ç.Á.Ð2QÔ$Q”5—=’=ÐW[×WaÑWa€LÜ#*¨6¿z¹zÈ!½}ÐUY×U`ÑU`ÐhtÔ#u€Nð ÒØ×Ñ˜qÔ!Ø'Õ5ˆØÕ+ˆ	ð ÒÜ˜vÐ'MÔNÜØ�\‰\˜!�_ Ñ.×SÐS°6·<±<³>À^Ñ3SØPÐQW×Q]ÑQ]ÐP^Ð^qØ�z‰zˆlðô	
ô
 	Ø�M‰M˜TŸ[™[Ñ(Ø?ÀÇÁ¸ÈeÐTX×T_ÑT_ÐS`Ðaõ	
ð
 —‘˜tŸz™z¨!�}Ó-ˆä×&Ò& t§z¡z°6·<±<Ó@€Lð #€Dð )ÐØ�'ÔØˆz�D‰zˆà—‘˜R  AÓ&ˆØÕ&ˆ	Ø'Õ0ˆð (1§¡¼5¿=¹=Ì%Ï.É.Ð:YÔ'Y”e—m’mÐ_h×_nÑ_n€OÜ—9’9˜YÕ<¸dÔZ€LÜ—)’)˜IÕ6¸ÔT€Kð ˜1Ñ€EØ˜Õ$¨°cÕ(9×'FÑ'FÀuÈcÓ'RÕR×_Ñ_Ð`eÐgjÓk€JØ�˜cÕ!€Ið �'Ôà! QÑ&×+Ñ+°Ð+Ó3×7Ñ7¸BÐ7Ó?ˆØ˜'Õ!ˆØ—Z‘Z “^ˆ
à˜a‘ˆØ Õ'×,Ñ,¨RÓ0°:×3IÑ3IÈ%ÐQRÓ3SÕSˆ	Ø×)Ñ)¨%°Ó3ˆ	ä�:Š:�iÓ ×#Ñ# LÓ1Ð1r   c                  óB   a € ] tR tRtRtRR V 3R llltR R ltRtV ;t# )	ÚDiceLossiZ  u  Compute the SÃ¸rensen-Dice loss of ``(B, C, H, W)`` logits against ``(B, H, W)`` class indices (module form).

``criterion = DiceLoss(average, eps, weight, ignore_index)`` stores its arguments, and
``loss = criterion(pred, target)`` is :func:`~kornia.losses.dice_loss`. A plain tensor ``weight`` is stored as a
non-persistent buffer, so ``criterion.to(device)`` moves it and ``state_dict`` omits it.

Convention:
    See the Convention block of :func:`~kornia.losses.dice_loss`.

Args:
    average: ``'micro'`` (default) or ``'macro'``, as in :func:`~kornia.losses.dice_loss`.
    eps: term added to the denominator, non-negative.
    weight: class weights ``(C,)``; ``None`` weights every class by 1.
    ignore_index: label whose pixels are left out; ``None`` ignores no label.

Shape:
    - pred: logits ``(B, C, H, W)``.
    - target: int64 class indices ``(B, H, W)`` in ``[0, C)``, or ``ignore_index``.
    - Output: a 0-d tensor.

See Also:
    - :func:`~kornia.losses.dice_loss`: the one-call form.
    - :class:`~kornia.losses.TverskyLoss`: weights false positives and false negatives separately.
    - :class:`~kornia.losses.LovaszSoftmaxLoss`: optimises the IoU instead of the Dice overlap.
    - :class:`~kornia.losses.FocalLoss`: a per-pixel cross entropy that down-weights easy pixels, not an overlap.

Example:
    >>> criterion = DiceLoss()
    >>> pred = torch.randn(1, 5, 3, 5, requires_grad=True)
    >>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(5)
    >>> output = criterion(pred, target)
    >>> output.backward()

c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   rH   rI   rJ   rK   r   r   rL   rM   r   r,   r   )r   s   "r   r   ÚDiceLoss.__annotate__~  s<   € ÷ )ñ )àð)ð ð)ð 'ð	)ð
 $ð)ð 
ñ)r   c                óP  <€ \        V\        \        34      '       d   VR8  d   \        RV 24      hRR0p\	        W9   RV RV 24       \
        SV `  4        Wn        W n        \        V\        P                  4      '       d   W0n        MV P                  RVRR	7       W@n        R
# )a  Initialize the Dice loss module.

Args:
    average: Reduction strategy for multi-class computation.
    eps: Small constant added for numerical stability.
    weight: Optional class-weight tensor of shape ``(C,)``.
    ignore_index: Label value to exclude from loss computation.
r;   rz   rP   r{   r|   r}   r   F)Ú
persistentN)r"   rƒ   rK   r�   r   ÚsuperÚ__init__rH   rJ   r   Ú	Parameterr   Úregister_bufferrL   )ÚselfrH   rJ   r   rL   r‰   Ú	__class__s   &&&&& €r   r—   ÚDiceLoss.__init__~  s    ø€ ô �cœC¤˜<×(Ò(¨S°3¬YÜÐ>¸s¸eÐDÓEÐEØ# WÐ-ÐÜ�WÑ0Ð4SÐTdÐSeÐelÐmtÐluÐ2vÔwä‰ÑÔØŒØŒÜ�fœbŸl™l×+Ò+Ø �Kà× Ñ  ¨6¸eÐ ÔDØ(Ör   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r8   r   r   )r   s   "r   r   r“   ›  s&   € ÷ _ñ _˜Lð _°,ð _À<ñ _r   c                óp   € \        WV P                  V P                  V P                  V P                  4      # )uè  Compute SÃ¸rensen-Dice loss for segmentation logits and labels.

Args:
    pred: Logit tensor with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is number of classes,
        :math:`H` is height, and :math:`W` is width.
    target: Integer target labels with shape ``(B, H, W)``.

Returns:
    Scalar tensor containing ``1 - Dice`` after applying the configured
    averaging strategy, class weights, numerical epsilon, and optional
    ignored label handling.
)ru   rH   rJ   r   rL   )rš   r   r8   s   &&&r   ÚforwardÚDiceLoss.forward›  s)   € ô ˜ t§|¡|°T·X±X¸t¿{¹{ÈD×L]ÑL]Ó^Ð^r   )rH   rJ   rL   r   ©rP   g:Œ0âŽyE>Niœÿÿÿ)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r—   rŸ   Ú__static_attributes__Ú__classcell__)r›   s   @r   r‘   r‘   Z  s   ø† ñ!÷F)ò )÷:_ó _r   r‘   i €  r¡   )r¦   Ú
__future__r   Útypingr   r   Útorch.nn.functionalr   Ú
functionalr„   Úkornia.core.checkr   r   Úkornia.core.utilsr   r   r	   Úkornia.losses._utilsr
   Úkornia.losses.one_hotr   r   r'   r*   r5   rE   rw   ru   ÚModuler‘   r   r   r   Ú<module>r²      sd   ðñ$ =å "å ã ß Ð Ý ç Bß MÑ MÝ 3ß >ð €õõ*õ
?õJS÷Zm2ô`O_ˆr�y‰yö O_r   