+
    åûj¶$  ã                  óè   a € 0 t $ ^ RIHt ^ RIt^ RIHt ^ RIt^ RIHu H	t
 ^ RIHt ^ RIHt ^ RIHt ]P                  P                   tR]R&   R	 R
 ltRR R llt ! R R]P*                  4      tR# )é    )ÚannotationsN)ÚOptional)Únn)Úmask_ignore_pixels)Úone_hotÚfloatÚ
_FLOAT_MAXc               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Úalphar   ÚbetaÚepsÚreturnÚNone© )Úformats   "ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\tversky.pyÚ__annotate__r   %   s.   € ÷ Vñ V˜Uð V¨%ð V°eð VÀñ Vó    c                ó´   € R V 3RV3RV33 FH  w  r4\        V\        \        34      '       g   K#  RTu;8:  d   \        8:  d   K8  M \	        V RV 24      h	  R# )r   r   r   ç        z' must be non-negative and finite. Got: N)Ú
isinstanceÚintr   r	   Ú
ValueError)r   r   r   ÚnameÚvalues   &&&  r   Ú_check_parametersr   %   s\   € ð
 ! %Ð(¨6°4¨.¸5À#¸,ÓG‰ˆÜ�eœc¤5˜\×*Ô*°C¸5Ö4NÄJ×4NÐ4NÜ ˜vÐ%LÈUÈGÐTÓUÐUó Hr   c               ó4   € V ^8„  d   QhRRRRRRRRRRRR	R
R/# )r   Úpredútorch.TensorÚtargetr   r   r   r   Úignore_indexúOptional[int]r   r   )r   s   "r   r   r   /   sW   € ÷ c/ñ c/Ø
ðc/àðc/ð ðc/ð ð	c/ð
 
ðc/ð  ðc/ð ñc/r   c                ór  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\        P                  4      '       g   \        R\	        V4       24      h\        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\        W#V4       V P                  \        P                  \        P                  39   d   \        P                  MV P                  p\        P                   ! V ^VR7      p\#        W4      w  r\%        WP                  ^,          V P                  VRR7      p	Ve"   VP'                  ^4      p
Wz,          pWš,          p	RpWy,          P)                  V4      pVRV	,
          ,          P)                  V4      pRV,
          V	,          P)                  V4      pV	P)                  V4      ^ 8„  pWÂV,          ,           W>,          ,           V,           pVVP+                  V( R4      ,          P+                  V( R4      pVP)                  R4      VP)                  R4      P-                  ^4      ,          pRVP/                  4       ,
          P1                  V P                  4      # )a¤	  Compute the Tversky loss of ``(B, C, H, W)`` logits against ``(B, H, W)`` class indices.

``loss = tversky_loss(pred, target, alpha, beta)`` is one minus the Tversky index :cite:`salehi2017tversky` of the
softmax of ``pred`` over the classes (:math:`P`) and the one-hot ``target`` (:math:`G`) on the non-ignored pixels.
``alpha`` weights the false positives :math:`P \setminus G` and ``beta`` the false negatives :math:`G \setminus P`.

.. math::

    \text{loss} = 1 - \frac{|PG|}{|PG| + \alpha |P \setminus G| + \beta |G \setminus P|}

Convention:
    - ``pred``, ``target`` and ``ignore_index`` behave as in :func:`~kornia.losses.dice_loss`: logits
      ``(B, C, H, W)`` with the softmax taken inside, int64 class indices ``(B, H, W)`` and ignored pixels removed
      from their own sample. The index is computed per sample and class, averaged over the classes present in the
      sample's non-ignored target, then over the batch; a sample whose pixels are all ignored enters the batch
      mean as loss 1. There is no ``weight``, ``average`` or ``reduction``.
    - :math:`\alpha = \beta = 0.5` gives ``dice_loss(average='macro', eps=2 * eps)``, and
      :math:`\alpha = \beta = 1` the per-class Tanimoto coefficient. For :math:`\alpha + \beta = 1` and
      :math:`\alpha > 0`, the unsmoothed per-class score is :math:`F_{\sqrt{\beta / \alpha}}`.

Args:
    pred: logits ``(B, C, H, W)``.
    target: int64 class indices ``(B, H, W)`` in ``[0, C)``, or ``ignore_index``.
    alpha: weight of the false positives, non-negative and finite.
    beta: weight of the false negatives, non-negative and finite.
    eps: term added to the denominator, non-negative and finite.
    ignore_index: label whose pixels are left out; ``None`` ignores no label.

Returns:
    the loss, a 0-d tensor.

Note:
    Softmax, spatial reductions and the ratio use float32 for float16 and
    bfloat16 inputs to avoid overflow in large-image sums and ratio gradients.
    The returned loss retains the input dtype.

See Also:
    - :class:`~kornia.losses.TverskyLoss`: the module form.
    - :func:`~kornia.losses.dice_loss`: weights false positives and false negatives equally; adds ``average`` and
      class ``weight``.

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 = tversky_loss(pred, target, alpha=0.5, beta=0.5)
    >>> output.backward()

z%pred type is not a torch.Tensor. Got z'target type is not a torch.Tensor. Got z,Invalid pred shape, we expect BxNxHxW. Got: Nz.pred and target shapes must be the same. Got: z and z1pred and target must be in the same device. Got: :r   NN:é   NNzExpected target size z, got )ÚdimÚdtyper   )Údevicer'   r   g      ð?éþÿÿÿ)r   é   éÿÿÿÿ)r   ÚtorchÚTensorÚ	TypeErrorÚtypeÚlenÚshaper   r(   ÚSizer   r'   Úfloat16Úbfloat16Úfloat32ÚFÚsoftmaxr   r   Ú	unsqueezeÚsumÚmasked_fillÚ	clamp_minÚmeanÚto)r   r!   r   r   r   r"   Úreduction_dtypeÚ	pred_softÚtarget_maskÚtarget_one_hotÚmaskÚdimsÚtpÚfpÚfnÚpresentÚdenominatorÚscores   &&&&&&            r   Útversky_lossrJ   /   sè  € ôr �dœEŸL™L×)Ò)ÜÐ?ÄÀTÃ
¸|ÐLÓMÐMä�fœeŸl™l×+Ò+ÜÐAÄ$ÀvÃ,ÀÐPÓQÐQäˆ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ä�e 3Ô'ð (,§z¡z´e·m±mÄUÇ^Á^Ð5TÔ'T”e—m’mÐZ^×ZdÑZd€OÜ—	’	˜$ A¨_Ô=€IÜ,¨VÓBÑ€Fä˜V§Z¡Z°¥]¸4¿;¹;ÈoÐcfÔg€NàÒØ×$Ñ$ QÓ'ˆØÕ$ˆ	Ø'Õ.ˆà€DØ
Õ
$×	)Ñ	)¨$Ó	/€BØ
�s˜^Õ+Õ
,×	1Ñ	1°$Ó	7€BØ��?˜nÕ
,×	1Ñ	1°$Ó	7€BØ× Ñ  Ó&¨Ñ*€GØ˜r•z•/ D¥IÕ-°Õ3€Kà�+×)Ñ)¨7¨(°CÓ8Õ8×EÑEÀwÀhÐPSÓT€EØ�I‰I�b‹M˜GŸK™K¨›O×5Ñ5°aÓ8Õ8€Eà�%—*‘*“,Õ×"Ñ" 4§:¡:Ó.Ð.r   c                  óB   a € ] tR t^•tRtRR V 3R llltR R ltRtV ;t# )ÚTverskyLossa  Compute the Tversky loss of ``(B, C, H, W)`` logits against ``(B, H, W)`` class indices (module form).

``criterion = TverskyLoss(alpha, beta, eps, ignore_index)`` stores its arguments, and
``loss = criterion(pred, target)`` is :func:`~kornia.losses.tversky_loss`.

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

Args:
    alpha: weight of the false positives, non-negative and finite.
    beta: weight of the false negatives, non-negative and finite.
    eps: term added to the denominator, non-negative and finite.
    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.tversky_loss`: the one-call form.
    - :class:`~kornia.losses.DiceLoss`: weights false positives and false negatives equally; adds ``average`` and
      class ``weight``.

Examples:
    >>> N = 5  # num_classes
    >>> criterion = TverskyLoss(alpha=0.5, beta=0.5)
    >>> pred = torch.randn(1, N, 3, 5, requires_grad=True)
    >>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)
    >>> output = criterion(pred, target)
    >>> output.backward()

c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r   r   r   r   r"   r#   r   r   r   )r   s   "r   r   ÚTverskyLoss.__annotate__¸   s1   € ÷ 8ñ 8˜eð 8¨5ð 8°uð 8ÐS`ð 8Ðlpñ 8r   c                	ól   <€ \         SV `  4        \        WV4       Wn        W n        W0n        W@n        R # )N)ÚsuperÚ__init__r   r   r   r   r"   )Úselfr   r   r   r"   Ú	__class__s   &&&&&€r   rQ   ÚTverskyLoss.__init__¸   s-   ø€ Ü‰ÑÔÜ˜% sÔ+Ø!Œ
ØŒ	ØŒØ+7Ör   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r    r!   r   r   )r   s   "r   r   rN   À   s&   € ÷ ^ñ ^˜Lð ^°,ð ^À<ñ ^r   c                óp   € \        WV P                  V P                  V P                  V P                  4      # )a[  Compute the Tversky segmentation loss for class 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 class-label tensor with shape ``(B, H, W)``.
        Labels matching ``self.ignore_index`` are excluded from the
        loss when an ignore index is configured.

Returns:
    Scalar tensor containing the Tversky loss. ``self.alpha`` controls
    the false-positive penalty and ``self.beta`` controls the
    false-negative penalty.
)rJ   r   r   r   r"   )rR   r   r!   s   &&&r   ÚforwardÚTverskyLoss.forwardÀ   s)   € ô  ˜D¨$¯*©*°d·i±iÀÇÁÈ4×K\ÑK\Ó]Ð]r   )r   r   r   r"   ©g:Œ0âŽyE>iœÿÿÿ)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rQ   rW   Ú__static_attributes__Ú__classcell__)rS   s   @r   rL   rL   •   s   ø† ñ ÷D8ò 8÷^ó ^r   rL   rY   )Ú__conditional_annotations__Ú
__future__r   ÚsysÚtypingr   r,   Útorch.nn.functionalr   Ú
functionalr6   Úkornia.losses._utilsr   Úkornia.losses.one_hotr   Ú
float_infoÚmaxr	   Ú__annotations__r   rJ   ÚModulerL   )ra   s   @r   Ú<module>rm      s[   øð÷$ #Ð "ã 
Ý ã ß Ð Ý å 3Ý )ð —N‘N×&Ñ&€
ˆEÓ &õV÷c/ôL;^�"—)‘)ö ;^r   