MONAI
MONAI copied to clipboard
Negative strides issue in monai.transforms.LoadImage causes error during collate
Describe the bug
When using monai.transforms.LoadImage with the nrrdreader to load an NRRD file, the resulting image metadata contains negative strides. This negative strides issue leads to an error when the tensor is collated.
To Reproduce
import monai
# Load an NRRD file
img = monai.transforms.LoadImage(reader="nrrdreader", index_order="C")("wrong_something.nrrd")
print(img.meta['spatial_shape'].strides) # Output: (-8,)
Error log:
torch/utils/data/_utils/collate.py", line 222, in <listcomp>
return collate([torch.as_tensor(b) for b in batch], collate_fn_map=collate_fn_map)
ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array with array.copy().)
Test data: https://drive.google.com/file/d/1Et-khdsou7E2T_aoX0zLvnld49Xh8YDn/view?usp=drive_link