Project-MONAI / Project-MONAI/MONAI

get_edge_surface_distance passes the deprecated always_return_as_numpy argument internally

Open
#9,059 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.7k
Forks
1.6k
Avg merge
5d 1h
Merged PRs (30d)
20

Description

Describe the bug

monai/metrics/utils.py declares get_mask_edges() with a deprecation decorator on one of its arguments:

@deprecated_arg(
    name="always_return_as_numpy",
    since="1.5.0",
    removed="1.7.0",
    msg_suffix="The option is removed and the return type will always be equal to the input type.",
)
def get_mask_edges(..., always_return_as_numpy: bool = False):

get_edge_surface_distance() in the same module then calls it with that exact deprecated argument (monai/metrics/utils.py:363 on dev):

edges_pred, edges_gt, *areas = get_mask_edges(
    y_pred, y, crop=True, spacing=edges_spacing, always_return_as_numpy=False
)

Two consequences:

  1. SurfaceDistanceMetric and HausdorffDistanceMetric both route through get_edge_surface_distance, so every call emits a FutureWarning about an argument the caller never passed and cannot suppress. It shows up in ordinary validation loops.
  2. The argument is scheduled for removal in 1.7.0, and this internal call site would break that removal.

False is already the parameter default, so the keyword can be dropped with no behaviour change.

To Reproduce

import warnings, torch
from monai.metrics import SurfaceDistanceMetric

a = torch.zeros(1, 1, 32, 32); a[..., :16, :] = 1
b = torch.zeros(1, 1, 32, 32); b[..., :20, :] = 1

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always")
    SurfaceDistanceMetric()(a, b)

print([str(x.message) for x in w if "always_return_as_numpy" in str(x.message)])

This prints one FutureWarning. HausdorffDistanceMetric behaves the same way.

Expected behavior

No deprecation warning, since the caller did not pass a deprecated argument.

Environment

MONAI version: 1.6.0rc1+52.g7f6bf2db
Numpy version: 2.4.6
Pytorch version: 2.13.0
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 7f6bf2db52387d14ef867a79b888e7cc1b81c700

Optional dependencies:
scipy version: 1.17.1
Pillow version: 12.3.0
psutil version: 7.2.2
(others not installed)

System: Darwin
Platform: macOS-26.5.2-arm64-arm-64bit
Python version: 3.11.6
Num physical CPUs: 12
Total physical memory (GB): 32.0
Num GPUs: 0
Has CUDA: False

Additional context

Dropping the keyword leaves results unchanged. Measured over three metric calls on identical inputs:

deprecation warnings SurfaceDistance Hausdorff SurfaceDistance reversed
before 3 1.173913 4.000000 1.400000
after 0 1.173913 4.000000 1.400000

This is the same class of warning-hygiene issue as #8931 / #8932, in the same file.

I have a fix and a regression test ready, and would be glad to open a PR.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in monai/metrics/utils.py at get_edge_surface_distance(), around line 363, and inspect its call to get_mask_edges(). Remove the deprecated keyword without changing the results, then add or run the regression coverage described in the issue to confirm SurfaceDistanceMetric and HausdorffDistanceMetric emit no warning and retain their existing values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.