Morphology#
- class kornia.losses.HausdorffERLoss(alpha=2.0, k=10, reduction='mean')[source]#
Binary 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:
\[hd(X,Y) = \max_{x \in X} \min_{y \in Y}||x - y||_2\]Furthermore, the bidirectional HD is:
\[HD(X,Y) = max(hd(X, Y), hd(Y, X))\]This is an Hausdorff Distance (HD) Loss that based on morphological erosion, which provided a differentiable approximation of Hausdorff distance as stated in [KS19]. The code is refactored on top of here.
- Parameters:
alpha (
float, optional) – controls the erosion rate in each iteration. Default:2.0k (
int, optional) – the number of iterations of erosion. Default:10reduction (
str, optional) – 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. Default:"mean"
Examples
>>> hdloss = HausdorffERLoss() >>> input = torch.randn(5, 3, 20, 20) >>> target = (torch.rand(5, 1, 20, 20) * 2).long() >>> res = hdloss(input, target)
- class kornia.losses.HausdorffERLoss3D(alpha=2.0, k=10, reduction='mean')[source]#
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:
\[hd(X,Y) = \max_{x \in X} \min_{y \in Y}||x - y||_2\]Furthermore, the bidirectional HD is:
\[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 [KS19]. The code is refactored on top of here.
- Parameters:
alpha (
float, optional) – controls the erosion rate in each iteration. Default:2.0k (
int, optional) – the number of iterations of erosion. Default:10reduction (
str, optional) – 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. Default:"mean"
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)