+
    åûj~  ã                  ól   € ^ RI Ht ^ RIt^ RIHtHt ^ RIHt R R lt ! R R]P                  4      t	R# )	é    )ÚannotationsN)ÚTensorÚnn)ÚKORNIA_CHECK_SHAPEc               ó$   € V ^8„  d   QhRRRRRR/# ©é   Úpredr   ÚtargetÚreturn© )Úformats   "ÚVC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\lovasz_hinge.pyÚ__annotate__r      s+   € ÷ TSñ TS˜Fð TS¨Fð TS°vñ TSó    c                ó¤  € \        V . RO4       \        V. RO4       V P                  ^ ,          VP                  ^ ,          8X  d"   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\        P
                  ! V P                  \        P                  4      pV P                  ^R7      pVP                  ^R7      P                  V4      pVP                  w  rVRV,          R,
          pRW7,          ,
          pVP                  ^RR	7      w  rš\        P                  ! WPP                  R
7      P                  R^4      P                  ^V4      P                  R4      pWKV
P                  R4      3,          pVP                  WV4      pVP                  ^RR7      pWÜP!                  ^4      ,
          pVRV,
          P!                  ^4      ,           pRWï,          ,
          pV^8”  d   VR,          VRRR13,          ,
          VR&   V	P#                  4       V,          P                  ^4      P%                  4       pTP                  V P'                  4       '       d   V P                  4      # T4      # )uœ  Compute the binary LovÃ¡sz-hinge IoU loss of ``(B, 1, H, W)`` logits against ``(B, H, W)`` labels.

``loss = lovasz_hinge_loss(pred, target)`` optimises the intersection over union (IoU) of two foregrounds: the
one predicted by the single logit channel of ``pred`` (:math:`X`) and the one labelled in ``target`` (:math:`Y`).
It minimises the LovÃ¡sz extension [1] of the Jaccard loss [2].

.. math::

    \Delta_J = 1 - \frac{|X \cap Y|}{|X \cup Y|}

Reference:
    [1] http://proceedings.mlr.press/v37/yub15.pdf
    [2] https://arxiv.org/pdf/1705.08790.pdf

Convention:
    - ``pred`` holds one logit channel and ``target`` labels of 1 for the foreground and 0 for the background; the
      batch and spatial sizes must match. The loss is computed per image and averaged over the batch; there is no
      ``reduction``.
    - The extension is evaluated at the hinge errors :math:`\max(0, 1 - z (2t - 1))` of logit :math:`z` and label
      :math:`t`, so the loss is not :math:`1 - \text{IoU}`: logits of :math:`\pm 1` that are
      positive on the predicted foreground give :math:`2 (1 - \text{IoU})` of that prediction, and correct
      logits of magnitude at least 1 give 0.
    - ``target`` is not validated and there is no ``ignore_index``: a label of 2 is accepted, and ``-100``, the
      ``ignore_index`` of :func:`~kornia.losses.focal_loss` and :func:`~kornia.losses.dice_loss`, can make the
      loss negative.

Args:
    pred: logits ``(B, 1, H, W)``.
    target: binary labels ``(B, H, W)``.

Returns:
    a scalar with the computed loss, in the dtype of a floating-point ``pred`` and in float32 for an
    integer or bool ``pred``. The Jaccard weights and the sum over pixels are computed in float32 for a
    float16 or bfloat16 ``pred``.

See Also:
    - :class:`~kornia.losses.LovaszHingeLoss`: the module form.
    - :func:`~kornia.losses.lovasz_softmax_loss`: the multi-class loss, from ``C >= 2`` logit channels against
      class indices.

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

Nz.pred and target shapes must be the same. Got: z and z1pred and target must be in the same device. Got: )Ú	start_dimg       @g      ð?T)ÚdimÚ
descending)Údevice)Úkeepdim.)ÚBÚ1ÚHÚW)r   r   r   éþÿÿÿéÿÿÿÿ).:é   NN)r   ÚshapeÚ
ValueErrorr   ÚtorchÚpromote_typesÚdtypeÚfloat32ÚflattenÚtoÚsortÚarangeÚreshapeÚrepeatÚviewÚsumÚcumsumÚreluÚmeanÚis_floating_point)r
   r   Úaccumulation_dtypeÚpred_flattenÚtarget_flattenr   ÚNÚsignsÚerrorsÚerrors_sortedÚpermutationÚbatch_indexÚtarget_sortedÚtarget_sorted_sumÚintersectionÚunionÚgradientÚlosss   &&                r   Úlovasz_hinge_lossr@      sb  € ôb �tÒ1Ô2ä�všÔ/à�J‰J�q�M˜VŸ\™\¨!�_Ô,°·±¸B¸C°ÀFÇLÁLÐQSÐQTÐDUÔ1UÜÐIÈ$Ï*É*ÈÐUZÐ[a×[gÑ[gÐZhÐiÓjÐjà�;‰;˜&Ÿ-™-Ô'ÜÐLÈTÏ[É[ÈMÐY^Ð_e×_lÑ_lÐ^mÐnÓoÐoô
 ×,Ò,¨T¯Z©Z¼¿¹ÓGÐØŸ<™<°!˜<Ó4€LØ#Ÿ^™^°a˜^Ó8×;Ñ;Ð<NÓO€Nð ×Ñ�D€Að �.Õ  3Õ&€EØ�<Õ'Õ'€FØ!'§¡°¸t Ó!DÑ€MÜŸ,š, q·±Ô=×EÑEÀbÈ!ÓL×SÑSÐTUÐWXÓY×aÑaÐbdÓe€KØ*¸×8HÑ8HÈÓ8LÐ+LÕM€MØ!×&Ñ& qÓ,€MØ -× 1Ñ 1°!¸TÐ 1Ó BÐØ,×/CÑ/CÀAÓ/FÕF€LØ%¨¨}Õ)<×(DÑ(DÀQÓ(GÕG€EØ˜\Õ1Õ1€HØˆ1„uØ$ WÕ-°¸¸c¸r¸c¸Õ0BÕBˆ�ÑØ!×&Ñ&Ó(¨8Õ3×8Ñ8¸Ó;×@Ñ@ÓB€Dà�7‰7 ×!7Ñ!7×!9Ò!9�4—:‘:ÓRÐRÐ?QÓRÐRr   c                  ó>   a € ] tR t^ttRtR V 3R lltR R ltRtV ;t# )ÚLovaszHingeLossu£  Compute the binary LovÃ¡sz-hinge IoU loss of ``(B, 1, H, W)`` logits against ``(B, H, W)`` labels (module form).

``criterion = LovaszHingeLoss()`` takes no arguments, and ``loss = criterion(pred, target)`` is
:func:`~kornia.losses.lovasz_hinge_loss`.

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

Shape:
    - pred: logits ``(B, 1, H, W)``.
    - target: binary labels ``(B, H, W)``.
    - Output: a scalar.

See Also:
    - :func:`~kornia.losses.lovasz_hinge_loss`: the one-call form.
    - :class:`~kornia.losses.LovaszSoftmaxLoss`: the multi-class loss, from ``C >= 2`` logit channels against
      class indices.

Example:
    >>> N = 1  # num_classes
    >>> criterion = LovaszHingeLoss()
    >>> 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   ÚNoner   )r   s   "r   r   ÚLovaszHingeLoss.__annotate__‘   s   € ÷ ñ ˜$ñ r   c                	ó$   <€ \         SV `  4        R # )N)ÚsuperÚ__init__)ÚselfÚ	__class__s   &€r   rH   ÚLovaszHingeLoss.__init__‘   s   ø€ Ü‰ÑÖr   c               ó$   € V ^8„  d   QhRRRRRR/# r   r   )r   s   "r   r   rE   ”   s!   € ÷ ;ñ ;˜Fð ;¨Fð ;°vñ ;r   c                ó   € \        WR7      # )a'  Compute binary Lovasz hinge loss for segmentation logits.

Args:
    pred: Binary logit tensor with shape ``(B, 1, H, W)``.
    target: Binary label tensor with shape ``(B, H, W)``.

Returns:
    Scalar tensor containing the Lovasz hinge surrogate for the
    intersection-over-union objective.
)r
   r   )r@   )rI   r
   r   s   &&&r   ÚforwardÚLovaszHingeLoss.forward”   s   € ô ! dÔ:Ð:r   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rH   rN   Ú__static_attributes__Ú__classcell__)rJ   s   @r   rB   rB   t   s   ø† ñ÷8ð ÷;ó ;r   rB   )
Ú
__future__r   r!   r   r   Úkornia.core.checkr   r@   ÚModulerB   r   r   r   Ú<module>rZ      s+   ðõ$ #ã ß å 0õTSôn+;�b—i‘iö +;r   