Skip to content

Commit 260d644

Browse files
committed
add lint fixes
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
1 parent 41692e5 commit 260d644

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

monai/metrics/meandice.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def __call__(self, y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor | tupl
311311
if y_pred.shape[1] == 1 and n_pred_ch > 1:
312312
y_pred_bool = torch.zeros(batch_size, n_pred_ch, *y_pred.shape[2:], dtype=torch.bool, device=device)
313313
for c in range(n_pred_ch):
314-
y_pred_bool[:, c] = (y_pred[:, 0] == c)
314+
y_pred_bool[:, c] = y_pred[:, 0] == c
315315
else:
316316
y_pred_bool = y_pred.bool()
317317

@@ -345,9 +345,12 @@ def __call__(self, y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor | tupl
345345
empty_mask = y_sum == 0
346346
dice = torch.where(
347347
empty_mask,
348-
torch.where(pred_sum == 0, torch.tensor(1.0, device=device, dtype=dice.dtype),
349-
torch.tensor(0.0, device=device, dtype=dice.dtype)),
350-
dice
348+
torch.where(
349+
pred_sum == 0,
350+
torch.tensor(1.0, device=device, dtype=dice.dtype),
351+
torch.tensor(0.0, device=device, dtype=dice.dtype),
352+
),
353+
dice,
351354
)
352355

353356
# Select channels: exclude background if requested

tests/metrics/test_compute_meandice.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,7 @@
291291
[[[0.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [0.0, 0.0]], [[0.0, 1.0], [1.0, 0.0]]],
292292
]
293293
), # (2, 3, 2, 2) one-hot
294-
"y": torch.tensor(
295-
[
296-
[[[0.0, 0.0], [0.0, 1.0]]],
297-
[[[0.0, 0.0], [0.0, 1.0]]],
298-
]
299-
), # (2, 1, 2, 2) class indices
294+
"y": torch.tensor([[[[0.0, 0.0], [0.0, 1.0]]], [[[0.0, 0.0], [0.0, 1.0]]]]), # (2, 1, 2, 2) class indices
300295
"include_background": False,
301296
},
302297
# batch 0: class 1 y_gt=[[0,0],[0,1]], y_pred=[[0,0],[1,1]] -> dice=2/3

0 commit comments

Comments
 (0)