class_docstr: Compute channel-wise binary Hausdorff loss based on distance transform. It can support both multi-classes and
  multi-labels tasks. The data `input` (BNHW[D] where N is number of classes) is compared with ground truth `target`
  (BNHW[D]).
  
  Note that axis N of `input` is expected to be logits or probabilities for each class, if passing logits as input,
  must set `sigmoid=True` or `softmax=True`, or specifying `other_act`. And the same axis of `target`
  can be 1 or N (one-hot format).
  
  The original paper: Karimi, D. et. al. (2019) Reducing the Hausdorff Distance in Medical Image Segmentation with
  Convolutional Neural Networks, IEEE Transactions on medical imaging, 39(2), 499-513
docstr: Args:
      include_background: if False, channel index 0 (background category) is excluded from the calculation.
          if the non-background segmentations are small compared to the total image size they can get overwhelmed
          by the signal from the background so excluding it in such cases helps convergence.
      to_onehot_y: whether to convert the ``target`` into the one-hot format,
          using the number of classes inferred from `input` (``input.shape[1]``). Defaults to False.
      sigmoid: if True, apply a sigmoid function to the prediction.
      softmax: if True, apply a softmax function to the prediction.
      other_act: callable function to execute other activation layers, Defaults to ``None``. for example:
          ``other_act = torch.tanh``.
      reduction: {``"none"``, ``"mean"``, ``"sum"``}
          Specifies the reduction to apply to the output. Defaults to ``"mean"``.
  
          - ``"none"``: no reduction will be applied.
          - ``"mean"``: the sum of the output will be divided by the number of elements in the output.
          - ``"sum"``: the output will be summed.
      batch: whether to sum the intersection and union areas over the batch dimension before the dividing.
          Defaults to False, a loss value is computed independently from each item in the batch
          before any `reduction`.
  
  Raises:
      TypeError: When ``other_act`` is not an ``Optional[Callable]``.
      ValueError: When more than 1 of [``sigmoid=True``, ``softmax=True``, ``other_act is not None``].
          Incompatible values.
docstr_tok: ["Args",":","include_background",":","if","False",",","channel","index","0","(","background","category",")","is","excluded","from","the","calculation",".","if","the","non-background","segmentations","are","small","compared","to","the","total","image","size","they","can","get","overwhelmed","by","the","signal","from","the","background","so","excluding","it","in","such","cases","helps","convergence",".","to_onehot_y",":","whether","to","convert","the","``","target","``","into","the","one-hot","format",",","using","the","number","of","classes","inferred","from","`","input","`","(","``","input.shape","[","1","]","``",")",".","Defaults","to","False",".","sigmoid",":","if","True",",","apply","a","sigmoid","function","to","the","prediction",".","softmax",":","if","True",",","apply","a","softmax","function","to","the","prediction",".","other_act",":","callable","function","to","execute","other","activation","layers",",","Defaults","to","``","None","``",".","for","example",":","``","other_act","=","torch.tanh","``",".","reduction",":","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``","}","Specifies","the","reduction","to","apply","to","the","output",".","Defaults","to","``","``","mean","''","``",".","-","``","``","none","''","``",":","no","reduction","will","be","applied",".","-","``","``","mean","''","``",":","the","sum","of","the","output","will","be","divided","by","the","number","of","elements","in","the","output",".","-","``","``","sum","''","``",":","the","output","will","be","summed",".","batch",":","whether","to","sum","the","intersection","and","union","areas","over","the","batch","dimension","before","the","dividing",".","Defaults","to","False",",","a","loss","value","is","computed","independently","from","each","item","in","the","batch","before","any","`","reduction","`",".","Raises",":","TypeError",":","When","``","other_act","``","is","not","an","``","Optional","[","Callable","]","``",".","ValueError",":","When","more","than","1","of","[","``","sigmoid=True","``",",","``","softmax=True","``",",","``","other_act","is","not","None","``","]",".","Incompatible","values","."]
code: def __init__(
      self,
      alpha: float = 2.0,
      include_background: bool = False,
      to_onehot_y: bool = False,
      sigmoid: bool = False,
      softmax: bool = False,
      other_act: Callable | None = None,
      reduction: LossReduction | str = LossReduction.MEAN,
      batch: bool = False,
  ) -> None:
      """
      Args:
          include_background: if False, channel index 0 (background category) is excluded from the calculation.
              if the non-background segmentations are small compared to the total image size they can get overwhelmed
              by the signal from the background so excluding it in such cases helps convergence.
          to_onehot_y: whether to convert the ``target`` into the one-hot format,
              using the number of classes inferred from `input` (``input.shape[1]``). Defaults to False.
          sigmoid: if True, apply a sigmoid function to the prediction.
          softmax: if True, apply a softmax function to the prediction.
          other_act: callable function to execute other activation layers, Defaults to ``None``. for example:
              ``other_act = torch.tanh``.
          reduction: {``"none"``, ``"mean"``, ``"sum"``}
              Specifies the reduction to apply to the output. Defaults to ``"mean"``.
  
              - ``"none"``: no reduction will be applied.
              - ``"mean"``: the sum of the output will be divided by the number of elements in the output.
              - ``"sum"``: the output will be summed.
          batch: whether to sum the intersection and union areas over the batch dimension before the dividing.
              Defaults to False, a loss value is computed independently from each item in the batch
              before any `reduction`.
  
      Raises:
          TypeError: When ``other_act`` is not an ``Optional[Callable]``.
          ValueError: When more than 1 of [``sigmoid=True``, ``softmax=True``, ``other_act is not None``].
              Incompatible values.
  
      """
      super(HausdorffDTLoss, self).__init__(
          reduction=LossReduction(reduction).value
      )
      if other_act is not None and not callable(other_act):
          raise TypeError(
              f"other_act must be None or callable but is {type(other_act).__name__}."
          )
      if int(sigmoid) + int(softmax) > 1:
          raise ValueError(
              "Incompatible values: more than 1 of [sigmoid=True, softmax=True, other_act is not None]."
          )
  
      self.alpha = alpha
      self.include_background = include_background
      self.to_onehot_y = to_onehot_y
      self.sigmoid = sigmoid
      self.softmax = softmax
      self.other_act = other_act
      self.batch = batch
  
file_path: MONAI/monai/losses/hausdorff_loss.py
imports: from __future__ import annotations
  import warnings
  from typing import Callable
  import torch
  from torch.nn.modules.loss import _Loss
  from monai.networks import one_hot
  from monai.transforms.utils import distance_transform_edt
  from monai.utils import LossReduction
label_desc: Use image node_id 1 to create a new HausdorffDTLoss object from inherited base classes: _Loss with example: obj = HausdorffDTLoss(alpha, include_background, to_onehot_y, sigmoid, softmax, other_act, reduction, batch)