Commit 503e979
fix(metrics): score a missed prediction in Hausdorff percentile, don't drop it
`HausdorffDistanceMetric(percentile=...)` returns `nan` when one of the two
masks is empty, where `percentile=None` returns `inf` for the same input.
`get_surface_distance` reports an infinite distance for every boundary voxel
when a mask is empty, so an all-infinite tensor reaches
`_compute_percentile_hausdorff_distance`. `torch.quantile` interpolates
linearly between the order statistics straddling the requested rank, and that
interpolation is `inf + (inf - inf) * frac`, which is `nan`. The maximum and
minimum paths escape it because they do not interpolate.
The quantile of a constant sequence is that constant, so the `nan` is an
artefact rather than a property of the distances. It also collides with the
meaning this metric already gives `nan`: both-masks-empty returns it to say
"not applicable", and `do_metric_reduction` excludes it from the average. A
prediction that missed the structure entirely is therefore removed from a
dataset score rather than counted as the worst case, and the reported HD95
improves as the model finds fewer structures. `get_not_nans=True` reveals the
shrinking denominator but is off by default.
Return the infinity directly when every distance is infinite, so the percentile
path agrees with the maximum path. The guard is exact: `get_surface_distance`
returns either all-finite or all-infinite distances, never a mixture, and each
direction of the symmetric distance is reduced separately.
Adds regression tests over both entry points at `percentile` None, 0, 50, 95,
99 and 100. Without the source change eight fail and four pass, the four being
the non-interpolating None and 0 paths.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: asifuddin01 <md.asif.uddin@g.bracu.ac.bd>1 parent c0d1ec1 commit 503e979
2 files changed
Lines changed: 52 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
156 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
211 | 229 | | |
212 | 230 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
| |||
204 | 210 | | |
205 | 211 | | |
206 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
207 | 239 | | |
208 | 240 | | |
209 | 241 | | |
0 commit comments