From 74ce60da23c63037c0ea687f25e5a00e35dc2aae Mon Sep 17 00:00:00 2001 From: Tristan Kirscher <85068746+Kirscher@users.noreply.github.com> Date: Sun, 30 Nov 2025 16:37:30 +0000 Subject: [PATCH] Fix: make y optional in ignore_background Signed-off-by: Tristan Kirscher <85068746+Kirscher@users.noreply.github.com> --- monai/metrics/active_learning_metrics.py | 4 +--- monai/metrics/utils.py | 7 +++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/monai/metrics/active_learning_metrics.py b/monai/metrics/active_learning_metrics.py index 7a1654191e..e252999441 100644 --- a/monai/metrics/active_learning_metrics.py +++ b/monai/metrics/active_learning_metrics.py @@ -129,9 +129,7 @@ def compute_variance( y_pred = y_pred.float() if not include_background: - y = y_pred - # TODO If this utils is made to be optional for 'y' it would be nice - y_pred, y = ignore_background(y_pred=y_pred, y=y) + y_pred, _ = ignore_background(y_pred=y_pred, y=None) # Set any values below 0 to threshold y_pred[y_pred <= 0] = threshold diff --git a/monai/metrics/utils.py b/monai/metrics/utils.py index 972ec0061e..5eea9f409b 100644 --- a/monai/metrics/utils.py +++ b/monai/metrics/utils.py @@ -51,7 +51,9 @@ ] -def ignore_background(y_pred: NdarrayTensor, y: NdarrayTensor) -> tuple[NdarrayTensor, NdarrayTensor]: +def ignore_background( + y_pred: NdarrayTensor, y: NdarrayTensor | None = None +) -> tuple[NdarrayTensor, NdarrayTensor | None]: """ This function is used to remove background (the first channel) for `y_pred` and `y`. @@ -63,7 +65,8 @@ def ignore_background(y_pred: NdarrayTensor, y: NdarrayTensor) -> tuple[NdarrayT """ - y = y[:, 1:] if y.shape[1] > 1 else y # type: ignore[assignment] + if y is not None: + y = y[:, 1:] if y.shape[1] > 1 else y # type: ignore[assignment] y_pred = y_pred[:, 1:] if y_pred.shape[1] > 1 else y_pred # type: ignore[assignment] return y_pred, y