class_docstr: Base class for binary Hausdorff loss based on morphological erosion.
  
  This is an Hausdorff Distance (HD) Loss that based on morphological erosion,which provided
  a differentiable approximation of Hausdorff distance as stated in :cite:`karimi2019reducing`.
  The code is refactored on top of `here <https://github.com/PatRyg99/HausdorffLoss/
      blob/master/hausdorff_loss.py>`__.
  
  Args:
      alpha: controls the erosion rate in each iteration.
      k: the number of iterations of erosion.
      reduction: Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'.
          'none': no reduction will be applied, 'mean': the weighted mean of the output is taken,
          'sum': the output will be summed.
  
  Returns:
      Estimated Hausdorff Loss.
class_docstr_tok: ["Base","class","for","binary","Hausdorff","loss","based","on","morphological","erosion",".","This","is","an","Hausdorff","Distance","(","HD",")","Loss","that","based","on","morphological","erosion",",","which","provided","a","differentiable","approximation","of","Hausdorff","distance","as","stated","in",":","cite",":","`","karimi2019reducing","`",".","The","code","is","refactored","on","top","of","`","here","<","https",":","\/\/github.com\/PatRyg99\/HausdorffLoss\/","blob\/master\/hausdorff_loss.py",">","`","__",".","Args",":","alpha",":","controls","the","erosion","rate","in","each","iteration",".","k",":","the","number","of","iterations","of","erosion",".","reduction",":","Specifies","the","reduction","to","apply","to","the","output",":","'none","'","|","'mean","'","|","'sum","'",".","'none","'",":","no","reduction","will","be","applied",",","'mean","'",":","the","weighted","mean","of","the","output","is","taken",",","'sum","'",":","the","output","will","be","summed",".","Returns",":","Estimated","Hausdorff","Loss","."]
docstr: Compute Hausdorff loss.
  
  Args:
      pred: predicted tensor with a shape of :math:`(B, C, H, W)` or :math:`(B, C, D, H, W)`.
          Each channel is as binary as: 1 -> fg, 0 -> bg.
      target: target tensor with a shape of :math:`(B, 1, H, W)` or :math:`(B, C, D, H, W)`.
  
  Returns:
      Estimated Hausdorff Loss.
docstr_tok: ["Compute","Hausdorff","loss",".","Args",":","pred",":","predicted","tensor","with","a","shape","of",":","math",":","`","(","B",",","C",",","H",",","W",")","`","or",":","math",":","`","(","B",",","C",",","D",",","H",",","W",")","`",".","Each","channel","is","as","binary","as",":","1","-",">","fg",",","0","-",">","bg",".","target",":","target","tensor","with","a","shape","of",":","math",":","`","(","B",",","1",",","H",",","W",")","`","or",":","math",":","`","(","B",",","C",",","D",",","H",",","W",")","`",".","Returns",":","Estimated","Hausdorff","Loss","."]
code: def forward(self, pred: Tensor, target: Tensor) -> Tensor:
      """Compute Hausdorff loss.
  
      Args:
          pred: predicted tensor with a shape of :math:`(B, C, H, W)` or :math:`(B, C, D, H, W)`.
              Each channel is as binary as: 1 -> fg, 0 -> bg.
          target: target tensor with a shape of :math:`(B, 1, H, W)` or :math:`(B, C, D, H, W)`.
  
      Returns:
          Estimated Hausdorff Loss.
      """
      if not (
          pred.shape[2:] == target.shape[2:]
          and pred.size(0) == target.size(0)
          and target.size(1) == 1
      ):
          raise ValueError(
              "Prediction and target need to be of same size, and target should not be one-hot."
              f"Got {pred.shape} and {target.shape}."
          )
  
      if pred.size(1) < target.max().item():
          raise ValueError("Invalid target value.")
  
      out = stack(
          [
              self.perform_erosion(
                  pred[:, i : i + 1],
                  where(
                      target == i,
                      tensor(
                          1, device=target.device, dtype=target.dtype
                      ),
                      tensor(
                          0, device=target.device, dtype=target.dtype
                      ),
                  ),
              )
              for i in range(pred.size(1))
          ]
      )
  
      if self.reduction == "mean":
          out = out.mean()
      elif self.reduction == "sum":
          out = out.sum()
      elif self.reduction == "none":
          pass
      else:
          raise NotImplementedError(
              f"reduction `{self.reduction}` has not been implemented yet."
          )
  
      return out
  
file_path: kornia/kornia/losses/hausdorff.py
imports: from __future__ import annotations
  from typing import Callable
  import torch
  from torch import nn
  from kornia.core import Module, Tensor, as_tensor, stack, tensor, where, zeros_like
label_desc: Use image node_id 4 for calling the _HausdorffERLossBase obj's underlying member method code with example usage: obj.forward(pred, target) and returns: out