Skip to content

Commit 2a9b490

Browse files
committed
Fix: make y optional in ignore_background
Signed-off-by: Tristan Kirscher <85068746+Kirscher@users.noreply.github.com>
1 parent e242c44 commit 2a9b490

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

monai/metrics/active_learning_metrics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ def compute_variance(
129129
y_pred = y_pred.float()
130130

131131
if not include_background:
132-
y = y_pred
133-
# TODO If this utils is made to be optional for 'y' it would be nice
134-
y_pred, y = ignore_background(y_pred=y_pred, y=y)
132+
y_pred, _ = ignore_background(y_pred=y_pred, y=None)
135133

136134
# Set any values below 0 to threshold
137135
y_pred[y_pred <= 0] = threshold

monai/metrics/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
]
5252

5353

54-
def ignore_background(y_pred: NdarrayTensor, y: NdarrayTensor) -> tuple[NdarrayTensor, NdarrayTensor]:
54+
def ignore_background(
55+
y_pred: NdarrayTensor, y: NdarrayTensor | None = None
56+
) -> tuple[NdarrayTensor, NdarrayTensor | None]:
5557
"""
5658
This function is used to remove background (the first channel) for `y_pred` and `y`.
5759
@@ -63,7 +65,8 @@ def ignore_background(y_pred: NdarrayTensor, y: NdarrayTensor) -> tuple[NdarrayT
6365
6466
"""
6567

66-
y = y[:, 1:] if y.shape[1] > 1 else y # type: ignore[assignment]
68+
if y is not None:
69+
y = y[:, 1:] if y.shape[1] > 1 else y # type: ignore[assignment]
6770
y_pred = y_pred[:, 1:] if y_pred.shape[1] > 1 else y_pred # type: ignore[assignment]
6871
return y_pred, y
6972

0 commit comments

Comments
 (0)