You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
distance_transform_edt not always working with cuCIM backend #7660
Describe the bug
The distance_transform_edt returns all zero in special cases when cuCIM is installed and used as a backend.
This happens when convert_to_cupy() decides that the data array needs to be copied here:
To Reproduce
!pip install torch
!pip install cucim
!pip install monai
!pip install numpy
from monai.transforms import distance_transform_edt
import torch
import numpy as np
# create a c-contiguous array
mask = np.zeros((1, 4, 4))
# make it f-contiguous to force convert_to_cupy to copy the data array later on
mask2 = np.asfortranarray(mask)
# convert to torch tensor to make distance_transform_edt use cuCIM backend
mask = torch.tensor(mask, device='cuda')
mask2 = torch.tensor(mask2, device='cuda')
# set half of the mask to foreground
mask[0, 0:2, :,] = 1
mask2[0, 0:2, :,] = 1
# confirm masks are the same
print(mask)
print(mask2)
# calculate distance transform
edt = distance_transform_edt(mask)
edt2 = distance_transform_edt(mask2)
# check if the results are the same
print(edt)
print(edt2)
Hi @aaronkujawa, thanks for the reporting. I have created a PR to fix it.
Main reason is that indices_ may not always be a shallow copy for F-order input as it constantly converts to C-order.
Activity
fix Project-MONAI#7660
KumoLiu commentedon Apr 19, 2024
Hi @aaronkujawa, thanks for the reporting. I have created a PR to fix it.
Main reason is that
indices_may not always be a shallow copy for F-order input as it constantly converts to C-order.MONAI/monai/transforms/utils.py
Line 2209 in ffd4454
MONAI/monai/utils/type_conversion.py
Line 262 in ffd4454
aaronkujawa commentedon Apr 22, 2024
Hi @KumoLiu , thanks for the quick fix!
Always convert input to C-order in distance_transform_edt (#7675)