class_docstr: Binary 3D Hausdorff loss based on morphological erosion.
  
  Hausdorff Distance loss measures the maximum distance of a predicted segmentation boundary to
  the nearest ground-truth edge pixel. For two segmentation point sets X and Y ,
  the one-sided HD from X to Y is defined as:
  
  .. math::
  
      hd(X,Y) = \max_{x \in X} \min_{y \in Y}||x - y||_2
  
  Furthermore, the bidirectional HD is:
  
  .. math::
  
      HD(X,Y) = max(hd(X, Y), hd(Y, X))
  
  This is a 3D 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.
  
  Examples:
      >>> hdloss = HausdorffERLoss3D()
      >>> input = torch.randn(5, 3, 20, 20, 20)
      >>> target = (torch.rand(5, 1, 20, 20, 20) * 2).long()
      >>> res = hdloss(input, target)
class_docstr_tok: ["Binary","3D","Hausdorff","loss","based","on","morphological","erosion",".","Hausdorff","Distance","loss","measures","the","maximum","distance","of","a","predicted","segmentation","boundary","to","the","nearest","ground-truth","edge","pixel",".","For","two","segmentation","point","sets","X","and","Y",",","the","one-sided","HD","from","X","to","Y","is","defined","as",":","..","math",":",":","hd","(","X",",","Y",")","=","\\max_","{","x","\\in","X","}","\\min_","{","y","\\in","Y","}","||x","-","y||_2","Furthermore",",","the","bidirectional","HD","is",":","..","math",":",":","HD","(","X",",","Y",")","=","max","(","hd","(","X",",","Y",")",",","hd","(","Y",",","X",")",")","This","is","a","3D","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",".","Examples",":",">",">",">","hdloss","=","HausdorffERLoss3D","(",")",">",">",">","input","=","torch.randn","(","5",",","3",",","20",",","20",",","20",")",">",">",">","target","=","(","torch.rand","(","5",",","1",",","20",",","20",",","20",")","*","2",")",".long","(",")",">",">",">","res","=","hdloss","(","input",",","target",")"]
docstr: Compute 3D Hausdorff loss.
  
  Args:
      pred: predicted tensor with a shape of :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, D, H, W)`.
  
  Returns:
      Estimated Hausdorff Loss.
docstr_tok: ["Compute","3D","Hausdorff","loss",".","Args",":","pred",":","predicted","tensor","with","a","shape","of",":","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",",","D",",","H",",","W",")","`",".","Returns",":","Estimated","Hausdorff","Loss","."]
code: def forward(self, pred: Tensor, target: Tensor) -> Tensor:
      """Compute 3D Hausdorff loss.
  
      Args:
          pred: predicted tensor with a shape of :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, D, H, W)`.
  
      Returns:
          Estimated Hausdorff Loss.
      """
      if pred.dim() != 5:
          raise ValueError(
              f"Only 3D images supported. Got {pred.dim()}."
          )
  
      return super().forward(pred, target)
  
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 2 for calling the HausdorffERLoss3D obj's underlying member method code with example usage: obj.forward(pred, target) and returns: super