:py:mod:`mipcandy.common.optim.loss`
====================================

.. py:module:: mipcandy.common.optim.loss

.. autodoc2-docstring:: mipcandy.common.optim.loss
   :allowtitles:

Module Contents
---------------

Classes
~~~~~~~

.. list-table::
   :class: autosummary longtable
   :align: left

   * - :py:obj:`FocalBCEWithLogits <mipcandy.common.optim.loss.FocalBCEWithLogits>`
     -
   * - :py:obj:`Loss <mipcandy.common.optim.loss.Loss>`
     -
   * - :py:obj:`SegmentationLoss <mipcandy.common.optim.loss.SegmentationLoss>`
     -
   * - :py:obj:`DiceCELossWithLogits <mipcandy.common.optim.loss.DiceCELossWithLogits>`
     -
   * - :py:obj:`DiceBCELossWithLogits <mipcandy.common.optim.loss.DiceBCELossWithLogits>`
     -

API
~~~

.. py:class:: FocalBCEWithLogits(alpha: float, gamma: float, *, reduction: typing.Literal[mean, sum, none] = 'mean')
   :canonical: mipcandy.common.optim.loss.FocalBCEWithLogits

   Bases: :py:obj:`torch.nn.Module`

   .. py:method:: forward(logits: torch.Tensor, targets: torch.Tensor) -> torch.Tensor
      :canonical: mipcandy.common.optim.loss.FocalBCEWithLogits.forward

      .. autodoc2-docstring:: mipcandy.common.optim.loss.FocalBCEWithLogits.forward

.. py:class:: Loss()
   :canonical: mipcandy.common.optim.loss.Loss

   Bases: :py:obj:`torch.nn.Module`

   .. py:property:: validation_mode
      :canonical: mipcandy.common.optim.loss.Loss.validation_mode
      :type: bool

      .. autodoc2-docstring:: mipcandy.common.optim.loss.Loss.validation_mode

.. py:class:: SegmentationLoss(num_classes: int, include_background: bool)
   :canonical: mipcandy.common.optim.loss.SegmentationLoss

   Bases: :py:obj:`mipcandy.common.optim.loss.Loss`

   .. py:method:: logitfy_no_grad(ids: torch.Tensor) -> torch.Tensor
      :canonical: mipcandy.common.optim.loss.SegmentationLoss.logitfy_no_grad

      .. autodoc2-docstring:: mipcandy.common.optim.loss.SegmentationLoss.logitfy_no_grad

.. py:class:: DiceCELossWithLogits(num_classes: int, *, lambda_ce: float = 1, lambda_soft_dice: float = 1, smooth: float = 1e-05, include_background: bool = True)
   :canonical: mipcandy.common.optim.loss.DiceCELossWithLogits

   Bases: :py:obj:`mipcandy.common.optim.loss.SegmentationLoss`

   .. py:method:: _forward(outputs: torch.Tensor, labels: torch.Tensor) -> tuple[torch.Tensor, dict[str, float]]
      :canonical: mipcandy.common.optim.loss.DiceCELossWithLogits._forward

      .. autodoc2-docstring:: mipcandy.common.optim.loss.DiceCELossWithLogits._forward

   .. py:method:: forward(outputs: torch.Tensor, labels: torch.Tensor) -> tuple[torch.Tensor, dict[str, float]]
      :canonical: mipcandy.common.optim.loss.DiceCELossWithLogits.forward

      .. autodoc2-docstring:: mipcandy.common.optim.loss.DiceCELossWithLogits.forward

.. py:class:: DiceBCELossWithLogits(*, lambda_bce: float = 1, lambda_soft_dice: float = 1, smooth: float = 1e-05, min_percentage_per_class: float | None = None)
   :canonical: mipcandy.common.optim.loss.DiceBCELossWithLogits

   Bases: :py:obj:`mipcandy.common.optim.loss.SegmentationLoss`

   .. py:method:: _forward(outputs: torch.Tensor, labels: torch.Tensor) -> tuple[torch.Tensor, dict[str, float]]
      :canonical: mipcandy.common.optim.loss.DiceBCELossWithLogits._forward

      .. autodoc2-docstring:: mipcandy.common.optim.loss.DiceBCELossWithLogits._forward

   .. py:method:: forward(outputs: torch.Tensor, labels: torch.Tensor) -> tuple[torch.Tensor, dict[str, float]]
      :canonical: mipcandy.common.optim.loss.DiceBCELossWithLogits.forward

      .. autodoc2-docstring:: mipcandy.common.optim.loss.DiceBCELossWithLogits.forward
