-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When I try to compute GeneralizedDiceMetric. I get the following error. I must point out that if I replace the 'GeneralizedDiceMetricwithDiceMetric` it works fine.
File "train_4.py", line 120, in main
dice_metric(y_pred = val_outputs.to(dtype=torch.int32), y = val_labels.to(dtype=torch.int32))
File "/opt/conda/lib/python3.8/site-packages/monai/metrics/metric.py", line 344, in __call__
ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/monai/metrics/metric.py", line 77, in __call__
return self._compute_tensor(y_pred.detach(), y_, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/monai/metrics/generalized_dice.py", line 77, in _compute_tensor
return compute_generalized_dice(
File "/opt/conda/lib/python3.8/site-packages/monai/metrics/generalized_dice.py", line 173, in compute_generalized_dice
(y_pred_o == 0)[denom_zeros],
File "/opt/conda/lib/python3.8/site-packages/monai/data/meta_tensor.py", line 297, in __torch_function__
ret = MetaTensor.update_meta(ret, func, args, kwargs)
File "/opt/conda/lib/python3.8/site-packages/monai/data/meta_tensor.py", line 237, in update_meta
ret_meta = decollate_batch(args[0], detach=False)[batch_idx]
File "/opt/conda/lib/python3.8/site-packages/monai/data/meta_tensor.py", line 276, in __torch_function__
ret = super().__torch_function__(func, types, args, kwargs)
File "/opt/conda/lib/python3.8/site-packages/torch/_tensor.py", line 1295, in __torch_function__
ret = func(*args, **kwargs)
TypeError: only integer tensors of a single element can be converted to an index
To Reproduce
I am sharing a relevant code snippet
post_trans = Compose([Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
dice_metric = GeneralizedDiceScore(include_background=False, reduction="mean_batch")
for val_data in val_loader:
val_image = val_data["image"].to(device)
val_labels = val_data["mask"].to(device)
_val_outputs = model(val_image)
val_outputs = post_trans(_val_outputs)
dice_metric(y_pred = val_outputs, y = val_labels)
The shape of val_outputs is [4, 1, 256, 256, 24] and is a binary tensor.
Expected behavior
I expect the behavior to be the same DiceMetric
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working