-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
Hello, some metrics have bugs when used with CUDA tensors. In particular, Generalized Dice Score fails with the following error when both y_pred and y are on the same CUDA device.
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Instead, in Average Surface Distance the device of the output is always cpu even if both outputs are on gpu.
To Reproduce
For Generalized Dice Score:
x = torch.randint(0, 2, (1, 6, 96, 96, 96)).to("cuda:0")
y = torch.randint(0, 2, (1, 6, 96, 96, 96)).to("cuda:0")
monai.metrics.compute_generalized_dice(x, y)
will raise the RuntimeError.
For Average Surface Distance
x = torch.randint(0, 2, (1, 6, 96, 96, 96)).to("cuda:0")
y = torch.randint(0, 2, (1, 6, 96, 96, 96)).to("cuda:0")
monai.metrics.compute_average_surface_distance(x, y)
will return a tensor([[...]], dtype=torch.float64) instead of tensor([[...]], device='cuda:0') (see Mean Dice for correct behavior).
Expected behavior
The metrics are computed without raising errors when inputs are on gpu and the returned output is on the same device.
Environment
Monai: 1.1.0