Skip to content

Add HausdorffDistance and HausdorffDistance95 metrics (closes #683)#3744

Draft
MukundaKatta wants to merge 1 commit intopytorch:masterfrom
MukundaKatta:feat/hausdorff-distance-metric
Draft

Add HausdorffDistance and HausdorffDistance95 metrics (closes #683)#3744
MukundaKatta wants to merge 1 commit intopytorch:masterfrom
MukundaKatta:feat/hausdorff-distance-metric

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

Closes #683. Adds HausdorffDistance and HausdorffDistance95 metrics for 2D/3D segmentation masks (binary and multi-class with ignore_index).

Implementation

Pure-torch (no runtime scipy dep — scipy is dev-only). Boundaries are extracted via padded neighbor shifts (torch.roll) so the same code path handles (B, H, W) and (B, D, H, W) masks. Pairwise distances use torch.cdist. Cross-validated against scipy.spatial.distance.directed_hausdorff on a random shape — exact match (3.605551).

Files

  • ignite/metrics/hausdorff_distance.py — both classes, configurable percentile, ignore_index, full lifecycle.
  • ignite/metrics/__init__.py — register exports.
  • docs/source/metrics.rst — add to docs index.
  • tests/ignite/metrics/test_hausdorff_distance.py — 13 tests including known-output 2D/3D cases (corner-pair, two-square shapes), update→compute lifecycle, reset, multi-class with ignore_index, HD95 outlier-suppression, engine integration.

Test plan

  • 13/13 pass locally (Python 3.13, torch 2.11).
  • Lifecycle and sync_all_reduce mirror existing metrics (MeanSquaredError/PSNR).

Implements pure-torch Hausdorff distance for 2D and 3D segmentation
masks (binary and multi-class with optional ignore_index).
HausdorffDistance95 is the standard 95th-percentile variant used in
medical imaging benchmarks. Boundaries are extracted via neighbor
shifts so the metric has no scipy/cKDTree runtime dependency.

Closes pytorch#683
@github-actions github-actions Bot added docs module: metrics Metrics module labels Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Hausdorff distance in Metrics

1 participant