Add HausdorffDistance and HausdorffDistance95 metrics (closes #683)#3744
Draft
MukundaKatta wants to merge 1 commit intopytorch:masterfrom
Draft
Add HausdorffDistance and HausdorffDistance95 metrics (closes #683)#3744MukundaKatta wants to merge 1 commit intopytorch:masterfrom
MukundaKatta wants to merge 1 commit intopytorch:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #683. Adds
HausdorffDistanceandHausdorffDistance95metrics for 2D/3D segmentation masks (binary and multi-class withignore_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 usetorch.cdist. Cross-validated againstscipy.spatial.distance.directed_hausdorffon a random shape — exact match (3.605551).Files
ignite/metrics/hausdorff_distance.py— both classes, configurablepercentile,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 withignore_index, HD95 outlier-suppression, engine integration.Test plan
sync_all_reducemirror existing metrics (MeanSquaredError/PSNR).